osg学习函数用法addPrimitiveSet +模型操作

来源:互联网 发布:cassandra数据库登录 编辑:程序博客网 时间:2024/04/30 06:39
addPrimitiveSet函数用来设置绘制的几何图形。
DrawArrays 类的构造函数为osg::DrawArrays::DrawArrays ( GLenum  mode,  GLint  first,  GLsizei  count ) ,mode是几何图形的类型,
有:osg::Box[盒子],
osg::Capsule[胶囊形],
osg::CompositeShape[组合型],
osg::Cone[圆锥形],
osg::Cylinder[圆柱形],
osg::HeightField[高程形],
osg::InfinitePlane[有限面],
osg::Sphere[球形],o
sg::TriangleMesh[三角蒙皮]等;
osg::PrimitiveSet::GLenum  mode,  GLint  first,  GLsizei  count ) );//基础类型,顶点的关联方式
。总共有这么些方式:
POINTS ,LINES ,LINE_STRIP ,LINE_LOOP, TRIANGLES ,TRIANGLE_STRIP, TRIANGLE_FAN ,QUADS ,QUAD_STRIP ,POLYGON 。
____________________first是顶点数组中的起始数据的数组下标,count是数据的个数\——————————————————————————————————————————————————————————
//模型操作   右是X轴,向里的是Y轴,而向上是Z轴
//移动
//  osg::MatrixTransform*trans=new osg::MatrixTransform;//生成矩阵变换函数指针
osg::ref_ptr < osg::MatrixTransform> trans = new osg::MatrixTransform;
//trans->setMatrix(osg::Matrix::translate(0,0,50));//向上
trans->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(90.0),0,0,-1)*
osg::Matrix::scale(3,3,3)*osg::Matrix::translate(0,0,50));//向移单位+放大 ,,,注意顺序问题
trans->addChild(cow);
//缩放
osg::ref_ptr < osg::MatrixTransform> scale = new osg::MatrixTransform;
//scale->setMatrix(osg::Matrix::scale(25,25,25));//放大25
scale->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(90.0),0,0,1)*
osg::Matrix::scale(25,25,25)*osg::Matrix::translate(-80, 0, -2));//大5+向下,乘号, 
scale->addChild(glider);
//旋转
osg::ref_ptr < osg::MatrixTransform> rot = new osg::MatrixTransform;
rot->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(45.0),1, 0, 0)*
osg::Matrix::scale(0.5,0.5,0.5)*osg::Matrix::translate(80, 0, -2)) ;//向右单位,缩0.5且平躺45度   x,y,z轴 
rot->addChild(Cessna);


root->addChild(Cessna);//原模型
root->addChild(trans);
root->addChild(scale);
root->addChild(rot);
0 0
原创粉丝点击