| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include <osgUtil/Optimizer> |
|---|
| 15 | #include <osgDB/ReadFile> |
|---|
| 16 | #include <osgProducer/Viewer> |
|---|
| 17 | |
|---|
| 18 | #include <osg/Material> |
|---|
| 19 | #include <osg/Geode> |
|---|
| 20 | #include <osg/BlendFunc> |
|---|
| 21 | #include <osg/Depth> |
|---|
| 22 | #include <osg/Projection> |
|---|
| 23 | #include <osg/AutoTransform> |
|---|
| 24 | #include <osg/Geometry> |
|---|
| 25 | |
|---|
| 26 | #include <osgText/Text> |
|---|
| 27 | |
|---|
| 28 | osg::Node* createLabel(const osg::Vec3& pos, float size, const std::string& label) |
|---|
| 29 | { |
|---|
| 30 | osg::Geode* geode = new osg::Geode(); |
|---|
| 31 | |
|---|
| 32 | std::string timesFont("fonts/arial.ttf"); |
|---|
| 33 | |
|---|
| 34 | { |
|---|
| 35 | osgText::Text* text = new osgText::Text; |
|---|
| 36 | geode->addDrawable( text ); |
|---|
| 37 | |
|---|
| 38 | text->setFont(timesFont); |
|---|
| 39 | text->setPosition(pos); |
|---|
| 40 | text->setCharacterSize(size); |
|---|
| 41 | text->setAlignment(osgText::Text::CENTER_CENTER); |
|---|
| 42 | text->setText(label); |
|---|
| 43 | |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | return geode; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | osg::Node* createLabel2(const osg::Vec3& pos, float size, const std::string& label) |
|---|
| 50 | { |
|---|
| 51 | osg::Geode* geode = new osg::Geode(); |
|---|
| 52 | |
|---|
| 53 | std::string timesFont("fonts/arial.ttf"); |
|---|
| 54 | |
|---|
| 55 | { |
|---|
| 56 | osgText::Text* text = new osgText::Text; |
|---|
| 57 | geode->addDrawable( text ); |
|---|
| 58 | |
|---|
| 59 | text->setFont(timesFont); |
|---|
| 60 | text->setPosition(pos); |
|---|
| 61 | text->setFontResolution(40,40); |
|---|
| 62 | text->setCharacterSize(size); |
|---|
| 63 | text->setAlignment(osgText::Text::CENTER_CENTER); |
|---|
| 64 | text->setAutoRotateToScreen(true); |
|---|
| 65 | text->setAutoScaleToLimitScreenSizeToFontResolution(true); |
|---|
| 66 | text->setDrawMode(osgText::Text::TEXT_PIXMAP); |
|---|
| 67 | text->setText(label); |
|---|
| 68 | |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | return geode; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | osg::Node* createLabel3(const osg::Vec3& pos, float size, const std::string& label) |
|---|
| 75 | { |
|---|
| 76 | osg::Geode* geode = new osg::Geode(); |
|---|
| 77 | |
|---|
| 78 | std::string timesFont("fonts/arial.ttf"); |
|---|
| 79 | |
|---|
| 80 | { |
|---|
| 81 | osgText::Text* text = new osgText::Text; |
|---|
| 82 | geode->addDrawable( text ); |
|---|
| 83 | |
|---|
| 84 | text->setFont(timesFont); |
|---|
| 85 | text->setPosition(pos); |
|---|
| 86 | text->setFontResolution(40,40); |
|---|
| 87 | text->setCharacterSize(size); |
|---|
| 88 | text->setAlignment(osgText::Text::CENTER_CENTER); |
|---|
| 89 | text->setAutoRotateToScreen(true); |
|---|
| 90 | text->setAutoScaleToLimitScreenSizeToFontResolution(true); |
|---|
| 91 | text->setText(label); |
|---|
| 92 | |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | return geode; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | osg::Node* createAxis(const osg::Vec3& s, const osg::Vec3& e, int numReps) |
|---|
| 99 | { |
|---|
| 100 | osg::Group* group = new osg::Group; |
|---|
| 101 | |
|---|
| 102 | osg::Vec3 dv = e-s; |
|---|
| 103 | dv /= float(numReps-1); |
|---|
| 104 | |
|---|
| 105 | osg::Vec3 pos = s; |
|---|
| 106 | |
|---|
| 107 | bool useAuto = false; |
|---|
| 108 | if (useAuto) |
|---|
| 109 | { |
|---|
| 110 | osg::Vec3Array* vertices = new osg::Vec3Array; |
|---|
| 111 | |
|---|
| 112 | for(int i=0;i<numReps;++i) |
|---|
| 113 | { |
|---|
| 114 | osg::AutoTransform* at = new osg::AutoTransform; |
|---|
| 115 | at->setPosition(pos); |
|---|
| 116 | at->setAutoRotateToScreen(true); |
|---|
| 117 | at->setAutoScaleToScreen(true); |
|---|
| 118 | at->addChild(createLabel(osg::Vec3(0.0f,0.0f,0.0f),40.0f,"Test 2")); |
|---|
| 119 | vertices->push_back(pos); |
|---|
| 120 | pos += dv; |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | group->addChild(at); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | osg::Vec4Array* colors = new osg::Vec4Array; |
|---|
| 127 | colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); |
|---|
| 128 | |
|---|
| 129 | osg::Geometry* geom = new osg::Geometry; |
|---|
| 130 | geom->setVertexArray(vertices); |
|---|
| 131 | geom->setColorArray(colors); |
|---|
| 132 | geom->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP,0,vertices->size())); |
|---|
| 133 | |
|---|
| 134 | osg::Geode* geode = new osg::Geode; |
|---|
| 135 | geode->addDrawable(geom); |
|---|
| 136 | |
|---|
| 137 | group->addChild(geode); |
|---|
| 138 | } |
|---|
| 139 | else |
|---|
| 140 | { |
|---|
| 141 | osg::Vec3Array* vertices = new osg::Vec3Array; |
|---|
| 142 | |
|---|
| 143 | for(int i=0;i<numReps;++i) |
|---|
| 144 | { |
|---|
| 145 | group->addChild(createLabel3(osg::Vec3(pos),dv.length()*0.5f,"Test 2")); |
|---|
| 146 | vertices->push_back(pos); |
|---|
| 147 | pos += dv; |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | osg::Vec4Array* colors = new osg::Vec4Array; |
|---|
| 153 | colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); |
|---|
| 154 | |
|---|
| 155 | osg::Geometry* geom = new osg::Geometry; |
|---|
| 156 | geom->setVertexArray(vertices); |
|---|
| 157 | geom->setColorArray(colors); |
|---|
| 158 | geom->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP,0,vertices->size())); |
|---|
| 159 | |
|---|
| 160 | osg::Geode* geode = new osg::Geode; |
|---|
| 161 | geode->addDrawable(geom); |
|---|
| 162 | |
|---|
| 163 | group->addChild(geode); |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | return group; |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | osg::Node* createScene() |
|---|
| 170 | { |
|---|
| 171 | osg::Group* root = new osg::Group; |
|---|
| 172 | |
|---|
| 173 | int numReps = 3333; |
|---|
| 174 | |
|---|
| 175 | root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(1000.0,0.0,0.0),numReps)); |
|---|
| 176 | root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0,1000.0,0.0),numReps)); |
|---|
| 177 | root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0,0.0,1000.0),numReps)); |
|---|
| 178 | |
|---|
| 179 | return root; |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | int main( int argc, char **argv ) |
|---|
| 183 | { |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates how to do Head Up Displays."); |
|---|
| 190 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] [filename] ..."); |
|---|
| 191 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | osgProducer::Viewer viewer(arguments); |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | viewer.getUsage(*arguments.getApplicationUsage()); |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 205 | { |
|---|
| 206 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 207 | return 1; |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | if (arguments.errors()) |
|---|
| 215 | { |
|---|
| 216 | arguments.writeErrorMessages(std::cout); |
|---|
| 217 | return 1; |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | viewer.setSceneData(createScene()); |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | viewer.realize(); |
|---|
| 226 | |
|---|
| 227 | while( !viewer.done() ) |
|---|
| 228 | { |
|---|
| 229 | |
|---|
| 230 | viewer.sync(); |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | viewer.update(); |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | viewer.frame(); |
|---|
| 238 | |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | viewer.sync(); |
|---|
| 243 | |
|---|
| 244 | return 0; |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | |
|---|
| 255 | |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | } |
|---|