正在加载图片...
3.使用Shape,改变state 3.1本章目标 用osg:Shape实例构建场景。使用osg:StateSet控制shape的渲染。 3.2使用Shape类 Shape类是所有形状类别的基类。Shape既可用于剪裁和碰撞检测也可用于定义程序性地产生几 何体的那些基本形状。下面的类继承自Shape类: TriangleMesh Sphere InfinitePlane HeightField Cylinder Cone CompositeShape Box 为了使这些形状可以被渲染,我们需要把他们和Drawable类的实例关联起来。ShapeDrawable类 提供了这样的功能。这个类继承自Drawable并允许我们把Shape实例附加到可以被渲染的东西上。 既然ShapeDrawable类继承自Drawable,ShapDrawable实例就可以被加到Geode类实例上。下面 的步骤演示了将一个单位立方体加到空场景中时是如何做到这些的。 /Declare a group to act as root node of a scene: osg:Group*root new osg:Group(); /Declare a box class (derived from shape class)instance /This constructor takes an osg:Vec3 to define the center /and a float to define the height,width and depth. //(an overloaded constructor allows you to specify unique /height,width and height values.) osg:Box*unitCube new osg:Box(osg:Vec3(0,0,0),1.0f); /Declare an instance of the shape drawable class and initialize /it with the unitCube shape we created above. /This class is derived from'drawable'so instances of this /class can be added to Geode instances. osg:ShapeDrawable*unitCubeDrawable new osg:ShapeDrawable(unitCube); /Declare a instance of the geode class: osg:Geode*basicShapesGeode new osg:Geode(); /Add the unit cube drawable to the geode: basicShapesGeode->addDrawable(unitCubeDrawable); /Add the goede to the scene: root->addChild(basicShapesGeode):8 3.使用 Shape,改变 state 3.1 本章目标 用 osg::Shape 实例构建场景。使用 osg::StateSet 控制 shape 的渲染。 3.2 使用 Shape 类 Shape 类是所有形状类别的基类。Shape 既可用于剪裁和碰撞检测也可用于定义程序性地产生几 何体的那些基本形状。下面的类继承自 Shape 类: TriangleMesh Sphere InfinitePlane HeightField Cylinder Cone CompositeShape Box 为了使这些形状可以被渲染,我们需要把他们和 Drawable 类的实例关联起来。ShapeDrawable 类 提供了这样的功能。这个类继承自 Drawable 并允许我们把 Shape 实例附加到可以被渲染的东西上。 既然 ShapeDrawable 类继承自 Drawable,ShapDrawable 实例就可以被加到 Geode 类实例上。下面 的步骤演示了将一个单位立方体加到空场景中时是如何做到这些的。 // Declare a group to act as root node of a scene: osg::Group* root = new osg::Group(); // Declare a box class (derived from shape class) instance // This constructor takes an osg::Vec3 to define the center // and a float to define the height, width and depth. // (an overloaded constructor allows you to specify unique // height, width and height values.) osg::Box* unitCube = new osg::Box( osg::Vec3(0,0,0), 1.0f); // Declare an instance of the shape drawable class and initialize // it with the unitCube shape we created above. // This class is derived from 'drawable' so instances of this // class can be added to Geode instances. osg::ShapeDrawable* unitCubeDrawable = new osg::ShapeDrawable(unitCube); // Declare a instance of the geode class: osg::Geode* basicShapesGeode = new osg::Geode(); // Add the unit cube drawable to the geode: basicShapesGeode->addDrawable(unitCubeDrawable); // Add the goede to the scene: root->addChild(basicShapesGeode);
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有