现在的位置: 首页 > 综合 > 正文

每日一练(二) animationPath

2018年05月17日 ⁄ 综合 ⁄ 共 1888字 ⁄ 字号 评论关闭

1、创建棋盘纹理:

      棋盘纹理,就是在一个二维空间创建一个网格,在这个网格的四角为一个区域,进行颜色填充。采用QUADS方式绘制改棋盘。

osg::Node*  OSGAnimateImpl::CreateBase(osg::Vec3 center,float radius)
{
    // 1. 创建棋盘纹理

    // 网格数
    int numTileX = 10;
    int numTileY = 10;

    // 网格宽高
    float fWidth = 2*radius;
    float fHeight = 2*radius;

    // 坐标
    osg::Vec3 v000(center - osg::Vec3(radius,radius,0.0f));
    osg::Vec3 dx(osg::Vec3(fWidth/((float)numTileX),0.0f,0.0f));
    osg::Vec3 dy(osg::Vec3(0.0f,fHeight/((float)numTileY),0.0f));
    
    // fill in vertices for grid, note numTilesX+1 * numTilesY+1
    // 生成网格点,横向:x+1 纵向:y+1  共(x+1)*(y+1)个点
    osg::Vec3Array* coords = new osg::Vec3Array();
    
    for(int j = 0; j <= numTileY; ++j)
         for(int i = 0; i <= numTileX; ++i)
        {
            coords->push_back(v000 + dx*(float)i +dy*(float)j);
        }
          
    // 黑白两种颜色
    osg::Vec4Array* clors = new osg::Vec4Array();
    clors->push_back(osg::Vec4(0.0f,0.0f,0.0f,1.0f));
    clors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
    int numClorSize = clors->size();

    // 创建坐标
    int numindicePreRow = numTileX + 1;
    osg::UByteArray* indicescoord = new osg::UByteArray();
    osg::UByteArray* indicesclor = new osg::UByteArray();
    for(int ix = 0; ix < numTileX; ++ix)
        for(int iy = 0; iy < numTileY; ++iy)
    {
        indicescoord->push_back(ix     + (iy+1)*numindicePreRow);
        indicescoord->push_back(ix     + iy*numindicePreRow);
        indicescoord->push_back((ix+1) + iy*numindicePreRow);
        indicescoord->push_back((ix+1) + (iy+1)*numindicePreRow);

        //clr
        indicesclor->push_back((ix+iy)%numClorSize);
    }
    // normal
    osg::Vec3Array* normals =new osg::Vec3Array();
    normals->push_back(osg::Vec3(0.0f,0.0f,1.0f));

    // set up the simple geometry
    osg::Geometry* geom = new osg::Geometry();
    
    geom->setVertexArray(coords);
    geom->setVertexIndices(indicescoord);

    geom->setColorArray(clors);
    geom->setColorIndices(indicesclor);
    geom->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE);

    geom->setNormalArray(normals);
    geom->setNormalBinding(osg::Geometry::BIND_OVERALL);

    geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,indicescoord->size()));

    osg::Geode* geode = new osg::Geode();
    geode->addDrawable(geom);

    return geode;
}

 1.1 效果图:

2、创建动画路径:

3、创建运动物体:

4、解析命令行参数:

5、其他:

抱歉!评论已关闭.