#include #include #include #include #include #include #include #include #include int main() { osg::Group *root = new osg::Group(); osg::Geode *pyramidGeode = new osg::Geode(); osg::Geometry *pyramidGeometry = new osg::Geometry(); osg::Geometry *geo2 = new osg::Geometry(); pyramidGeode->addDrawable(pyramidGeometry); pyramidGeode->addDrawable(geo2); root->addChild(pyramidGeode); osg::Vec3Array *vertices = new osg::Vec3Array; vertices->push_back(osg::Vec3(0, 0, 0)); vertices->push_back(osg::Vec3(10, 0, 0)); vertices->push_back(osg::Vec3(10, 10, 0)); vertices->push_back(osg::Vec3(0, 10, 0)); vertices->push_back(osg::Vec3(5, 5, 10)); pyramidGeometry->setVertexArray(vertices); geo2->setVertexArray(vertices); osg::Vec4Array *colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f)); colors->push_back(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f)); colors->push_back(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f)); colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f)); pyramidGeometry->setColorArray(colors); pyramidGeometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX); osg::DrawElementsUInt *base = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0); base->push_back(3); base->push_back(2); base->push_back(1); base->push_back(0); pyramidGeometry->addPrimitiveSet(base); /* osg::DrawElementsUInt *faceOne = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0); faceOne->push_back(0); faceOne->push_back(1); faceOne->push_back(4); pyramidGeometry->addPrimitiveSet(faceOne); osg::DrawElementsUInt *faceTwo = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0); faceTwo->push_back(1); faceTwo->push_back(2); faceTwo->push_back(4); pyramidGeometry->addPrimitiveSet(faceTwo); osg::DrawElementsUInt *faceThree = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0); faceThree->push_back(2); faceThree->push_back(3); faceThree->push_back(4); pyramidGeometry->addPrimitiveSet(faceThree); osg::DrawElementsUInt *faceFour = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0); faceFour->push_back(3); faceFour->push_back(0); faceFour->push_back(4); pyramidGeometry->addPrimitiveSet(faceFour); */ osg::DrawElementsUInt *indices = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0); indices->push_back(0); indices->push_back(1); indices->push_back(4); indices->push_back(1); indices->push_back(2); indices->push_back(4); indices->push_back(2); indices->push_back(3); indices->push_back(4); indices->push_back(3); indices->push_back(0); indices->push_back(4); pyramidGeometry->addPrimitiveSet(indices); root->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); // write file osgDB::ReaderWriter::WriteResult result = osgDB::Registry::instance()->writeNode(*root,"asdf.osg", osgDB::Registry::instance()->getOptions()); osgViewer::Viewer viewer; viewer.setSceneData(root); viewer.setCameraManipulator(new osgGA::TrackballManipulator()); viewer.setUpViewInWindow(0, 0, 640, 480); viewer.realize(); while (!viewer.done()) viewer.frame(); return 0; }