| 1 | #include <osg/Geode> |
|---|
| 2 | #include <osg/ShapeDrawable> |
|---|
| 3 | #include <osg/Material> |
|---|
| 4 | #include <osg/Texture2D> |
|---|
| 5 | #include <osg/Geometry> |
|---|
| 6 | #include <osg/MatrixTransform> |
|---|
| 7 | #include <osg/PositionAttitudeTransform> |
|---|
| 8 | #include <osg/BlendFunc> |
|---|
| 9 | #include <osg/ClearNode> |
|---|
| 10 | |
|---|
| 11 | #include <osgUtil/Tesselator> |
|---|
| 12 | #include <osgUtil/TransformCallback> |
|---|
| 13 | #include <osgUtil/CullVisitor> |
|---|
| 14 | |
|---|
| 15 | #include <osgText/Text> |
|---|
| 16 | |
|---|
| 17 | #include <osgGA/TrackballManipulator> |
|---|
| 18 | #include <osgProducer/Viewer> |
|---|
| 19 | #include <osgDB/ReadFile> |
|---|
| 20 | |
|---|
| 21 | #include <osgSim/SphereSegment> |
|---|
| 22 | |
|---|
| 23 | using namespace osgSim; |
|---|
| 24 | |
|---|
| 25 | class MyNodeCallback: public osg::NodeCallback |
|---|
| 26 | { |
|---|
| 27 | void operator()(osg::Node*,osg::NodeVisitor*); |
|---|
| 28 | }; |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | void MyNodeCallback::operator()(osg::Node* n,osg::NodeVisitor* nv) |
|---|
| 57 | { |
|---|
| 58 | if(osgSim::SphereSegment* ss=dynamic_cast<osgSim::SphereSegment*>(n)) |
|---|
| 59 | { |
|---|
| 60 | osg::Vec3 vec; |
|---|
| 61 | float azRange, elevRange; |
|---|
| 62 | ss->getArea(vec,azRange,elevRange); |
|---|
| 63 | |
|---|
| 64 | static float angle = 0.0f; |
|---|
| 65 | if(++angle > 359.0f) angle = 0.0f; |
|---|
| 66 | vec.set(sin(osg::DegreesToRadians(angle)),cos(osg::DegreesToRadians(angle)),0.0f); |
|---|
| 67 | |
|---|
| 68 | std::cout<<"angle "<<angle<<" degrees, vec is "<<vec |
|---|
| 69 | <<", azRange is "<<osg::RadiansToDegrees(azRange) |
|---|
| 70 | <<", elevRange is "<<osg::RadiansToDegrees(elevRange) |
|---|
| 71 | <<std::endl; |
|---|
| 72 | |
|---|
| 73 | ss->setArea(vec,azRange,elevRange); |
|---|
| 74 | } |
|---|
| 75 | traverse(n,nv); |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | osg::Node* createSphereSegment() |
|---|
| 79 | { |
|---|
| 80 | SphereSegment* ss = new SphereSegment(osg::Vec3(0.0f,0.0f,0.0f), 1.0f, |
|---|
| 81 | osg::Vec3(0.0f,1.0f,0.0f), |
|---|
| 82 | osg::DegreesToRadians(90.0f), |
|---|
| 83 | osg::DegreesToRadians(45.0f), |
|---|
| 84 | 60); |
|---|
| 85 | ss->setAllColors(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); |
|---|
| 86 | ss->setSideColor(osg::Vec4(0.0f,0.0f,1.0f,0.1f)); |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | return ss; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | int main( int argc, char **argv ) |
|---|
| 95 | { |
|---|
| 96 | |
|---|
| 97 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates both text, animation and billboard via custom transform to create the OpenSceneGraph logo.."); |
|---|
| 101 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); |
|---|
| 102 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 103 | arguments.getApplicationUsage()->addCommandLineOption("ps","Render the Professional Services logo"); |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | osgProducer::Viewer viewer(arguments); |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | viewer.getUsage(*arguments.getApplicationUsage()); |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 116 | { |
|---|
| 117 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 118 | return 1; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | if (arguments.errors()) |
|---|
| 126 | { |
|---|
| 127 | arguments.writeErrorMessages(std::cout); |
|---|
| 128 | return 1; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | osg::Node* node = createSphereSegment(); |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | viewer.setSceneData( node ); |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | viewer.realize(); |
|---|
| 138 | |
|---|
| 139 | while( !viewer.done() ) |
|---|
| 140 | { |
|---|
| 141 | |
|---|
| 142 | viewer.sync(); |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | viewer.update(); |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | viewer.frame(); |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | viewer.sync(); |
|---|
| 154 | |
|---|
| 155 | return 0; |
|---|
| 156 | } |
|---|