/* File: ex_cone.cpp */ #include #include #include #include #include #include #include #include using namespace osg; void usage() { std::cout << "usage: ex_cone\n"; exit(0); } int main( int argc, char **argv ) { if (argc != 1) usage(); // initialize the viewer. osgViewer::Viewer viewer; // create parameters to define a cone float radius = 2.0; float height = 2.0; float xcen = 0.0f; float ycen = 0.0f; float zcen = 0.0f; float color[4] = {0.5, 0.5, 0.8, 1.0}; // Create a vector to represent the "center of the cone" Vec3 vcen(xcen, ycen, zcen); Cone* cone = new Cone(vcen, radius, height); // Create a drawable object based on the cone ShapeDrawable *drawable = new ShapeDrawable(cone); drawable->setColor(Vec4(color[0], color[1], color[2], color[3])); Geode* geode = new Geode(); geode->addDrawable(drawable); // tilt the scene so the default eye position is looking down on the model. // and add the cone geode MatrixTransform* rootnode = new MatrixTransform; rootnode->setMatrix(Matrix::rotate(inDegrees(30.0), 1.0, 0.0, 0.0)); rootnode->addChild(geode); // run optimization over the scene graph osgUtil::Optimizer optimzer; optimzer.optimize(rootnode); // set the scene to render viewer.setSceneData(rootnode); viewer.setCameraManipulator(new osgGA::TrackballManipulator()); // normal viewer usage. return viewer.run(); }