| 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, osgText::Text::AxisAlignment axisAlignment) |
|---|
| 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->setAxisAlignment(axisAlignment); |
|---|
| 42 | text->setAlignment(osgText::Text::CENTER_CENTER); |
|---|
| 43 | text->setText(label); |
|---|
| 44 | |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | return geode; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | osg::Node* createLabel3(const osg::Vec3& pos, float size, const std::string& label) |
|---|
| 52 | { |
|---|
| 53 | osg::Geode* geode = new osg::Geode(); |
|---|
| 54 | |
|---|
| 55 | std::string timesFont("fonts/arial.ttf"); |
|---|
| 56 | |
|---|
| 57 | { |
|---|
| 58 | osgText::Text* text = new osgText::Text; |
|---|
| 59 | geode->addDrawable( text ); |
|---|
| 60 | |
|---|
| 61 | text->setFont(timesFont); |
|---|
| 62 | text->setPosition(pos); |
|---|
| 63 | text->setFontResolution(40,40); |
|---|
| 64 | text->setCharacterSize(size); |
|---|
| 65 | text->setAlignment(osgText::Text::CENTER_CENTER); |
|---|
| 66 | text->setAutoRotateToScreen(true); |
|---|
| 67 | text->setCharacterSizeMode(osgText::Text::OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT); |
|---|
| 68 | text->setText(label); |
|---|
| 69 | |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | return geode; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | osg::Node* createAxis(const osg::Vec3& s, const osg::Vec3& e, int numReps, osg::AutoTransform::AutoRotateMode autoRotateMode, osgText::Text::AxisAlignment axisAlignment, const std::string& str) |
|---|
| 76 | { |
|---|
| 77 | osg::Group* group = new osg::Group; |
|---|
| 78 | |
|---|
| 79 | osg::Vec3 dv = e-s; |
|---|
| 80 | dv /= float(numReps-1); |
|---|
| 81 | |
|---|
| 82 | osg::Vec3 pos = s; |
|---|
| 83 | |
|---|
| 84 | bool useAuto = true; |
|---|
| 85 | if (useAuto) |
|---|
| 86 | { |
|---|
| 87 | osg::Vec3Array* vertices = new osg::Vec3Array; |
|---|
| 88 | |
|---|
| 89 | for(int i=0;i<numReps;++i) |
|---|
| 90 | { |
|---|
| 91 | osg::AutoTransform* at = new osg::AutoTransform; |
|---|
| 92 | at->setPosition(pos); |
|---|
| 93 | at->setAutoRotateMode(autoRotateMode); |
|---|
| 94 | at->addChild(createLabel(osg::Vec3(0.0f,0.0f,0.0f),dv.length()*0.2f,str, axisAlignment)); |
|---|
| 95 | vertices->push_back(pos); |
|---|
| 96 | pos += dv; |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | group->addChild(at); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | osg::Vec4Array* colors = new osg::Vec4Array; |
|---|
| 103 | colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); |
|---|
| 104 | |
|---|
| 105 | osg::Geometry* geom = new osg::Geometry; |
|---|
| 106 | geom->setVertexArray(vertices); |
|---|
| 107 | geom->setColorArray(colors); |
|---|
| 108 | geom->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP,0,vertices->size())); |
|---|
| 109 | |
|---|
| 110 | osg::Geode* geode = new osg::Geode; |
|---|
| 111 | geode->addDrawable(geom); |
|---|
| 112 | |
|---|
| 113 | group->addChild(geode); |
|---|
| 114 | } |
|---|
| 115 | else |
|---|
| 116 | { |
|---|
| 117 | osg::Vec3Array* vertices = new osg::Vec3Array; |
|---|
| 118 | |
|---|
| 119 | for(int i=0;i<numReps;++i) |
|---|
| 120 | { |
|---|
| 121 | group->addChild(createLabel3(osg::Vec3(pos),dv.length()*0.5f,str)); |
|---|
| 122 | vertices->push_back(pos); |
|---|
| 123 | pos += dv; |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | osg::Vec4Array* colors = new osg::Vec4Array; |
|---|
| 129 | colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); |
|---|
| 130 | |
|---|
| 131 | osg::Geometry* geom = new osg::Geometry; |
|---|
| 132 | geom->setVertexArray(vertices); |
|---|
| 133 | geom->setColorArray(colors); |
|---|
| 134 | geom->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP,0,vertices->size())); |
|---|
| 135 | |
|---|
| 136 | osg::Geode* geode = new osg::Geode; |
|---|
| 137 | geode->addDrawable(geom); |
|---|
| 138 | |
|---|
| 139 | group->addChild(geode); |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | return group; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | osg::Node* createScene() |
|---|
| 146 | { |
|---|
| 147 | osg::Group* root = new osg::Group; |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | int numReps = 10; |
|---|
| 151 | root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(1000.0,0.0,0.0),numReps,osg::AutoTransform::ROTATE_TO_CAMERA,osgText::Text::XY_PLANE, "ROTATE_TO_CAMERA")); |
|---|
| 152 | root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0,1000.0,0.0),numReps,osg::AutoTransform::ROTATE_TO_SCREEN,osgText::Text::XY_PLANE, "ROTATE_TO_SCREEN")); |
|---|
| 153 | root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0,0.0,1000.0),numReps,osg::AutoTransform::NO_ROTATION,osgText::Text::XZ_PLANE, "NO_ROTATION")); |
|---|
| 154 | |
|---|
| 155 | return root; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | int main( int argc, char **argv ) |
|---|
| 159 | { |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates how to do Head Up Displays."); |
|---|
| 166 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] [filename] ..."); |
|---|
| 167 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | osgProducer::Viewer viewer(arguments); |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | viewer.getUsage(*arguments.getApplicationUsage()); |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 181 | { |
|---|
| 182 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 183 | return 1; |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | if (arguments.errors()) |
|---|
| 191 | { |
|---|
| 192 | arguments.writeErrorMessages(std::cout); |
|---|
| 193 | return 1; |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | viewer.setSceneData(createScene()); |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | viewer.realize(); |
|---|
| 202 | |
|---|
| 203 | while( !viewer.done() ) |
|---|
| 204 | { |
|---|
| 205 | |
|---|
| 206 | viewer.sync(); |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | viewer.update(); |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | viewer.frame(); |
|---|
| 214 | |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | viewer.sync(); |
|---|
| 219 | |
|---|
| 220 | return 0; |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | } |
|---|