/* File: ex_arrow.cpp */ #include #include #include #include #include #include #include #include using namespace osg; Geode *make_cone(float xcen, float ycen, float zcen, float radius, float height, float r, float g, float b, float alpha) { Cone* cone = new Cone(Vec3(xcen, ycen, zcen), radius, height); ShapeDrawable *drawable = new ShapeDrawable(cone); drawable->setColor(Vec4(r, g, b, alpha)); Geode* geode = new Geode(); geode->addDrawable(drawable); return geode; } Geode *make_cylinder(float xcen, float ycen, float zcen, float radius, float height, float r, float g, float b, float alpha) { Cylinder* cylinder = new Cylinder(Vec3(xcen, ycen, zcen), radius, height); ShapeDrawable *drawable = new ShapeDrawable(cylinder); drawable->setColor(Vec4(r, g, b, alpha)); Geode* geode = new Geode(); geode->addDrawable(drawable); return geode; } void usage() { std::cout << "usage: ex_arrow\n"; exit(0); } int main( int argc, char **argv ) { if (argc != 1) usage(); // initialize the viewer. osgViewer::Viewer viewer; // Create an arrow // first create a cone float radius = 0.5; float height = 1.0; float xcen = 0.0f; float ycen = 0.0f; float zcen = 2.25f; float r = 0.7; float g = 0.5; float b = 0.3; float alpha = 1.0; Geode *cone = make_cone(xcen, ycen, zcen, radius, height, r, g, b, alpha); // second create a cylinder radius = 0.25; height = 2.0; xcen = 0.0f; ycen = 0.0f; zcen = 1.0f; r = 0.4; g = 0.6; b = 0.5; alpha = 1.0; Geode *cylinder = make_cylinder(xcen, ycen, zcen, radius, height, r, g, b, alpha); // create an arrow, as a transform node which parents the cone and the cylinder MatrixTransform* arrow = new MatrixTransform; arrow->setMatrix(Matrix::scale(1.0, 1.0, 1.0)); arrow->addChild(cone); arrow->addChild(cylinder); // add the arrow to the scene root node MatrixTransform* rootnode = new MatrixTransform; rootnode->setMatrix(Matrix::rotate(inDegrees(30.0), 1.0, 0.0, 0.0)); rootnode->addChild(arrow); // 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(); }