#include <OSGNavigator.h>
Definition at line 62 of file OSGNavigator.h.
|
|
The navigation mode, i.e. the actual active low-level navigator. The NONE case is also used for the purpose of matrix consistency. Definition at line 67 of file OSGNavigator.h.
|
|
|
The navigation state, mainly needed for correct interpretation of mouse motions, which have to be interpreted differently for different states. Interpretation also depends on the currently active Navigator::Mode.
Definition at line 75 of file OSGNavigator.h. 00076 { 00077 IDLE=0, 00078 ROTATING, 00079 TRANSLATING_XY, 00080 TRANSLATING_Z, 00081 00082 TRANSLATING_ZPLUS=10, 00083 TRANSLATING_ZMINUS 00084 };
|
|
|
Abstraction enumeration for mouse buttons, to keep the Navigator independent of the actual Window System.
Definition at line 86 of file OSGNavigator.h. 00087 { 00088 LEFT_MOUSE=0, 00089 MIDDLE_MOUSE, 00090 RIGHT_MOUSE, 00091 UP_MOUSE, 00092 DOWN_MOUSE 00093 };
|
|
|
Abstraction enumeration for keys, to keep the Navigator independent of the actual Window System. Definition at line 95 of file OSGNavigator.h. 00096 { 00097 LEFT=0, 00098 RIGHT, 00099 FORWARDS, 00100 BACKWARDS, 00101 LEFTROT, 00102 RIGHTROT 00103 };
|
|
|
Definition at line 154 of file OSGNavigator.cpp. 00154 : 00155 _rRotationAngle(0.04908739f), 00156 _rMotionFactor(1.f), 00157 _currentState(IDLE), 00158 _currentMode(TRACKBALL), 00159 _vp(NullFC), 00160 _cartN(NullFC), 00161 _moved(false), 00162 _clickCenter(true), 00163 _lastX(0), 00164 _lastY(0), 00165 _ip(0,0,0) 00166 { 00167 }
|
|
|
Definition at line 171 of file OSGNavigator.cpp.
|
|
||||||||||||||||
|
Mouse button press handler. Definition at line 179 of file OSGNavigator.cpp. References _currentMode, _currentState, _flyer, _lastX, _lastY, _moved, _rMotionFactor, _trackball, _walker, DOWN_MOUSE, FLY, FNOTICE, osg::WalkNavigator::forward(), osg::FlyNavigator::forward(), getIntersectionPoint(), IDLE, LEFT_MOUSE, MIDDLE_MOUSE, NONE, RIGHT_MOUSE, ROTATING, TRACKBALL, osg::TrackballNavigator::translateZ(), TRANSLATING_XY, TRANSLATING_Z, TRANSLATING_ZMINUS, TRANSLATING_ZPLUS, UP_MOUSE, and WALK. Referenced by osg::SimpleSceneManager::mouseButtonPress(). 00180 { 00181 _lastX = x; _lastY = y; 00182 _moved = false; 00183 00184 switch (_currentMode) 00185 { 00186 case NONE: 00187 _currentState = IDLE; 00188 break; 00189 00190 case TRACKBALL: 00191 00192 switch (button) 00193 { 00194 case LEFT_MOUSE : _currentState = ROTATING; 00195 break; 00196 00197 case RIGHT_MOUSE : _currentState = TRANSLATING_Z; 00198 break; 00199 00200 case MIDDLE_MOUSE: _currentState = TRANSLATING_XY; 00201 getIntersectionPoint(x,y); 00202 break; 00203 00204 case UP_MOUSE : _currentState = IDLE; 00205 _trackball.translateZ(-_rMotionFactor); 00206 break; 00207 00208 case DOWN_MOUSE : _currentState = IDLE; 00209 _trackball.translateZ(_rMotionFactor); 00210 break; 00211 00212 default: FNOTICE(("Navigator: buttonPress, unknown button\n")); 00213 break; 00214 } 00215 break; 00216 00217 case FLY: 00218 00219 switch (button) 00220 { 00221 case LEFT_MOUSE : _currentState = TRANSLATING_ZPLUS; 00222 break; 00223 00224 case MIDDLE_MOUSE: _currentState = ROTATING; 00225 break; 00226 00227 case RIGHT_MOUSE : _currentState = TRANSLATING_ZMINUS; 00228 break; 00229 00230 case UP_MOUSE : _currentState = IDLE; 00231 _flyer.forward(-_rMotionFactor); 00232 break; 00233 00234 case DOWN_MOUSE : _currentState = IDLE; 00235 _flyer.forward(_rMotionFactor); 00236 break; 00237 00238 default: FNOTICE(("Navigator: buttonPress, unknown button\n")); 00239 break; 00240 } 00241 break; 00242 00243 case WALK: 00244 00245 switch (button) 00246 { 00247 case LEFT_MOUSE : _currentState = TRANSLATING_ZPLUS; 00248 break; 00249 00250 case MIDDLE_MOUSE: _currentState = ROTATING; 00251 break; 00252 00253 case RIGHT_MOUSE : _currentState = TRANSLATING_ZMINUS; 00254 break; 00255 00256 case UP_MOUSE : _currentState = IDLE; 00257 _walker.forward(-_rMotionFactor); 00258 break; 00259 00260 case DOWN_MOUSE : _currentState = IDLE; 00261 _walker.forward(_rMotionFactor); 00262 break; 00263 00264 default: FNOTICE(("Navigator: buttonPress, unknown button\n")); 00265 break; 00266 } 00267 break; 00268 00269 default: 00270 00271 FNOTICE(("Navigator: buttonPress, unknown mode\n")); 00272 break; 00273 } 00274 }
|
|
||||||||||||||||
|
Mouse button release handler. Definition at line 278 of file OSGNavigator.cpp. References _clickCenter, _currentMode, _currentState, _moved, _trackball, _vp, osg::Action::apply(), osg::IntersectAction::create(), osg::IntersectAction::didHit(), FLY, FNOTICE, osg::Line::getDirection(), osg::IntersectAction::getHitPoint(), osg::Line::getPosition(), IDLE, NONE, osg::TrackballNavigator::setAt(), osg::IntersectAction::setLine(), TRACKBALL, and WALK. Referenced by osg::SimpleSceneManager::mouseButtonRelease(). 00279 { 00280 switch (_currentMode) 00281 { 00282 case NONE: break; 00283 00284 case TRACKBALL: if (!_moved && _clickCenter) 00285 { 00286 IntersectAction * act = IntersectAction::create(); 00287 Line line; 00288 _vp->getCamera()->calcViewRay(line, x, y, *_vp); 00289 00290 Pnt3f lp1 = line.getPosition(); 00291 Vec3f ld1 = line.getDirection(); 00292 00293 act->setLine(line); 00294 act->apply(_vp->getRoot()); 00295 if (act->didHit()) 00296 { 00297 Pnt3f p1 = act->getHitPoint(); 00298 _trackball.setAt(p1); 00299 } 00300 00301 delete act; 00302 } 00303 break; 00304 00305 case FLY: break; 00306 case WALK: break; 00307 00308 default: FNOTICE(("Navigator: buttonRelease, unknown mode\n")); 00309 break; 00310 } 00311 _currentState=IDLE; 00312 }
|
|
||||||||||||||||
|
Key press handler. Definition at line 316 of file OSGNavigator.cpp. References _currentMode, _flyer, _rMotionFactor, _rRotationAngle, _trackball, _walker, BACKWARDS, FLY, FNOTICE, osg::WalkNavigator::forward(), osg::FlyNavigator::forward(), FORWARDS, LEFT, LEFTROT, NONE, osg::WalkNavigator::right(), osg::FlyNavigator::right(), RIGHT, RIGHTROT, osg::WalkNavigator::rotate(), osg::FlyNavigator::rotate(), TRACKBALL, osg::TrackballNavigator::translateZ(), and WALK. Referenced by osg::SimpleSceneManager::key(). 00317 { 00318 switch (_currentMode) 00319 { 00320 case NONE: 00321 break; 00322 00323 case TRACKBALL: 00324 00325 switch (key) 00326 { 00327 case LEFT : /*undefined*/ break; 00328 case RIGHT : /*undefined*/ break; 00329 case FORWARDS : _trackball.translateZ(-_rMotionFactor); break; 00330 case BACKWARDS : _trackball.translateZ(_rMotionFactor); break; 00331 default : FNOTICE(("Navigator: keyPress, unknown key\n")); 00332 } 00333 break; 00334 00335 case FLY: 00336 00337 switch (key) 00338 { 00339 case LEFTROT : _flyer.rotate(-_rRotationAngle, 0); break; 00340 case RIGHTROT : _flyer.rotate( _rRotationAngle, 0); break; 00341 case LEFT : _flyer.right( _rMotionFactor); break; 00342 case RIGHT : _flyer.right(-_rMotionFactor); break; 00343 case FORWARDS : _flyer.forward(-_rMotionFactor); break; 00344 case BACKWARDS : _flyer.forward( _rMotionFactor); break; 00345 default : FNOTICE(("Navigator: keyPress, unknown key\n")); 00346 } 00347 break; 00348 00349 case WALK: 00350 00351 switch (key) 00352 { 00353 case LEFTROT : _walker.rotate(-_rRotationAngle, 0); break; 00354 case RIGHTROT : _walker.rotate( _rRotationAngle, 0); break; 00355 case LEFT : _walker.right( _rMotionFactor); break; 00356 case RIGHT : _walker.right(-_rMotionFactor); break; 00357 case FORWARDS : _walker.forward(-_rMotionFactor); break; 00358 case BACKWARDS : _walker.forward( _rMotionFactor); break; 00359 default : FNOTICE(("Navigator: keyPress, unknown key\n")); 00360 } 00361 break; 00362 00363 default: 00364 00365 FNOTICE(("Navigator: keyPress, unknown mode\n")); 00366 break; 00367 } 00368 }
|
|
||||||||||||
|
Mouse motion handler. Definition at line 372 of file OSGNavigator.cpp. References _currentMode, _currentState, _flyer, _lastX, _lastY, _moved, _rMotionFactor, _trackball, _vp, _walker, calcDeltas(), FLY, FNOTICE, osg::WalkNavigator::forward(), osg::FlyNavigator::forward(), NONE, osg::NullFC, osg::osgabs(), osg::osgpow(), osg::osgSgn(), osg::WalkNavigator::rotate(), osg::FlyNavigator::rotate(), osg::TrackballNavigator::rotate(), ROTATING, TRACKBALL, osg::TrackballNavigator::translateXY(), osg::TrackballNavigator::translateZ(), TRANSLATING_XY, TRANSLATING_Z, TRANSLATING_ZMINUS, TRANSLATING_ZPLUS, and WALK. Referenced by idle(), and osg::SimpleSceneManager::mouseMove(). 00373 { 00374 _moved = true; 00375 00376 Real32 width = Real32(_vp->getPixelWidth()); 00377 Real32 height = Real32(_vp->getPixelHeight()); 00378 00379 if(width <= 0 || height <= 0) 00380 return; 00381 00382 WindowPtr par = _vp->getParent(); 00383 Real32 winHeight; 00384 00385 if(par != NullFC) 00386 winHeight = (Real32)par->getHeight(); 00387 else 00388 winHeight = height; 00389 00390 Real32 fromX = (2.0f * (_lastX - _vp->getPixelLeft())- width)/ width; 00391 Real32 fromY = (2.0f * (winHeight - _lastY - _vp->getPixelBottom()) 00392 - height) / height; 00393 Real32 toX = (2.0f * (x - _vp->getPixelLeft()) - width) / width; 00394 Real32 toY = (2.0f * (winHeight - y - _vp->getPixelBottom()) 00395 - height)/height; 00396 00397 switch (_currentMode) 00398 { 00399 case NONE: 00400 FNOTICE(("Navigator: moveTo NONE mode\n")); 00401 break; 00402 00403 case TRACKBALL: 00404 00405 switch (_currentState) 00406 { 00407 case ROTATING :_trackball.rotate(fromX, fromY, toX, toY); 00408 break; 00409 00410 case TRANSLATING_XY:{ 00411 Real32 distanceX = 0,distanceY = 0; 00412 calcDeltas(Int16(_lastX), Int16(_lastY), x, y, 00413 distanceX, distanceY); 00414 _trackball.translateXY(distanceX, distanceY); 00415 } 00416 break; 00417 00418 case TRANSLATING_Z: { 00419 Real32 distance = osgSgn(toY-fromY)* 00420 100.f * 00421 osgpow(osgabs(toY-fromY),2.f); 00422 _trackball.translateZ(distance * _rMotionFactor); 00423 } 00424 break; 00425 00426 default :;//IDLE 00427 } 00428 00429 break; 00430 00431 case FLY: 00432 00433 { 00434 Real32 distanceX = -(fromX-toX); 00435 Real32 distanceY = (fromY-toY); 00436 _flyer.rotate(distanceX, distanceY); 00437 00438 switch (_currentState) 00439 { 00440 case TRANSLATING_ZPLUS: _flyer.forward(-_rMotionFactor); 00441 break; 00442 00443 case TRANSLATING_ZMINUS: _flyer.forward(_rMotionFactor); 00444 break; 00445 00446 case ROTATING: break; 00447 00448 default: ;//IDLE 00449 } 00450 } 00451 break; 00452 00453 case WALK: 00454 00455 { 00456 Real32 distanceX = -(fromX-toX); 00457 Real32 distanceY = (fromY-toY); 00458 _walker.rotate(distanceX, distanceY); 00459 00460 switch (_currentState) 00461 { 00462 case TRANSLATING_ZPLUS: _walker.forward(-_rMotionFactor); 00463 break; 00464 00465 case TRANSLATING_ZMINUS: _walker.forward(_rMotionFactor); 00466 break; 00467 00468 case ROTATING: break; 00469 00470 default: ;//IDLE 00471 } 00472 } 00473 break; 00474 00475 default: 00476 00477 FNOTICE(("Navigator: moveTo, unknown mode\n")); 00478 break; 00479 } 00480 _lastX = x; 00481 _lastY = y; 00482 }
|
|
||||||||||||||||
|
Performs some idle operations, depending on the current navigation mode Definition at line 486 of file OSGNavigator.cpp. References _currentMode, FLY, moveTo(), NONE, TRACKBALL, and WALK. Referenced by osg::SimpleSceneManager::idle(). 00487 { 00488 switch (_currentMode) 00489 { 00490 case NONE: 00491 case TRACKBALL: 00492 break; 00493 case FLY: 00494 case WALK: 00495 if (buttons) 00496 moveTo(x,y); 00497 break; 00498 } 00499 }
|
|
|
Updates the camera transformation matrix directly in the node specified as the cart. Definition at line 504 of file OSGNavigator.cpp. References _cartN, _currentMode, _flyer, _NoneMatrix, _trackball, _walker, osg::beginEditCP(), osg::AttachmentContainerPtr::dcast(), osg::endEditCP(), FFATAL, FLY, FNOTICE, FWARNING, osg::NodePtr::getCore(), getMatrix(), osg::TrackballNavigator::getMatrix(), osg::TransformationMatrix< ValueTypeT >::inverse(), osg::TransformationMatrix< ValueTypeT >::mult(), NONE, osg::NullFC, osg::TransformationMatrix< ValueTypeT >::setIdentity(), theMatrix, TRACKBALL, and WALK. Referenced by osg::SimpleSceneManager::redraw(). 00505 { 00506 theMatrix.setIdentity(); 00507 if(_cartN != NullFC && _cartN->getParent() != NullFC) 00508 { 00509 _cartN->getParent()->getToWorld(theMatrix); 00510 theMatrix.inverse(theMatrix); 00511 } 00512 00513 switch(_currentMode) 00514 { 00515 case NONE: theMatrix.mult(_NoneMatrix); break; 00516 case TRACKBALL: theMatrix.mult(_trackball.getMatrix()); break; 00517 case FLY: theMatrix.mult(_flyer .getMatrix()); break; 00518 case WALK: theMatrix.mult(_walker .getMatrix()); break; 00519 default: FNOTICE(("Navigator: updateCamTrans, unknown mode\n")); 00520 break; 00521 } 00522 00523 if(_cartN != NullFC) 00524 { 00525 TransformPtr t = TransformPtr::dcast(_cartN->getCore()); 00526 if(t == NullFC) 00527 { 00528 FWARNING (("Navigator: updateCamTrans, core is not TransformPtr\n")); 00529 } 00530 else 00531 { 00532 beginEditCP(t); 00533 { 00534 t->getSFMatrix()->setValue(theMatrix); 00535 } 00536 endEditCP(t); 00537 } 00538 } 00539 else 00540 { 00541 FFATAL (("!_cartN in Navigator::updateCameraTrans\n")); 00542 } 00543 }
|
|
|
Referenced by osg::SimpleSceneManager::initialize(), and osg::SimpleSceneManager::setNavigationMode(). |
|
|
Set the viewport. Definition at line 572 of file OSGNavigator.cpp. References _vp, _walker, osg::WalkNavigator::setGround(), and osg::WalkNavigator::setWorld(). Referenced by osg::SimpleSceneManager::initialize(), and osg::SimpleSceneManager::setWindow(). 00573 { 00574 _vp=new_viewport; 00575 _walker.setGround(_vp->getRoot()); 00576 _walker.setWorld (_vp->getRoot()); 00577 }
|
|
|
Set the rotation angle. Definition at line 558 of file OSGNavigator.cpp. References _rRotationAngle. 00559 { 00560 _rRotationAngle = new_angle; 00561 }
|
|
|
Set the motion factor. Definition at line 565 of file OSGNavigator.cpp. References _rMotionFactor. Referenced by osg::SimpleSceneManager::showAll(). 00566 { 00567 _rMotionFactor = new_factor; 00568 }
|
|
|
Set the from point, i.e. the viewer position. Definition at line 590 of file OSGNavigator.cpp. References _currentMode, _flyer, _NoneMatrix, _trackball, _walker, FLY, FNOTICE, NONE, osg::FlyNavigator::setFrom(), osg::TrackballNavigator::setFrom(), setNoneMatrix(), TRACKBALL, and WALK. 00591 { 00592 switch (_currentMode) 00593 { 00594 case NONE: 00595 setNoneMatrix( new_from, 00596 (Pnt3f)(_NoneMatrix[3]-_NoneMatrix[2]), 00597 (Vec3f) _NoneMatrix[1] ); 00598 break; 00599 case TRACKBALL: _trackball.setFrom(new_from); break; 00600 case FLY: _flyer .setFrom(new_from); break; 00601 case WALK: _walker .setFrom(new_from); break; 00602 default: FNOTICE(("Navigator: setFrom, unknown mode")); 00603 break; 00604 } 00605 }
|
|
|
Set the at point, i.e. the target position for the viewer. Definition at line 609 of file OSGNavigator.cpp. References _currentMode, _flyer, _NoneMatrix, _trackball, _walker, FLY, FNOTICE, NONE, osg::FlyNavigator::setAt(), osg::TrackballNavigator::setAt(), setNoneMatrix(), TRACKBALL, and WALK. 00610 { 00611 switch (_currentMode) 00612 { 00613 case NONE: 00614 setNoneMatrix((Pnt3f)_NoneMatrix[3], new_at, (Vec3f)_NoneMatrix[1]); 00615 break; 00616 case TRACKBALL: _trackball.setAt(new_at); break; 00617 case FLY: _flyer .setAt(new_at); break; 00618 case WALK: _walker .setAt(new_at); break; 00619 default: FNOTICE(("Navigator: setAt, unknown mode")); 00620 break; 00621 } 00622 }
|
|
|
Set the distance from the target position. Definition at line 626 of file OSGNavigator.cpp. References _currentMode, _flyer, _trackball, _walker, FLY, FNOTICE, osg::WalkNavigator::forward(), osg::FlyNavigator::forward(), NONE, osg::TrackballNavigator::setDistance(), TRACKBALL, and |