|
- int main( int argc, char** argv )
- {
- osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array(8);
- (*vertices)[0].set( 0.0f, 0.0f, 0.0f );
- (*vertices)[1].set( 1.0f, 0.0f, 0.0f );
- (*vertices)[2].set( 1.0f, 0.0f, 1.0f );
- (*vertices)[3].set( 0.0f, 0.0f, 1.0f );
- (*vertices)[4].set( 0.0f, 1.0f, 0.0f );
- (*vertices)[5].set( 1.0f, 1.0f, 0.0f );
- (*vertices)[6].set( 1.0f, 1.0f, 1.0f );
- (*vertices)[7].set( 0.0f, 1.0f, 1.0f );
- osg::ref_ptr<osg::DrawElementsUInt> index = new osg::DrawElementsUInt(
- osg::DrawElementsUInt::TRIANGLES);
- index->push_back(0);index->push_back(1);index->push_back(2);
- index->push_back(0);index->push_back(2);index->push_back(3);
-
- index->push_back(1);index->push_back(5);index->push_back(2);
- index->push_back(2);index->push_back(5);index->push_back(6);
- index->push_back(6);index->push_back(5);index->push_back(4);
- index->push_back(6);index->push_back(4);index->push_back(7);
- index->push_back(7);index->push_back(4);index->push_back(0);
- index->push_back(7);index->push_back(0);index->push_back(3);
- index->push_back(0);index->push_back(5);index->push_back(1);
- index->push_back(0);index->push_back(4);index->push_back(5);
- index->push_back(3);index->push_back(6);index->push_back(2);
- index->push_back(3);index->push_back(7);index->push_back(6);
- osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
- normals->push_back(osg::Vec3(0,-1,0));
- normals->push_back(osg::Vec3(0,-1,0));
- normals->push_back(osg::Vec3(0,-1,0));
- normals->push_back(osg::Vec3(0,-1,0));
- normals->push_back(osg::Vec3(0,-1,0));
- normals->push_back(osg::Vec3(0,-1,0));
- normals->push_back(osg::Vec3(1,0,0));
- normals->push_back(osg::Vec3(1,0,0));
- normals->push_back(osg::Vec3(1,0,0));
- normals->push_back(osg::Vec3(1,0,0));
- normals->push_back(osg::Vec3(1,0,0));
- normals->push_back(osg::Vec3(1,0,0));
- normals->push_back(osg::Vec3(0,1,0));
- normals->push_back(osg::Vec3(0,1,0));
- normals->push_back(osg::Vec3(0,1,0));
- normals->push_back(osg::Vec3(0,1,0));
- normals->push_back(osg::Vec3(0,1,0));
- normals->push_back(osg::Vec3(0,1,0));
- normals->push_back(osg::Vec3(-1,0,0));
- normals->push_back(osg::Vec3(-1,0,0));
- normals->push_back(osg::Vec3(-1,0,0));
- normals->push_back(osg::Vec3(-1,0,0));
- normals->push_back(osg::Vec3(-1,0,0));
- normals->push_back(osg::Vec3(-1,0,0));
- normals->push_back(osg::Vec3(0,0,-1));
- normals->push_back(osg::Vec3(0,0,-1));
- normals->push_back(osg::Vec3(0,0,-1));
- normals->push_back(osg::Vec3(0,0,-1));
- normals->push_back(osg::Vec3(0,0,-1));
- normals->push_back(osg::Vec3(0,0,-1));
- normals->push_back(osg::Vec3(0,0,1));
- normals->push_back(osg::Vec3(0,0,1));
- normals->push_back(osg::Vec3(0,0,1));
- normals->push_back(osg::Vec3(0,0,1));
- normals->push_back(osg::Vec3(0,0,1));
- normals->push_back(osg::Vec3(0,0,1));
- osg::ref_ptr<osg::Geometry> cuboid = new osg::Geometry;
- cuboid->setVertexArray(vertices);
- cuboid->addPrimitiveSet(index);
- cuboid->setNormalArray(normals);
- cuboid->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
- osg::ref_ptr<osg::Geode> geode = new osg::Geode;
- geode->addDrawable(cuboid);
- osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
- viewer->setSceneData(geode);
- viewer->addEventHandler(new osgViewer::WindowSizeHandler);
- return viewer->run();
- }
复制代码 今天测试创建简单的立方体,发现一个问题,模型有一半是黑色,不知道为什么?看了代码好像没什么问题,望达人指导一下? |
|