OSG::Drawable, Geode的用法

osg::Drawable表示可绘制的物体的抽象接口,比如文字,基本图形。 可绘制的物体本身不能被加到场景中,要使用Geode将可绘制物体附加到其上。


这个其实之前的osgText::Text也属于Drawable的范围。还有一些其他的类继承自Drawable,但是由于我没用过,画出来也碍事,就没画了。


#include<osgViewer/Viewer>


int main(int argc, char **argv)
{
<span style="white-space:pre">	</span>osgViewer::Viewer viewer;


<span style="white-space:pre">	</span>//创建三角形的顶点数组
<span style="white-space:pre">	</span>osg::Vec3 myCoords[] =
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>osg::Vec3(-10, 0.0, 0.0),
<span style="white-space:pre">		</span>osg::Vec3(10, 0.0f, 0.0),
<span style="white-space:pre">		</span>osg::Vec3(0.0, 0.0f, 10.0)
<span style="white-space:pre">	</span>};
<span style="white-space:pre">	</span>int numCoords = sizeof(myCoords) / sizeof(osg::Vec3);
<span style="white-space:pre">	</span>osg::Vec3Array* vertices = new osg::Vec3Array(numCoords, myCoords);


<span style="white-space:pre">	</span>//创建三角形drawable
<span style="white-space:pre">	</span>osg::Geometry* triangleGeom = new osg::Geometry();
<span style="white-space:pre">	</span>// pass the created vertex array to the points geometry object.
<span style="white-space:pre">	</span>triangleGeom->setVertexArray(vertices);
<span style="white-space:pre">	</span>//使用这些顶点画三角形
<span style="white-space:pre">	</span>triangleGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, numCoords));


<span style="white-space:pre">	</span>osg::Geode *geode = new osg::Geode;
<span style="white-space:pre">	</span>geode->addDrawable(triangleGeom);


<span style="white-space:pre">	</span>viewer.setSceneData(geode);
<span style="white-space:pre">	</span>return viewer.run();
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值