| 1 | #include <osg/Geode> |
|---|
| 2 | #include <osg/ShapeDrawable> |
|---|
| 3 | #include <osg/Material> |
|---|
| 4 | #include <osg/Texture2D> |
|---|
| 5 | #include <osg/MatrixTransform> |
|---|
| 6 | #include <osg/PositionAttitudeTransform> |
|---|
| 7 | #include <osg/BlendFunc> |
|---|
| 8 | #include <osg/ClearNode> |
|---|
| 9 | |
|---|
| 10 | #include <osgUtil/Tesselator> |
|---|
| 11 | #include <osgUtil/TransformCallback> |
|---|
| 12 | #include <osgUtil/CullVisitor> |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #include <osgGA/TrackballManipulator> |
|---|
| 16 | #include <osgProducer/Viewer> |
|---|
| 17 | #include <osgDB/ReadFile> |
|---|
| 18 | |
|---|
| 19 | #include <osgSim/ScalarsToColors> |
|---|
| 20 | #include <osgSim/ColorRange> |
|---|
| 21 | #include <osgSim/ScalarBar> |
|---|
| 22 | |
|---|
| 23 | #include <sstream> |
|---|
| 24 | #include <math.h> |
|---|
| 25 | |
|---|
| 26 | using namespace osgSim; |
|---|
| 27 | |
|---|
| 28 | osg::Node* createScalarBar() |
|---|
| 29 | { |
|---|
| 30 | #if 1 |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | std::vector<osg::Vec4> cs; |
|---|
| 36 | cs.push_back(osg::Vec4(1.0f,0.0f,0.0f,1.0f)); |
|---|
| 37 | cs.push_back(osg::Vec4(0.0f,1.0f,0.0f,1.0f)); |
|---|
| 38 | cs.push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); |
|---|
| 39 | cs.push_back(osg::Vec4(0.0f,0.0f,1.0f,1.0f)); |
|---|
| 40 | cs.push_back(osg::Vec4(0.0f,1.0f,1.0f,1.0f)); |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | struct MyScalarPrinter: public ScalarBar::ScalarPrinter |
|---|
| 44 | { |
|---|
| 45 | std::string printScalar(float scalar) |
|---|
| 46 | { |
|---|
| 47 | std::cout<<"In MyScalarPrinter::printScalar"<<std::endl; |
|---|
| 48 | if(scalar==0.0f) return ScalarBar::ScalarPrinter::printScalar(scalar)+" Bottom"; |
|---|
| 49 | else if(scalar==0.5f) return ScalarBar::ScalarPrinter::printScalar(scalar)+" Middle"; |
|---|
| 50 | else if(scalar==1.0f) return ScalarBar::ScalarPrinter::printScalar(scalar)+" Top"; |
|---|
| 51 | else return ScalarBar::ScalarPrinter::printScalar(scalar); |
|---|
| 52 | } |
|---|
| 53 | }; |
|---|
| 54 | |
|---|
| 55 | ColorRange* cr = new ColorRange(0.0f,1.0f,cs); |
|---|
| 56 | ScalarBar* sb = new ScalarBar(20, 11, cr, "ScalarBar", ScalarBar::VERTICAL, 4.0f, new MyScalarPrinter); |
|---|
| 57 | sb->setScalarPrinter(new MyScalarPrinter); |
|---|
| 58 | |
|---|
| 59 | return sb; |
|---|
| 60 | #else |
|---|
| 61 | ScalarBar *sb = new ScalarBar; |
|---|
| 62 | ScalarBar::TextProperties tp; |
|---|
| 63 | tp._fontFile = "fonts/times.ttf"; |
|---|
| 64 | |
|---|
| 65 | sb->setTextProperties(tp); |
|---|
| 66 | |
|---|
| 67 | return sb; |
|---|
| 68 | #endif |
|---|
| 69 | |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | int main( int argc, char **argv ) |
|---|
| 73 | { |
|---|
| 74 | |
|---|
| 75 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates both text, animation and billboard via custom transform to create the OpenSceneGraph logo.."); |
|---|
| 79 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); |
|---|
| 80 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 81 | arguments.getApplicationUsage()->addCommandLineOption("ps","Render the Professional Services logo"); |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | osgProducer::Viewer viewer(arguments); |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | viewer.getUsage(*arguments.getApplicationUsage()); |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 94 | { |
|---|
| 95 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 96 | return 1; |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | if (arguments.errors()) |
|---|
| 104 | { |
|---|
| 105 | arguments.writeErrorMessages(std::cout); |
|---|
| 106 | return 1; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | osg::Node* node = createScalarBar(); |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | viewer.setSceneData( node ); |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | viewer.realize(); |
|---|
| 116 | |
|---|
| 117 | while( !viewer.done() ) |
|---|
| 118 | { |
|---|
| 119 | |
|---|
| 120 | viewer.sync(); |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | viewer.update(); |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | viewer.frame(); |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | viewer.sync(); |
|---|
| 132 | |
|---|
| 133 | return 0; |
|---|
| 134 | } |
|---|