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

本文介绍使用OSG库进行几何图形绘制的方法,包括通过addPrimitiveSet设置不同类型的几何图形,如Box、Capsule等,并详细讲解了DrawArrays类的使用。此外,还介绍了如何通过MatrixTransform实现模型的位置移动、缩放及旋转操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值