- Timestamp:
- 04/08/05 11:45:06 (8 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgsimulation/osgsimulation.cpp
r3977 r3994 25 25 #include <osg/PositionAttitudeTransform> 26 26 #include <osg/MatrixTransform> 27 #include <osg/AutoTransform> 27 28 #include <osg/CoordinateSystemNode> 28 29 … … 137 138 osg::NodePath nodePath = nv->getNodePath(); 138 139 139 osg::MatrixTransform* mt = nodePath.empty() ? 0 : dynamic_cast<osg::MatrixTransform*>(nodePath.back());140 osg::AutoTransform * mt = nodePath.empty() ? 0 : dynamic_cast<osg::AutoTransform*>(nodePath.back()); 140 141 if (mt) 141 142 { … … 163 164 } 164 165 165 //osg::Matrixd matrix;166 166 ellipsoid->computeLocalToWorldTransformFromLatLongHeight(_latitude,_longitude,_height,matrix); 167 167 matrix.preMult(osg::Matrixd::rotate(_rotation)); 168 168 169 mt->setMatrix(matrix); 169 mt->setPosition(osg::Vec3d(matrix(3,0),matrix(3,1),matrix(3,2))); 170 osg::Quat quat; 171 quat.set(matrix); 172 mt->setRotation(quat); 170 173 } 171 174 … … 180 183 double _height; 181 184 osg::Quat _rotation; 185 bool _useAutoTrans; 182 186 }; 183 187 … … 228 232 229 233 viewer.getCullSettings().setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES); 230 viewer.getCullSettings().setNearFarRatio(0.0000 1f);234 viewer.getCullSettings().setNearFarRatio(0.0000000001f); 231 235 232 236 // get details on keyboard and mouse bindings used by the viewer. … … 305 309 } 306 310 307 osg::ref_ptr<osg::Node> root = createEarth(); 311 osg::ref_ptr<osg::MatrixTransform> parent; 312 osg::ref_ptr<osg::Node> root; 313 314 osg::Matrix mat; 315 mat.makeScale(osg::Vec3(000000.1, 000000.1, 000000.1)); 316 parent = new osg::MatrixTransform(mat); 317 318 root = createEarth(); 308 319 309 320 if (!root) return 0; 310 321 322 parent->addChild(root.get()); 323 311 324 // add a viewport to the viewer and attach the scene graph. 312 viewer.setSceneData( root.get());325 viewer.setSceneData(parent.get()); 313 326 314 327 osg::CoordinateSystemNode* csn = dynamic_cast<osg::CoordinateSystemNode*>(root.get()); 315 if (csn) 316 { 317 osg::Node* cessna = osgDB::readNodeFile("cessna.osg"); 318 if (cessna) 319 { 320 double s = 30000.0 / cessna->getBound().radius(); 321 322 osg::MatrixTransform* scaler = new osg::MatrixTransform; 323 scaler->addChild(cessna); 324 scaler->setMatrix(osg::Matrixd::scale(s,s,s)*osg::Matrixd::rotate(rotation)); 325 scaler->getOrCreateStateSet()->setMode(GL_RESCALE_NORMAL,osg::StateAttribute::ON); 326 327 osg::MatrixTransform* mt = new osg::MatrixTransform; 328 mt->addChild(scaler); 329 330 331 if (!nc) nc = new ModelPositionCallback; 332 333 mt->setUpdateCallback(nc); 334 335 csn->addChild(mt); 336 337 osgGA::NodeTrackerManipulator* tm = new osgGA::NodeTrackerManipulator; 338 tm->setTrackerMode(trackerMode); 339 tm->setRotationMode(rotationMode); 340 tm->setTrackNode(scaler); 341 342 unsigned int num = viewer.addCameraManipulator(tm); 343 viewer.selectCameraManipulator(num); 344 } 345 else 346 { 347 std::cout<<"Failed to read cessna.osg"<<std::endl; 348 } 349 } 350 351 328 329 if (csn) 330 { 331 osg::Node* cessna = osgDB::readNodeFile("cessna.osg"); 332 if (cessna) 333 { 334 double s = 30000.0 / cessna->getBound().radius(); 335 336 osg::MatrixTransform* scaler = new osg::MatrixTransform; 337 scaler->addChild(cessna); 338 scaler->setMatrix(osg::Matrixd::scale(5,5,5)); 339 scaler->getOrCreateStateSet()->setMode(GL_RESCALE_NORMAL,osg::StateAttribute::ON); 340 341 osg::AutoTransform * mt; 342 343 mt = new osg::AutoTransform; 344 mt->setAutoScaleToScreen(true); 345 mt->addChild(scaler); 346 347 if (!nc) 348 nc = new ModelPositionCallback; 349 350 mt->setUpdateCallback(nc); 351 352 csn->addChild(mt); 353 354 osgGA::NodeTrackerManipulator* tm = new osgGA::NodeTrackerManipulator; 355 tm->setTrackerMode(trackerMode); 356 tm->setRotationMode(rotationMode); 357 tm->setTrackNode(scaler); 358 359 unsigned int num = viewer.addCameraManipulator(tm); 360 viewer.selectCameraManipulator(num); 361 } 362 else 363 { 364 std::cout<<"Failed to read cessna.osg"<<std::endl; 365 } 366 } 352 367 353 368 // create the windows and run the threads.
