- Timestamp:
- 04/08/05 11:55:52 (8 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgsimulation/osgsimulation.cpp
r3994 r3996 25 25 #include <osg/PositionAttitudeTransform> 26 26 #include <osg/MatrixTransform> 27 #include <osg/AutoTransform>28 27 #include <osg/CoordinateSystemNode> 29 28 … … 118 117 { 119 118 _longitude += ((2.0*osg::PI)/360.0)/20.0; 120 _latitude = sin(_longitude);121 122 // adjust the heading and roll to roughly look ok,123 // but bearing no reality to physics..124 osg::Quat heading;125 heading.makeRotate(osg::DegreesToRadians(90.0)+cos(_longitude),0.0,0.0,1.0);126 127 osg::Quat roll;128 roll.makeRotate(-_latitude*0.5f,0.0,1.0,0.0);129 130 _rotation = roll*heading;131 119 } 132 120 … … 138 126 osg::NodePath nodePath = nv->getNodePath(); 139 127 140 osg::AutoTransform * mt = nodePath.empty() ? 0 : dynamic_cast<osg::AutoTransform*>(nodePath.back());128 osg::MatrixTransform* mt = nodePath.empty() ? 0 : dynamic_cast<osg::MatrixTransform*>(nodePath.back()); 141 129 if (mt) 142 130 { … … 164 152 } 165 153 154 //osg::Matrixd matrix; 166 155 ellipsoid->computeLocalToWorldTransformFromLatLongHeight(_latitude,_longitude,_height,matrix); 167 156 matrix.preMult(osg::Matrixd::rotate(_rotation)); 168 157 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); 158 mt->setMatrix(matrix); 173 159 } 174 160 … … 183 169 double _height; 184 170 osg::Quat _rotation; 185 bool _useAutoTrans;186 171 }; 187 172 … … 219 204 arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] image_file_left_eye image_file_right_eye"); 220 205 arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 221 arguments.getApplicationUsage()->addCommandLineOption("--rotate-model angle x y z","Rotate model");222 arguments.getApplicationUsage()->addCommandLineOption("--flight-path","");223 arguments.getApplicationUsage()->addCommandLineOption("--tracker-mode","NODE_CENTER_AND_ROTATION | NODE_CENTER_AND_AZIM | NODE_CENTER");224 arguments.getApplicationUsage()->addCommandLineOption("--rotation-mode","TRACKBALL | ELEVATION_AZIM");225 206 226 207 … … 232 213 233 214 viewer.getCullSettings().setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES); 234 viewer.getCullSettings().setNearFarRatio(0.0000 000001f);215 viewer.getCullSettings().setNearFarRatio(0.00001f); 235 216 236 217 // get details on keyboard and mouse bindings used by the viewer. … … 309 290 } 310 291 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(); 292 osg::ref_ptr<osg::Node> root = createEarth(); 319 293 320 294 if (!root) return 0; 321 295 322 parent->addChild(root.get());323 324 296 // add a viewport to the viewer and attach the scene graph. 325 viewer.setSceneData( parent.get());297 viewer.setSceneData(root.get()); 326 298 327 299 osg::CoordinateSystemNode* csn = dynamic_cast<osg::CoordinateSystemNode*>(root.get()); 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 } 300 if (csn) 301 { 302 osg::Node* cessna = osgDB::readNodeFile("cessna.osg"); 303 if (cessna) 304 { 305 double s = 30000.0 / cessna->getBound().radius(); 306 307 osg::MatrixTransform* scaler = new osg::MatrixTransform; 308 scaler->addChild(cessna); 309 scaler->setMatrix(osg::Matrixd::scale(s,s,s)*osg::Matrixd::rotate(rotation)); 310 scaler->getOrCreateStateSet()->setMode(GL_RESCALE_NORMAL,osg::StateAttribute::ON); 311 312 osg::MatrixTransform* mt = new osg::MatrixTransform; 313 mt->addChild(scaler); 314 315 316 if (!nc) nc = new ModelPositionCallback; 317 318 mt->setUpdateCallback(nc); 319 320 csn->addChild(mt); 321 322 osgGA::NodeTrackerManipulator* tm = new osgGA::NodeTrackerManipulator; 323 tm->setTrackerMode(trackerMode); 324 tm->setRotationMode(rotationMode); 325 tm->setTrackNode(scaler); 326 327 unsigned int num = viewer.addCameraManipulator(tm); 328 viewer.selectCameraManipulator(num); 329 } 330 else 331 { 332 std::cout<<"Failed to read cessna.osg"<<std::endl; 333 } 334 } 335 336 367 337 368 338 // create the windows and run the threads.
