| 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 | #include <osg/Projection> |
|---|
| 10 | |
|---|
| 11 | #include <osgUtil/Tesselator> |
|---|
| 12 | #include <osgUtil/TransformCallback> |
|---|
| 13 | #include <osgUtil/CullVisitor> |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | #include <osgGA/TrackballManipulator> |
|---|
| 17 | #include <osgProducer/Viewer> |
|---|
| 18 | #include <osgDB/ReadFile> |
|---|
| 19 | |
|---|
| 20 | #include <osgSim/ScalarsToColors> |
|---|
| 21 | #include <osgSim/ColorRange> |
|---|
| 22 | #include <osgSim/ScalarBar> |
|---|
| 23 | |
|---|
| 24 | #include <sstream> |
|---|
| 25 | #include <math.h> |
|---|
| 26 | |
|---|
| 27 | using namespace osgSim; |
|---|
| 28 | using osgSim::ScalarBar; |
|---|
| 29 | |
|---|
| 30 | osg::Node* createScalarBar() |
|---|
| 31 | { |
|---|
| 32 | #if 1 |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | std::vector<osg::Vec4> cs; |
|---|
| 38 | cs.push_back(osg::Vec4(1.0f,0.0f,0.0f,1.0f)); |
|---|
| 39 | cs.push_back(osg::Vec4(0.0f,1.0f,0.0f,1.0f)); |
|---|
| 40 | cs.push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); |
|---|
| 41 | cs.push_back(osg::Vec4(0.0f,0.0f,1.0f,1.0f)); |
|---|
| 42 | cs.push_back(osg::Vec4(0.0f,1.0f,1.0f,1.0f)); |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | struct MyScalarPrinter: public ScalarBar::ScalarPrinter |
|---|
| 46 | { |
|---|
| 47 | std::string printScalar(float scalar) |
|---|
| 48 | { |
|---|
| 49 | std::cout<<"In MyScalarPrinter::printScalar"<<std::endl; |
|---|
| 50 | if(scalar==0.0f) return ScalarBar::ScalarPrinter::printScalar(scalar)+" Bottom"; |
|---|
| 51 | else if(scalar==0.5f) return ScalarBar::ScalarPrinter::printScalar(scalar)+" Middle"; |
|---|
| 52 | else if(scalar==1.0f) return ScalarBar::ScalarPrinter::printScalar(scalar)+" Top"; |
|---|
| 53 | else return ScalarBar::ScalarPrinter::printScalar(scalar); |
|---|
| 54 | } |
|---|
| 55 | }; |
|---|
| 56 | |
|---|
| 57 | ColorRange* cr = new ColorRange(0.0f,1.0f,cs); |
|---|
| 58 | ScalarBar* sb = new ScalarBar(20, 11, cr, "ScalarBar", ScalarBar::VERTICAL, 0.1f, new MyScalarPrinter); |
|---|
| 59 | sb->setScalarPrinter(new MyScalarPrinter); |
|---|
| 60 | |
|---|
| 61 | return sb; |
|---|
| 62 | #else |
|---|
| 63 | ScalarBar *sb = new ScalarBar; |
|---|
| 64 | ScalarBar::TextProperties tp; |
|---|
| 65 | tp._fontFile = "fonts/times.ttf"; |
|---|
| 66 | |
|---|
| 67 | sb->setTextProperties(tp); |
|---|
| 68 | |
|---|
| 69 | return sb; |
|---|
| 70 | #endif |
|---|
| 71 | |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | osg::Node * createScalarBar_HUD() |
|---|
| 75 | { |
|---|
| 76 | osgSim::ScalarBar * geode = new osgSim::ScalarBar; |
|---|
| 77 | osgSim::ScalarBar::TextProperties tp; |
|---|
| 78 | tp._fontFile = "fonts/times.ttf"; |
|---|
| 79 | geode->setTextProperties(tp); |
|---|
| 80 | osg::StateSet * stateset = geode->getOrCreateStateSet(); |
|---|
| 81 | stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF); |
|---|
| 82 | |
|---|
| 83 | stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); |
|---|
| 84 | stateset->setRenderBinDetails(11, "RenderBin"); |
|---|
| 85 | |
|---|
| 86 | osg::MatrixTransform * modelview = new osg::MatrixTransform; |
|---|
| 87 | modelview->setReferenceFrame(osg::Transform::RELATIVE_TO_ABSOLUTE); |
|---|
| 88 | osg::Matrixd matrix(osg::Matrixd::scale(1000,1000,1000) * osg::Matrixd::translate(120,10,0)); |
|---|
| 89 | modelview->setMatrix(matrix); |
|---|
| 90 | modelview->addChild(geode); |
|---|
| 91 | |
|---|
| 92 | osg::Projection * projection = new osg::Projection; |
|---|
| 93 | projection->setMatrix(osg::Matrix::ortho2D(0,1280,0,1024)); |
|---|
| 94 | projection->addChild(modelview); |
|---|
| 95 | |
|---|
| 96 | return projection; |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | int main( int argc, char **argv ) |
|---|
| 100 | { |
|---|
| 101 | |
|---|
| 102 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates both text, animation and billboard via custom transform to create the OpenSceneGraph logo.."); |
|---|
| 106 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); |
|---|
| 107 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 108 | arguments.getApplicationUsage()->addCommandLineOption("ps","Render the Professional Services logo"); |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | osgProducer::Viewer viewer(arguments); |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | viewer.getUsage(*arguments.getApplicationUsage()); |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 121 | { |
|---|
| 122 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 123 | return 1; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | if (arguments.errors()) |
|---|
| 131 | { |
|---|
| 132 | arguments.writeErrorMessages(std::cout); |
|---|
| 133 | return 1; |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | osg::Group* group = new osg::Group; |
|---|
| 137 | group->addChild(createScalarBar()); |
|---|
| 138 | group->addChild(createScalarBar_HUD()); |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | viewer.setSceneData( group ); |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | viewer.realize(); |
|---|
| 145 | |
|---|
| 146 | while( !viewer.done() ) |
|---|
| 147 | { |
|---|
| 148 | |
|---|
| 149 | viewer.sync(); |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | viewer.update(); |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | viewer.frame(); |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | viewer.sync(); |
|---|
| 161 | |
|---|
| 162 | return 0; |
|---|
| 163 | } |
|---|