| [6941] | 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| [5928] | 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| [5939] | 20 | |
|---|
| 21 | |
|---|
| [5928] | 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | #include <osgDB/ReadFile> |
|---|
| 31 | #include <osgUtil/Optimizer> |
|---|
| [5962] | 32 | #include <osgViewer/Viewer> |
|---|
| [5928] | 33 | #include <osg/Projection> |
|---|
| 34 | #include <osg/MatrixTransform> |
|---|
| 35 | |
|---|
| 36 | #include <osgText/Text> |
|---|
| 37 | |
|---|
| [5939] | 38 | #include <osgUtil/Tessellator> // to tessellate multiple contours |
|---|
| [5928] | 39 | |
|---|
| 40 | |
|---|
| [5939] | 41 | class tessellateDemoGeometry : public osg::Geometry, public osgUtil::Tessellator { |
|---|
| [5928] | 42 | |
|---|
| [5939] | 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| [5928] | 46 | public: |
|---|
| [5939] | 47 | tessellateDemoGeometry() {}; |
|---|
| [5928] | 48 | |
|---|
| 49 | protected: |
|---|
| [5939] | 50 | virtual ~tessellateDemoGeometry() {}; |
|---|
| [5928] | 51 | }; |
|---|
| 52 | |
|---|
| 53 | osg::Geometry *makePolsTwo (void) |
|---|
| 54 | { |
|---|
| [5939] | 55 | |
|---|
| [5928] | 56 | |
|---|
| [5939] | 57 | tessellateDemoGeometry *gtess= new tessellateDemoGeometry; |
|---|
| [5928] | 58 | int i; |
|---|
| 59 | osg::Vec3Array *coords = new osg::Vec3Array; |
|---|
| 60 | osg::Vec3Array *nrms = new osg::Vec3Array; |
|---|
| 61 | osg::Vec2Array *tcs = new osg::Vec2Array; |
|---|
| 62 | osg::Vec3 nrm(0,-1,0); |
|---|
| 63 | static GLdouble quadstrip[8][3] = |
|---|
| 64 | { { 1900.0, 1130.0, 0.0 }, |
|---|
| 65 | { 2100.0, 1130.0, 0.0 }, |
|---|
| 66 | { 1900.0, 1350.0, 0.0 }, |
|---|
| 67 | { 1950.0, 1350.0, 0.0 }, |
|---|
| 68 | { 1900.0, 1550.0, 0.0 }, |
|---|
| 69 | { 2000.0, 1550.0, 0.0 }, |
|---|
| 70 | { 1900.0, 1750.0, 0.0 }, |
|---|
| 71 | { 2400.0, 1750.0, 0.0 } }; |
|---|
| 72 | static GLdouble innerquadstrip[8][3] = |
|---|
| 73 | { { 2000.0, 1230.0, 0.0 }, |
|---|
| 74 | { 2050.0, 1230.0, 0.0 }, |
|---|
| 75 | { 1920.0, 1350.0, 0.0 }, |
|---|
| 76 | { 1940.0, 1350.0, 0.0 }, |
|---|
| 77 | { 1920.0, 1550.0, 0.0 }, |
|---|
| 78 | { 1980.0, 1550.0, 0.0 }, |
|---|
| 79 | { 2000.0, 1650.0, 0.0 }, |
|---|
| 80 | { 2400.0, 1650.0, 0.0 } }; |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | for (i = 0; i < 8; i++) |
|---|
| 84 | { |
|---|
| 85 | coords->push_back(osg::Vec3(quadstrip[i][0],quadstrip[i][2],quadstrip[i][1])); |
|---|
| 86 | tcs->push_back(osg::Vec2(quadstrip[i][0],quadstrip[i][1])/200.0); |
|---|
| 87 | nrms->push_back(nrm); |
|---|
| 88 | } |
|---|
| 89 | for (i = 0; i < 8; i++) { |
|---|
| 90 | coords->push_back(osg::Vec3(innerquadstrip[i][0],innerquadstrip[i][2],innerquadstrip[i][1])); |
|---|
| 91 | tcs->push_back(osg::Vec2(innerquadstrip[i][0],innerquadstrip[i][1])/200.0); |
|---|
| 92 | nrms->push_back(nrm); |
|---|
| 93 | } |
|---|
| 94 | gtess->setVertexArray(coords); |
|---|
| 95 | gtess->setNormalArray(nrms); |
|---|
| 96 | gtess->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); |
|---|
| 97 | gtess->setTexCoordArray(0,tcs); |
|---|
| 98 | |
|---|
| [5939] | 99 | |
|---|
| [5928] | 100 | osg::StateSet* stateset = new osg::StateSet(); |
|---|
| 101 | |
|---|
| 102 | osg::Image* image = osgDB::readImageFile("Cubemap_snow/posy.jpg"); |
|---|
| 103 | if (image) |
|---|
| 104 | { |
|---|
| 105 | osg::Texture2D* texture = new osg::Texture2D; |
|---|
| 106 | texture->setImage(image); |
|---|
| 107 | texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT); |
|---|
| 108 | texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT); |
|---|
| 109 | stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); |
|---|
| 110 | } |
|---|
| 111 | gtess->setStateSet( stateset ); |
|---|
| 112 | |
|---|
| 113 | int nstart=0; |
|---|
| [5939] | 114 | |
|---|
| [5928] | 115 | gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP,nstart,8));nstart+=8; |
|---|
| 116 | gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP,nstart,8));nstart+=8; |
|---|
| 117 | |
|---|
| 118 | gtess->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); |
|---|
| 119 | gtess->setBoundaryOnly(true); |
|---|
| [5939] | 120 | gtess->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); |
|---|
| [5928] | 121 | |
|---|
| 122 | return gtess; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | osg::Geometry *makeSideWall (const float xpos) |
|---|
| 126 | { |
|---|
| 127 | |
|---|
| 128 | osg::Geometry *gtess= new osg::Geometry; |
|---|
| 129 | int i; |
|---|
| 130 | osg::Vec3Array *coords = new osg::Vec3Array; |
|---|
| 131 | osg::Vec3Array *nrms = new osg::Vec3Array; |
|---|
| 132 | osg::Vec2Array *tcs = new osg::Vec2Array; |
|---|
| 133 | osg::Vec3 nrm(-1,0,0); |
|---|
| 134 | |
|---|
| 135 | static GLdouble wall[4][2] = |
|---|
| 136 | { { 1130.0, 0.0 }, |
|---|
| 137 | { 1130.0, 300.0 } , |
|---|
| 138 | { 1340.0,300.0 }, |
|---|
| 139 | { 1340.0,0.0 } }; |
|---|
| 140 | |
|---|
| 141 | gtess->setVertexArray(coords); |
|---|
| 142 | gtess->setNormalArray(nrms); |
|---|
| 143 | gtess->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); |
|---|
| 144 | gtess->setTexCoordArray(0,tcs); |
|---|
| 145 | |
|---|
| 146 | for (i = 0; i < 4; i++) { |
|---|
| 147 | coords->push_back(osg::Vec3(xpos,wall[i][1],wall[i][0])); |
|---|
| 148 | tcs->push_back(osg::Vec2(wall[i][1],wall[i][0])/100.0); |
|---|
| 149 | nrms->push_back(nrm); |
|---|
| 150 | } |
|---|
| 151 | int nstart=0; |
|---|
| 152 | |
|---|
| 153 | gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,nstart,4));nstart+=4; |
|---|
| 154 | for (i = 0; i < 24; i++) { |
|---|
| 155 | float y=150+50*cos(i*2*osg::PI/24.0); |
|---|
| 156 | float z=1300+30* sin(i*2*osg::PI/24.0); |
|---|
| 157 | coords->push_back(osg::Vec3(xpos,y,z)); |
|---|
| 158 | tcs->push_back(osg::Vec2(y,z)/100.0); |
|---|
| 159 | nrms->push_back(nrm); |
|---|
| 160 | } |
|---|
| 161 | gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,nstart,24));nstart+=24; |
|---|
| 162 | for (i = 0; i < 5; i++) { |
|---|
| 163 | float y=150+50*cos(i*2*osg::PI/5.0); |
|---|
| 164 | float z=1200+40* sin(i*2*osg::PI/5.0); |
|---|
| 165 | coords->push_back(osg::Vec3(xpos,y,z)); |
|---|
| 166 | tcs->push_back(osg::Vec2(y,z)/100.0); |
|---|
| 167 | nrms->push_back(nrm); |
|---|
| 168 | } |
|---|
| 169 | gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,nstart,5));nstart+=5; |
|---|
| 170 | |
|---|
| [5939] | 171 | |
|---|
| [5928] | 172 | osg::StateSet* stateset = new osg::StateSet(); |
|---|
| 173 | |
|---|
| 174 | osg::Image* image = osgDB::readImageFile("Cubemap_snow/posx.jpg"); |
|---|
| 175 | if (image) |
|---|
| 176 | { |
|---|
| 177 | osg::Texture2D* texture = new osg::Texture2D; |
|---|
| 178 | texture->setImage(image); |
|---|
| 179 | texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT); |
|---|
| 180 | texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT); |
|---|
| 181 | stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); |
|---|
| 182 | } |
|---|
| 183 | gtess->setStateSet( stateset ); |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | osg::ref_ptr<osgUtil::Tessellator> tscx=new osgUtil::Tessellator; |
|---|
| [5939] | 187 | |
|---|
| [5928] | 188 | |
|---|
| 189 | tscx->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); |
|---|
| 190 | tscx->setBoundaryOnly(false); |
|---|
| [5939] | 191 | tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); |
|---|
| [5928] | 192 | |
|---|
| 193 | tscx->retessellatePolygons(*gtess); |
|---|
| 194 | |
|---|
| 195 | return gtess; |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | osg::Geometry *makeFrontWall (const float zpos) { |
|---|
| [5939] | 199 | |
|---|
| [5928] | 200 | |
|---|
| [5939] | 201 | |
|---|
| [5928] | 202 | int nstart=0; |
|---|
| 203 | |
|---|
| 204 | osg::Geometry *gtess= new osg::Geometry; |
|---|
| 205 | int i; |
|---|
| 206 | osg::Vec3Array *coords = new osg::Vec3Array; |
|---|
| 207 | osg::Vec3Array *nrms = new osg::Vec3Array; |
|---|
| 208 | osg::Vec2Array *tcs = new osg::Vec2Array; |
|---|
| 209 | osg::Vec3 nrm(0,-1,0); |
|---|
| 210 | |
|---|
| 211 | static GLdouble wall[5][2] = |
|---|
| 212 | { { 2200.0, 1130.0 }, |
|---|
| 213 | { 2600.0, 1130.0 }, |
|---|
| 214 | { 2600.0, 1340.0 }, |
|---|
| 215 | { 2400.0, 1440.0 }, |
|---|
| 216 | { 2200.0, 1340.0 } }; |
|---|
| 217 | |
|---|
| 218 | static GLdouble door[4][2] = |
|---|
| 219 | { { 2360.0, 1130.0 }, |
|---|
| 220 | { 2440.0, 1130.0 }, |
|---|
| 221 | { 2440.0, 1230.0 }, |
|---|
| 222 | { 2360.0, 1230.0 } }; |
|---|
| 223 | |
|---|
| 224 | static GLdouble windows[16][2] = |
|---|
| 225 | { { 2240.0, 1180.0 }, |
|---|
| 226 | { 2330.0, 1180.0 }, |
|---|
| 227 | { 2330.0, 1220.0 }, |
|---|
| 228 | { 2240.0, 1220.0 }, |
|---|
| 229 | { 2460.0, 1180.0 }, |
|---|
| 230 | { 2560.0, 1180.0 }, |
|---|
| 231 | { 2560.0, 1220.0 }, |
|---|
| 232 | { 2460.0, 1220.0 }, |
|---|
| 233 | { 2240.0, 1280.0 }, |
|---|
| 234 | { 2330.0, 1280.0 }, |
|---|
| 235 | { 2330.0, 1320.0 }, |
|---|
| 236 | { 2240.0, 1320.0 }, |
|---|
| 237 | { 2460.0, 1280.0 }, |
|---|
| 238 | { 2560.0, 1280.0 }, |
|---|
| 239 | { 2560.0, 1320.0 }, |
|---|
| 240 | { 2460.0, 1320.0 } }; |
|---|
| 241 | |
|---|
| 242 | gtess->setVertexArray(coords); |
|---|
| 243 | gtess->setNormalArray(nrms); |
|---|
| 244 | gtess->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); |
|---|
| 245 | gtess->setTexCoordArray(0,tcs); |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | for (i = 0; i < 5; i++) { |
|---|
| 249 | coords->push_back(osg::Vec3(wall[i][0],zpos,wall[i][1])); |
|---|
| 250 | tcs->push_back(osg::Vec2(wall[i][0],wall[i][1])/100.0); |
|---|
| 251 | nrms->push_back(nrm); |
|---|
| 252 | } |
|---|
| 253 | gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,nstart,5));nstart+=5; |
|---|
| 254 | |
|---|
| 255 | for (i = 0; i < 4; i++) { |
|---|
| 256 | coords->push_back(osg::Vec3(door[i][0],zpos,door[i][1])); |
|---|
| 257 | tcs->push_back(osg::Vec2(door[i][0],door[i][1])/100.0); |
|---|
| 258 | nrms->push_back(nrm); |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | for (i = 0; i < 16; i++) { |
|---|
| 262 | coords->push_back(osg::Vec3(windows[i][0],zpos,windows[i][1])); |
|---|
| 263 | tcs->push_back(osg::Vec2(windows[i][0],windows[i][1])/100.0); |
|---|
| 264 | nrms->push_back(nrm); |
|---|
| 265 | } |
|---|
| 266 | gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,nstart,20));nstart+=20; |
|---|
| 267 | |
|---|
| [5939] | 268 | |
|---|
| [5928] | 269 | osg::StateSet* stateset = new osg::StateSet(); |
|---|
| 270 | |
|---|
| 271 | osg::Image* image = osgDB::readImageFile("Cubemap_snow/posy.jpg"); |
|---|
| 272 | if (image) |
|---|
| 273 | { |
|---|
| 274 | osg::Texture2D* texture = new osg::Texture2D; |
|---|
| 275 | texture->setImage(image); |
|---|
| 276 | texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT); |
|---|
| 277 | texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT); |
|---|
| 278 | stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); |
|---|
| 279 | } |
|---|
| 280 | gtess->setStateSet( stateset ); |
|---|
| 281 | |
|---|
| [5939] | 282 | |
|---|
| [5928] | 283 | |
|---|
| 284 | osg::ref_ptr<osgUtil::Tessellator> tscx=new osgUtil::Tessellator; |
|---|
| 285 | tscx->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); |
|---|
| 286 | tscx->setBoundaryOnly(false); |
|---|
| [5939] | 287 | tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); |
|---|
| [5928] | 288 | |
|---|
| 289 | tscx->retessellatePolygons(*gtess); |
|---|
| 290 | |
|---|
| 291 | return gtess; |
|---|
| 292 | } |
|---|
| 293 | osg::Geode *makeHouse (void) { |
|---|
| 294 | osg::Geode *gd = new osg::Geode; |
|---|
| 295 | gd->addDrawable(makeFrontWall(0.0)); |
|---|
| 296 | gd->addDrawable(makeFrontWall(300.0)); |
|---|
| 297 | gd->addDrawable(makeSideWall(2200.0)); |
|---|
| 298 | gd->addDrawable(makeSideWall(2600.0)); |
|---|
| 299 | return gd; |
|---|
| 300 | } |
|---|
| 301 | osg::Geometry *makePols (void) { |
|---|
| [5939] | 302 | tessellateDemoGeometry *gtess= new tessellateDemoGeometry; |
|---|
| [5928] | 303 | int i; |
|---|
| 304 | osg::Vec3Array *coords = new osg::Vec3Array; |
|---|
| 305 | osg::Vec3Array *nrms = new osg::Vec3Array; |
|---|
| 306 | osg::Vec2Array *tcs = new osg::Vec2Array; |
|---|
| 307 | osg::Vec3 nrm(0,-1,0); |
|---|
| 308 | |
|---|
| 309 | static GLdouble rects[12][3] = |
|---|
| 310 | { { 50.0, 50.0, 0.0 }, |
|---|
| 311 | { 300.0, 50.0, 0.0 }, |
|---|
| 312 | { 300.0, 300.0, 0.0 }, |
|---|
| 313 | { 50.0, 300.0, 0.0 }, |
|---|
| 314 | { 100.0, 100.0, 0.0 }, |
|---|
| 315 | { 250.0, 100.0, 0.0 }, |
|---|
| 316 | { 250.0, 250.0, 0.0 }, |
|---|
| 317 | { 100.0, 250.0, 0.0 }, |
|---|
| 318 | { 150.0, 150.0, 0.0 }, |
|---|
| 319 | { 200.0, 150.0, 0.0 }, |
|---|
| 320 | { 200.0, 200.0, 0.0 }, |
|---|
| 321 | { 150.0, 200.0, 0.0 } }; |
|---|
| 322 | |
|---|
| 323 | static GLdouble rectsMidanti[12][3] = |
|---|
| 324 | { { 1050.0, 50.0, 0.0 }, |
|---|
| 325 | { 1300.0, 50.0, 0.0 }, |
|---|
| 326 | { 1300.0, 300.0, 0.0 }, |
|---|
| 327 | { 1050.0, 300.0, 0.0 }, |
|---|
| 328 | { 1250.0, 100.0, 0.0 }, |
|---|
| 329 | { 1100.0, 100.0, 0.0 }, |
|---|
| 330 | { 1100.0, 250.0, 0.0 }, |
|---|
| 331 | { 1250.0, 250.0, 0.0 }, |
|---|
| 332 | { 1200.0, 150.0, 0.0 }, |
|---|
| 333 | { 1150.0, 150.0, 0.0 }, |
|---|
| 334 | { 1150.0, 200.0, 0.0 }, |
|---|
| 335 | { 1200.0, 200.0, 0.0 } }; |
|---|
| 336 | static GLdouble spiral[16][3] = |
|---|
| 337 | { { 3400.0, 250.0, 0.0 }, |
|---|
| 338 | { 3400.0, 50.0, 0.0 }, |
|---|
| 339 | { 3050.0, 50.0, 0.0 }, |
|---|
| 340 | { 3050.0, 400.0, 0.0 }, |
|---|
| 341 | { 3350.0, 400.0, 0.0 }, |
|---|
| 342 | { 3350.0, 100.0, 0.0 }, |
|---|
| 343 | { 3100.0, 100.0, 0.0 }, |
|---|
| 344 | { 3100.0, 350.0, 0.0 }, |
|---|
| 345 | { 3300.0, 350.0, 0.0 }, |
|---|
| 346 | { 3300.0, 150.0, 0.0 }, |
|---|
| 347 | { 3150.0, 150.0, 0.0 }, |
|---|
| 348 | { 3150.0, 300.0, 0.0 }, |
|---|
| 349 | { 3250.0, 300.0, 0.0 }, |
|---|
| 350 | { 3250.0, 200.0, 0.0 }, |
|---|
| 351 | { 3200.0, 200.0, 0.0 }, |
|---|
| 352 | { 3200.0, 250.0, 0.0 } |
|---|
| 353 | }; |
|---|
| 354 | static GLdouble quad1[4][3] = |
|---|
| 355 | { { 2050.0, 150.0, 0.0 }, |
|---|
| 356 | { 2350.0, 150.0, 0.0 }, |
|---|
| 357 | { 2350.0, 200.0, 0.0 }, |
|---|
| 358 | { 2050.0, 200.0, 0.0 } |
|---|
| 359 | }; |
|---|
| 360 | static GLdouble quad2[4][3] = |
|---|
| 361 | { { 2100.0, 100.0, 0.0 }, |
|---|
| 362 | { 2300.0, 100.0, 0.0 }, |
|---|
| 363 | { 2300.0, 350.0, 0.0 }, |
|---|
| 364 | { 2100.0, 350.0, 0.0 } |
|---|
| 365 | }; |
|---|
| 366 | static GLdouble tri[3][3] = |
|---|
| 367 | { { 2200.0, 50.0, 0.0 }, |
|---|
| 368 | { 2250.0, 300.0, 0.0 }, |
|---|
| 369 | { 2150.0, 300.0, 0.0 } |
|---|
| 370 | }; |
|---|
| 371 | static GLdouble quad3[4][3] = |
|---|
| 372 | { { 100.0, 1100.0, 0.0 }, |
|---|
| 373 | { 1300.0, 1100.0, 0.0 }, |
|---|
| 374 | { 1300.0, 2350.0, 0.0 }, |
|---|
| 375 | { 100.0, 2350.0, 0.0} |
|---|
| 376 | }; |
|---|
| 377 | static GLdouble quadstrip[8][3] = |
|---|
| 378 | { { 900.0, 1130.0, 0.0 }, |
|---|
| 379 | { 1100.0, 1130.0, 0.0 }, |
|---|
| 380 | { 900.0, 1350.0, 0.0 }, |
|---|
| 381 | { 950.0, 1350.0, 0.0 }, |
|---|
| 382 | { 900.0, 1550.0, 0.0 }, |
|---|
| 383 | { 1000.0, 1550.0, 0.0 }, |
|---|
| 384 | { 900.0, 1750.0, 0.0 }, |
|---|
| 385 | { 1400.0, 1750.0, 0.0 } |
|---|
| 386 | }; |
|---|
| 387 | |
|---|
| 388 | for (i = 0; i < 12; i++) { |
|---|
| 389 | coords->push_back(osg::Vec3(rects[i][0],rects[i][2],rects[i][1])); |
|---|
| 390 | tcs->push_back(osg::Vec2(rects[i][0],rects[i][1])/200.0); |
|---|
| 391 | nrms->push_back(nrm); |
|---|
| 392 | } |
|---|
| 393 | for (i = 0; i < 12; i++) { |
|---|
| 394 | coords->push_back(osg::Vec3(rectsMidanti[i][0],rectsMidanti[i][2],rectsMidanti[i][1])); |
|---|
| 395 | tcs->push_back(osg::Vec2(rectsMidanti[i][0],rectsMidanti[i][1])/200.0); |
|---|
| 396 | nrms->push_back(nrm); |
|---|
| 397 | } |
|---|
| 398 | for (i = 0; i < 16; i++) { |
|---|
| 399 | coords->push_back(osg::Vec3(spiral[15-i][0],spiral[15-i][2],spiral[15-i][1])); |
|---|
| 400 | tcs->push_back(osg::Vec2(spiral[15-i][0],spiral[15-i][1])/200.0); |
|---|
| 401 | nrms->push_back(nrm); |
|---|
| 402 | } |
|---|
| 403 | for (i = 0; i < 4; i++) { |
|---|
| 404 | coords->push_back(osg::Vec3(quad1[i][0],quad1[i][2],quad1[i][1])); |
|---|
| 405 | tcs->push_back(osg::Vec2(quad1[i][0],quad1[i][1])/200.0); |
|---|
| 406 | nrms->push_back(nrm); |
|---|
| 407 | } |
|---|
| 408 | for (i = 0; i < 4; i++) { |
|---|
| 409 | coords->push_back(osg::Vec3(quad2[i][0],quad2[i][2],quad2[i][1])); |
|---|
| 410 | tcs->push_back(osg::Vec2(quad2[i][0],quad2[i][1])/200.0); |
|---|
| 411 | nrms->push_back(nrm); |
|---|
| 412 | } |
|---|
| 413 | for (i = 0; i < 3; i++) { |
|---|
| 414 | coords->push_back(osg::Vec3(tri[i][0],tri[i][2],tri[i][1])); |
|---|
| 415 | tcs->push_back(osg::Vec2(tri[i][0],tri[i][1])/200.0); |
|---|
| 416 | nrms->push_back(nrm); |
|---|
| 417 | } |
|---|
| 418 | |
|---|
| 419 | for (i = 0; i < 4; i++) { |
|---|
| 420 | coords->push_back(osg::Vec3(quad3[i][0],quad3[i][2],quad3[i][1])); |
|---|
| 421 | tcs->push_back(osg::Vec2(quad3[i][0],quad3[i][1])/200.0); |
|---|
| 422 | nrms->push_back(nrm); |
|---|
| 423 | } |
|---|
| 424 | { |
|---|
| 425 | osg::Vec3 centre(300,0,1500); |
|---|
| 426 | for (i = 0; i < 18; i++) { |
|---|
| 427 | osg::Vec3 rim=centre+osg::Vec3(-cos(osg::DegreesToRadians((float)i*20.0)),0.0,sin(osg::DegreesToRadians((float)i*20.0)))*150.0; |
|---|
| 428 | coords->push_back(rim); |
|---|
| 429 | tcs->push_back(osg::Vec2(rim.x(),rim.z())/200.0); |
|---|
| 430 | nrms->push_back(nrm); |
|---|
| 431 | } |
|---|
| 432 | } |
|---|
| 433 | { |
|---|
| 434 | osg::Vec3 centre(400,0,1800); |
|---|
| 435 | for (i = 0; i < 18; i++) { |
|---|
| 436 | osg::Vec3 rim=centre+osg::Vec3(-cos(osg::DegreesToRadians((float)i*15.0)),0.0,sin(osg::DegreesToRadians((float)i*15.0)))*250.0; |
|---|
| 437 | coords->push_back(rim); |
|---|
| 438 | tcs->push_back(osg::Vec2(rim.x(),rim.z())/200.0); |
|---|
| 439 | nrms->push_back(nrm); |
|---|
| 440 | } |
|---|
| 441 | } |
|---|
| 442 | { |
|---|
| 443 | osg::Vec3 centre(600,0,1400); |
|---|
| 444 | for (i = 0; i < 18; i++) { |
|---|
| 445 | osg::Vec3 rim=centre+osg::Vec3(-cos(osg::DegreesToRadians((float)i*12.0)),0.0,sin(osg::DegreesToRadians((float)i*12.0)))*250.0; |
|---|
| 446 | coords->push_back(rim); |
|---|
| 447 | tcs->push_back(osg::Vec2(rim.x(),rim.z())/200.0); |
|---|
| 448 | nrms->push_back(nrm); |
|---|
| 449 | } |
|---|
| 450 | } |
|---|
| 451 | |
|---|
| 452 | for (i = 0; i < 8; i++) { |
|---|
| 453 | coords->push_back(osg::Vec3(quadstrip[i][0],quadstrip[i][2],quadstrip[i][1])); |
|---|
| 454 | tcs->push_back(osg::Vec2(quadstrip[i][0],quadstrip[i][1])/200.0); |
|---|
| 455 | nrms->push_back(nrm); |
|---|
| 456 | } |
|---|
| 457 | gtess->setVertexArray(coords); |
|---|
| 458 | gtess->setNormalArray(nrms); |
|---|
| 459 | gtess->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); |
|---|
| 460 | gtess->setTexCoordArray(0,tcs); |
|---|
| 461 | |
|---|
| [5939] | 462 | |
|---|
| [5928] | 463 | osg::StateSet* stateset = new osg::StateSet(); |
|---|
| 464 | |
|---|
| 465 | osg::Image* image = osgDB::readImageFile("Cubemap_snow/posz.jpg"); |
|---|
| 466 | if (image) |
|---|
| 467 | { |
|---|
| 468 | osg::Texture2D* texture = new osg::Texture2D; |
|---|
| 469 | texture->setImage(image); |
|---|
| 470 | texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT); |
|---|
| 471 | texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT); |
|---|
| 472 | stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); |
|---|
| 473 | } |
|---|
| 474 | gtess->setStateSet( stateset ); |
|---|
| 475 | |
|---|
| 476 | int nstart=0; |
|---|
| 477 | |
|---|
| 478 | gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,nstart,12));nstart+=12; |
|---|
| 479 | gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,nstart,12));nstart+=12; |
|---|
| 480 | gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,nstart,16));nstart+=16; |
|---|
| 481 | gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,nstart,4));nstart+=4; |
|---|
| 482 | gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,nstart,4));nstart+=4; |
|---|
| 483 | gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,nstart,3));nstart+=3; |
|---|
| 484 | |
|---|
| 485 | gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP,nstart,4));nstart+=4; |
|---|
| 486 | gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_FAN,nstart,18));nstart+=18; |
|---|
| 487 | gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,nstart,18));nstart+=18; |
|---|
| 488 | gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,nstart,18));nstart+=18; |
|---|
| 489 | |
|---|
| 490 | gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP,nstart,8));nstart+=8; |
|---|
| 491 | |
|---|
| [5939] | 492 | |
|---|
| [5928] | 493 | |
|---|
| [5939] | 494 | |
|---|
| [5928] | 495 | |
|---|
| 496 | gtess->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); |
|---|
| 497 | gtess->setBoundaryOnly(true); |
|---|
| [5939] | 498 | gtess->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); |
|---|
| [5928] | 499 | |
|---|
| 500 | return gtess; |
|---|
| 501 | } |
|---|
| 502 | osg::Node* createHUD() |
|---|
| [5939] | 503 | { |
|---|
| [5928] | 504 | osg::Geode* geode = new osg::Geode(); |
|---|
| 505 | |
|---|
| 506 | std::string timesFont("fonts/arial.ttf"); |
|---|
| 507 | |
|---|
| 508 | |
|---|
| 509 | osg::StateSet* stateset = geode->getOrCreateStateSet(); |
|---|
| 510 | stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); |
|---|
| 511 | |
|---|
| 512 | |
|---|
| 513 | |
|---|
| 514 | stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); |
|---|
| 515 | stateset->setRenderBinDetails(11,"RenderBin"); |
|---|
| 516 | |
|---|
| 517 | osg::Vec3 position(150.0f,900.0f,0.0f); |
|---|
| 518 | osg::Vec3 delta(0.0f,-30.0f,0.0f); |
|---|
| 519 | |
|---|
| 520 | { |
|---|
| 521 | osgText::Text* text = new osgText::Text; |
|---|
| 522 | geode->addDrawable( text ); |
|---|
| 523 | |
|---|
| 524 | text->setFont(timesFont); |
|---|
| 525 | text->setPosition(position); |
|---|
| [5939] | 526 | text->setText("Tessellation example - no tessellation (use 'W' wireframe to visualise)"); |
|---|
| [5928] | 527 | text->setColor(osg::Vec4(1.0,1.0,0.8,1.0)); |
|---|
| 528 | position += delta; |
|---|
| 529 | |
|---|
| 530 | } |
|---|
| 531 | { |
|---|
| 532 | osgText::Text* text = new osgText::Text; |
|---|
| 533 | geode->addDrawable( text ); |
|---|
| 534 | |
|---|
| 535 | text->setFont(timesFont); |
|---|
| 536 | text->setPosition(position); |
|---|
| [5939] | 537 | text->setText("Press 'n' to use an alternative tessellation."); |
|---|
| [5928] | 538 | |
|---|
| 539 | } |
|---|
| 540 | |
|---|
| 541 | |
|---|
| 542 | osg::MatrixTransform* modelview_abs = new osg::MatrixTransform; |
|---|
| 543 | modelview_abs->setReferenceFrame(osg::Transform::ABSOLUTE_RF); |
|---|
| 544 | modelview_abs->setMatrix(osg::Matrix::identity()); |
|---|
| 545 | modelview_abs->addChild(geode); |
|---|
| 546 | |
|---|
| 547 | osg::Projection* projection = new osg::Projection; |
|---|
| 548 | projection->setMatrix(osg::Matrix::ortho2D(0,1280,0,1024)); |
|---|
| 549 | projection->addChild(modelview_abs); |
|---|
| 550 | |
|---|
| 551 | return projection; |
|---|
| 552 | |
|---|
| 553 | } |
|---|
| 554 | |
|---|
| 555 | |
|---|
| [5939] | 556 | osg::Group *makeTessellateExample (void) { |
|---|
| [5928] | 557 | osg::Group *grp=new osg::Group; |
|---|
| 558 | osg::Geode *gd=new osg::Geode; |
|---|
| 559 | gd->addDrawable(makePols()); |
|---|
| 560 | gd->addDrawable(makePolsTwo()); |
|---|
| 561 | grp->addChild(gd); |
|---|
| 562 | |
|---|
| 563 | grp->addChild(makeHouse()); |
|---|
| 564 | |
|---|
| 565 | return grp; |
|---|
| 566 | } |
|---|
| 567 | |
|---|
| [5939] | 568 | class setTessellateVisitor : public osg::NodeVisitor |
|---|
| 569 | { |
|---|
| 570 | |
|---|
| [5928] | 571 | |
|---|
| [5939] | 572 | |
|---|
| [5928] | 573 | |
|---|
| [5939] | 574 | |
|---|
| [5928] | 575 | public: |
|---|
| 576 | |
|---|
| [5939] | 577 | setTessellateVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { |
|---|
| [5928] | 578 | } |
|---|
| 579 | virtual void apply(osg::Geode& geode) { |
|---|
| [5939] | 580 | if (geode.getName().compare(0,9,"tessellate")==0) { |
|---|
| [5928] | 581 | for(unsigned int i=0;i<geode.getNumDrawables();++i) |
|---|
| 582 | { |
|---|
| 583 | osg::Geometry* geom = dynamic_cast<osg::Geometry*>(geode.getDrawable(i)); |
|---|
| 584 | if (geom) { |
|---|
| 585 | osg::ref_ptr<osgUtil::Tessellator> tscx=new osgUtil::Tessellator(); |
|---|
| 586 | if (tscx.valid()) { |
|---|
| 587 | tscx->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); |
|---|
| [5939] | 588 | if (geode.getName()== "tessellate") { |
|---|
| 589 | |
|---|
| [5928] | 590 | tscx->setBoundaryOnly(true); |
|---|
| [5939] | 591 | tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); |
|---|
| [5928] | 592 | geom->setUserData(tscx.get()); |
|---|
| [5939] | 593 | } else if (geode.getName()== "tessellate odd") { |
|---|
| [5928] | 594 | |
|---|
| [5939] | 595 | tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); |
|---|
| [5928] | 596 | tscx->retessellatePolygons(*geom); |
|---|
| [5939] | 597 | } else if (geode.getName()== "tessellate odd bound") { |
|---|
| [5928] | 598 | tscx->setBoundaryOnly(true); |
|---|
| [5939] | 599 | tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); |
|---|
| [5928] | 600 | tscx->retessellatePolygons(*geom); |
|---|
| [5939] | 601 | } else if (geode.getName()== "tessellate positive") { |
|---|
| 602 | tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_POSITIVE); |
|---|
| [5928] | 603 | tscx->retessellatePolygons(*geom); |
|---|
| [5939] | 604 | } else if (geode.getName()== "tessellate positive bound") { |
|---|
| [5928] | 605 | tscx->setBoundaryOnly(true); |
|---|
| 606 | tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_POSITIVE); |
|---|
| 607 | tscx->retessellatePolygons(*geom); |
|---|
| [5939] | 608 | } else if (geode.getName()== "tessellate negative") { |
|---|
| [5928] | 609 | tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_NEGATIVE); |
|---|
| 610 | tscx->retessellatePolygons(*geom); |
|---|
| [5939] | 611 | } else if (geode.getName()== "tessellate negative bound") { |
|---|
| [5928] | 612 | tscx->setBoundaryOnly(true); |
|---|
| 613 | tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_NEGATIVE); |
|---|
| 614 | tscx->retessellatePolygons(*geom); |
|---|
| [5939] | 615 | } else if (geode.getName()== "tessellate nonzero") { |
|---|
| [5928] | 616 | tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_NONZERO); |
|---|
| 617 | tscx->retessellatePolygons(*geom); |
|---|
| [5939] | 618 | } else if (geode.getName()== "tessellate nonzero bound") { |
|---|
| [5928] | 619 | tscx->setBoundaryOnly(true); |
|---|
| 620 | tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_NONZERO); |
|---|
| 621 | tscx->retessellatePolygons(*geom); |
|---|
| [5939] | 622 | } else if (geode.getName()== "tessellate geq2") { |
|---|
| [5928] | 623 | tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); |
|---|
| 624 | tscx->retessellatePolygons(*geom); |
|---|
| [5939] | 625 | } else if (geode.getName()== "tessellate geq2 bound") { |
|---|
| [5928] | 626 | tscx->setBoundaryOnly(true); |
|---|
| 627 | tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); |
|---|
| 628 | tscx->retessellatePolygons(*geom); |
|---|
| 629 | } |
|---|
| 630 | } |
|---|
| 631 | } |
|---|
| 632 | } |
|---|
| 633 | } |
|---|
| 634 | } |
|---|
| 635 | }; |
|---|
| 636 | |
|---|
| [5939] | 637 | class cxTessellateVisitor : public osg::NodeVisitor |
|---|
| 638 | { |
|---|
| 639 | |
|---|
| [5928] | 640 | |
|---|
| [5939] | 641 | |
|---|
| 642 | |
|---|
| [5928] | 643 | public: |
|---|
| 644 | |
|---|
| [5939] | 645 | cxTessellateVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { |
|---|
| [5928] | 646 | } |
|---|
| 647 | virtual void apply(osg::Geode& geode) { |
|---|
| 648 | |
|---|
| 649 | for(unsigned int i=0;i<geode.getNumDrawables();++i) |
|---|
| 650 | { |
|---|
| [5939] | 651 | tessellateDemoGeometry *geom=dynamic_cast<tessellateDemoGeometry*>(geode.getDrawable(i)); |
|---|
| [5928] | 652 | if (geom) { |
|---|
| 653 | if (!geom->getBoundaryOnly()) { |
|---|
| 654 | |
|---|
| 655 | geom->setBoundaryOnly(true); |
|---|
| 656 | |
|---|
| [5939] | 657 | } else { |
|---|
| [5928] | 658 | geom->setBoundaryOnly(false); |
|---|
| 659 | switch (geom->getWindingType()) { |
|---|
| 660 | case osgUtil::Tessellator::TESS_WINDING_ODD: |
|---|
| 661 | geom->setWindingType(osgUtil::Tessellator::TESS_WINDING_NONZERO); |
|---|
| 662 | break; |
|---|
| 663 | case osgUtil::Tessellator::TESS_WINDING_NONZERO: |
|---|
| 664 | geom->setWindingType( osgUtil::Tessellator::TESS_WINDING_POSITIVE); |
|---|
| 665 | break; |
|---|
| 666 | case osgUtil::Tessellator::TESS_WINDING_POSITIVE: |
|---|
| 667 | geom->setWindingType( osgUtil::Tessellator::TESS_WINDING_NEGATIVE); |
|---|
| 668 | break; |
|---|
| 669 | case osgUtil::Tessellator::TESS_WINDING_NEGATIVE: |
|---|
| 670 | geom->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); |
|---|
| 671 | break; |
|---|
| 672 | case osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO: |
|---|
| 673 | geom->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); |
|---|
| 674 | break; |
|---|
| 675 | } |
|---|
| 676 | } |
|---|
| 677 | |
|---|
| 678 | switch (geom->getWindingType()) { |
|---|
| 679 | case osgUtil::Tessellator::TESS_WINDING_ODD: |
|---|
| 680 | str="TESS_WINDING_ODD"; |
|---|
| 681 | break; |
|---|
| 682 | case osgUtil::Tessellator::TESS_WINDING_NONZERO: |
|---|
| 683 | str="TESS_WINDING_NONZERO"; |
|---|
| 684 | break; |
|---|
| 685 | case osgUtil::Tessellator::TESS_WINDING_POSITIVE: |
|---|
| 686 | str="TESS_WINDING_POSITIVE"; |
|---|
| 687 | break; |
|---|
| 688 | case osgUtil::Tessellator::TESS_WINDING_NEGATIVE: |
|---|
| 689 | str="TESS_WINDING_NEGATIVE"; |
|---|
| 690 | break; |
|---|
| 691 | case osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO: |
|---|
| 692 | str="TESS_WINDING_ABS_GEQ_TWO"; |
|---|
| 693 | break; |
|---|
| 694 | } |
|---|
| 695 | if (geom->getBoundaryOnly()) str += " Boundary"; |
|---|
| 696 | |
|---|
| 697 | geom->retessellatePolygons(*geom); |
|---|
| 698 | } |
|---|
| 699 | osgText::Text* txt = dynamic_cast<osgText::Text*>(geode.getDrawable(i)); |
|---|
| 700 | if (txt) { |
|---|
| 701 | const osg::Vec4& ct=txt->getColor(); |
|---|
| 702 | if (ct.z()<0.9) { |
|---|
| 703 | txt->setText(str.c_str()); |
|---|
| 704 | } |
|---|
| 705 | } |
|---|
| 706 | } |
|---|
| 707 | traverse(geode); |
|---|
| 708 | } |
|---|
| 709 | |
|---|
| 710 | std::string str; |
|---|
| 711 | }; |
|---|
| 712 | |
|---|
| 713 | class KeyboardEventHandler : public osgGA::GUIEventHandler |
|---|
| [5939] | 714 | { |
|---|
| [5928] | 715 | public: |
|---|
| 716 | |
|---|
| 717 | KeyboardEventHandler(osg::Node *nd): |
|---|
| 718 | _scene(nd) {} |
|---|
| 719 | |
|---|
| 720 | virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) |
|---|
| 721 | { |
|---|
| 722 | switch(ea.getEventType()) |
|---|
| 723 | { |
|---|
| 724 | case(osgGA::GUIEventAdapter::KEYDOWN): |
|---|
| 725 | { |
|---|
| 726 | if (_scene && ea.getKey()=='n') |
|---|
| 727 | { |
|---|
| [5939] | 728 | |
|---|
| 729 | |
|---|
| 730 | |
|---|
| 731 | cxTessellateVisitor tsv; |
|---|
| [5928] | 732 | _scene->accept(tsv); |
|---|
| 733 | return true; |
|---|
| 734 | } |
|---|
| 735 | break; |
|---|
| 736 | } |
|---|
| 737 | default: |
|---|
| 738 | break; |
|---|
| 739 | } |
|---|
| 740 | return false; |
|---|
| 741 | } |
|---|
| 742 | |
|---|
| 743 | osg::Node *_scene; |
|---|
| 744 | |
|---|
| 745 | }; |
|---|
| 746 | |
|---|
| 747 | |
|---|
| 748 | int main( int argc, char **argv ) |
|---|
| 749 | { |
|---|
| 750 | |
|---|
| 751 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 752 | |
|---|
| 753 | |
|---|
| [5962] | 754 | osgViewer::Viewer viewer; |
|---|
| [5928] | 755 | |
|---|
| 756 | |
|---|
| 757 | osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); |
|---|
| 758 | |
|---|
| 759 | |
|---|
| 760 | if (!loadedModel) |
|---|
| 761 | { |
|---|
| [5939] | 762 | loadedModel=makeTessellateExample(); |
|---|
| [5962] | 763 | |
|---|
| [5928] | 764 | } else { |
|---|
| [5962] | 765 | |
|---|
| [5939] | 766 | |
|---|
| 767 | setTessellateVisitor tsv; |
|---|
| [5928] | 768 | loadedModel->accept(tsv); |
|---|
| [5962] | 769 | |
|---|
| [5928] | 770 | } |
|---|
| 771 | |
|---|
| 772 | |
|---|
| 773 | osg::Group *gload= dynamic_cast<osg::Group *> (loadedModel.get()); |
|---|
| 774 | gload->addChild(createHUD()); |
|---|
| 775 | |
|---|
| 776 | |
|---|
| 777 | osgUtil::Optimizer optimizer; |
|---|
| 778 | optimizer.optimize(loadedModel.get() ); |
|---|
| 779 | |
|---|
| 780 | |
|---|
| 781 | viewer.setSceneData(loadedModel.get()); |
|---|
| 782 | |
|---|
| [5939] | 783 | |
|---|
| [5962] | 784 | viewer.addEventHandler(new KeyboardEventHandler(loadedModel.get())); |
|---|
| [5928] | 785 | |
|---|
| [5962] | 786 | return viewer.run(); |
|---|
| [5928] | 787 | } |
|---|