|
楼主 |
发表于 2009-5-22 13:15:30
|
显示全部楼层
示例代码如下,可以运行看一下效果
#include <osgViewer\Viewer>
#include <osg\Material>
#include <osg\Geode>
#include <osg\Geometry>
osg::Node* createGeonode(const osg::Vec3d& base)
{
osg::Geode* geode = new osg::Geode;
osg::Geometry* geometry = new osg::Geometry;
osg::Vec3d vertices[] =
{
osg::Vec3d(0, 0, 0) + base,
osg::Vec3d(0, 0, 1) + base,
osg::Vec3d(1, 0, 0) + base,
osg::Vec3d(1, 0, 1) + base,
osg::Vec3d(1, 1, 0) + base,
osg::Vec3d(1, 1, 1) + base,
osg::Vec3d(0, 1, 0) + base,
osg::Vec3d(0, 1, 1) + base,
osg::Vec3d(0, 0, 0) + base,
osg::Vec3d(0, 0, 1) + base
};
geometry->setVertexArray(new osg::Vec3dArray(10, vertices));
geometry->addPrimitiveSet(new osg:rawArrays(osg:rimitiveSet:UAD_STRIP, 0, 10));
geode->addDrawable(geometry);
osg::Material* material = new osg::Material;
geode->getOrCreateStateSet()->setAttributeAndModes(material);
return geode;
}
int main( int argc, char **argv )
{
osgViewer::Viewer viewer;
osg::Group* root = new osg::Group;
root->addChild(createGeonode(osg::Vec3d(10000000,10000000,10000000)));
viewer.setSceneData(root);
return viewer.run();
} |
|