#include <OSGNavigator.h>
Public Types | |
| enum | Mode { TRACKBALL = 0, FLY, WALK, NONE } |
| enum | State { IDLE = 0, ROTATING, TRANSLATING_XY, TRANSLATING_Z, TRANSLATING_ZPLUS = 10, TRANSLATING_ZMINUS } |
| enum | MouseButton { LEFT_MOUSE = 0, MIDDLE_MOUSE, RIGHT_MOUSE, UP_MOUSE, DOWN_MOUSE } |
| enum | Key { LEFT = 0, RIGHT, FORWARDS, BACKWARDS, LEFTROT, RIGHTROT } |
Public Member Functions | |
Constructors | |
| Navigator () | |
Destructors | |
| virtual | ~Navigator () |
Notificators | |
| virtual void | buttonPress (Int16 button, Int16 x, Int16 y) |
| virtual void | buttonRelease (Int16 button, Int16 x, Int16 y) |
| virtual void | keyPress (Int16 key, Int16 x, Int16 y) |
| virtual void | moveTo (Int16 x, Int16 y) |
| virtual void | idle (Int16 buttons, Int16 x, Int16 y) |
| void | updateCameraTransformation () |
Set | |
| void | setMode (Mode new_mode) |
| void | setViewport (ViewportPtr new_viewport) |
| void | setRotationAngle (Real32 new_angle) |
| void | setMotionFactor (Real32 new_factor) |
| void | setFrom (Pnt3f new_from) |
| void | setAt (Pnt3f new_at) |
| void | setDistance (Real32 new_distance) |
| void | setUp (Vec3f new_up) |
| void | set (Pnt3f new_from, Pnt3f new_at, Vec3f new_up) |
| void | set (const Matrix &new_matrix) |
| bool | setAbsolute (bool state) |
| bool | setClickCenter (bool state) |
| bool | setClickNoIntersect (bool state) |
| void | setCameraTransformation (const NodePtr &new_cartn) |
Get | |
| const Matrix & | getMatrix () |
| const Pnt3f & | getFrom () |
| const Pnt3f & | getAt () |
| const Vec3f & | getUp () |
| Real32 | getDistance () |
| State | getState () |
| Mode | getMode () |
| Real32 | getRotationAngle () |
| Real32 | getMotionFactor () |
| bool | getAbsolute () |
| bool | getClickCenter () |
| bool | getClickNoIntersect () |
| WalkNavigator * | getWalkNavigator () |
Private Member Functions | |
| void | setNoneMatrix (Pnt3f new_from, Pnt3f new_at, Vec3f new_up) |
| void | getIntersectionPoint (Int16 x, Int16 y) |
| void | calcDeltas (Int16 fromX, Int16 fromY, Int16 toX, Int16 toY, Real32 &distanceX, Real32 &distanceY) |
Private Attributes | |
Class Fields | |
| TrackballNavigator | _trackball |
| FlyNavigator | _flyer |
| WalkNavigator | _walker |
| Real32 | _rRotationAngle |
| Real32 | _rMotionFactor |
| State | _currentState |
| Mode | _currentMode |
| bool | _absolute |
| ViewportPtr | _vp |
| NodePtr | _cartN |
| bool | _moved |
| bool | _clickCenter |
| bool | _clickNoIntersect |
| Real32 | _lastX |
| Real32 | _lastY |
| Pnt3f | _ip |
| Vec3f | _dir |
| Matrix | theMatrix |
| Matrix | _NoneMatrix |
Definition at line 62 of file OSGNavigator.h.
| enum OSG::Navigator::Mode |
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.
| IDLE | Inactive state. |
| ROTATING | State for in-place rotation. |
| TRANSLATING_XY | State for x/y translation, used by the Trackball case. |
| TRANSLATING_Z | State for z translation, used by the Trackball case. |
| TRANSLATING_ZPLUS | State for rotation with automatic forward motion. The standard fly forward state. |
| TRANSLATING_ZMINUS | State for rotation with automatic backwards motion. The standard fly backwards state. |
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.
| LEFT_MOUSE | |
| MIDDLE_MOUSE | |
| RIGHT_MOUSE | |
| UP_MOUSE | Mouse wheel up button. |
| DOWN_MOUSE | Mouse wheel down button. |
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 };
| enum OSG::Navigator::Key |
| Navigator::Navigator | ( | ) |
Definition at line 153 of file OSGNavigator.cpp.
00153 : 00154 _rRotationAngle(0.04908739f), 00155 _rMotionFactor(1.f), 00156 _currentState(IDLE), 00157 _currentMode(TRACKBALL), 00158 _absolute(true), 00159 _vp(NullFC), 00160 _cartN(NullFC), 00161 _moved(false), 00162 _clickCenter(true), 00163 _clickNoIntersect(false), 00164 _lastX(0), 00165 _lastY(0), 00166 _ip(0,0,0) 00167 { 00168 }
| Navigator::~Navigator | ( | ) | [virtual] |
Definition at line 172 of file OSGNavigator.cpp.
References _cartN, and OSG::subRef().
00173 { 00174 OSG::subRef(_cartN); 00175 }
| void Navigator::buttonPress | ( | Int16 | button, | |
| Int16 | x, | |||
| Int16 | y | |||
| ) | [virtual] |
Definition at line 181 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().
00182 { 00183 _lastX = x; _lastY = y; 00184 _moved = false; 00185 00186 switch (_currentMode) 00187 { 00188 case NONE: 00189 _currentState = IDLE; 00190 break; 00191 00192 case TRACKBALL: 00193 00194 switch (button) 00195 { 00196 case LEFT_MOUSE : _currentState = ROTATING; 00197 break; 00198 00199 case RIGHT_MOUSE : _currentState = TRANSLATING_Z; 00200 break; 00201 00202 case MIDDLE_MOUSE: _currentState = TRANSLATING_XY; 00203 getIntersectionPoint(x,y); 00204 break; 00205 00206 case UP_MOUSE : _currentState = IDLE; 00207 _trackball.translateZ(-_rMotionFactor); 00208 break; 00209 00210 case DOWN_MOUSE : _currentState = IDLE; 00211 _trackball.translateZ(_rMotionFactor); 00212 break; 00213 00214 default: FNOTICE(("Navigator: buttonPress, unknown button\n")); 00215 break; 00216 } 00217 break; 00218 00219 case FLY: 00220 00221 switch (button) 00222 { 00223 case LEFT_MOUSE : _currentState = TRANSLATING_ZPLUS; 00224 break; 00225 00226 case MIDDLE_MOUSE: _currentState = ROTATING; 00227 break; 00228 00229 case RIGHT_MOUSE : _currentState = TRANSLATING_ZMINUS; 00230 break; 00231 00232 case UP_MOUSE : _currentState = IDLE; 00233 _flyer.forward(-_rMotionFactor); 00234 break; 00235 00236 case DOWN_MOUSE : _currentState = IDLE; 00237 _flyer.forward(_rMotionFactor); 00238 break; 00239 00240 default: FNOTICE(("Navigator: buttonPress, unknown button\n")); 00241 break; 00242 } 00243 break; 00244 00245 case WALK: 00246 00247 switch (button) 00248 { 00249 case LEFT_MOUSE : _currentState = TRANSLATING_ZPLUS; 00250 break; 00251 00252 case MIDDLE_MOUSE: _currentState = ROTATING; 00253 break; 00254 00255 case RIGHT_MOUSE : _currentState = TRANSLATING_ZMINUS; 00256 break; 00257 00258 case UP_MOUSE : _currentState = IDLE; 00259 _walker.forward(-_rMotionFactor); 00260 break; 00261 00262 case DOWN_MOUSE : _currentState = IDLE; 00263 _walker.forward(_rMotionFactor); 00264 break; 00265 00266 default: FNOTICE(("Navigator: buttonPress, unknown button\n")); 00267 break; 00268 } 00269 break; 00270 00271 default: 00272 00273 FNOTICE(("Navigator: buttonPress, unknown mode\n")); 00274 break; 00275 } 00276 }
| void Navigator::buttonRelease | ( | Int16 | button, | |
| Int16 | x, | |||
| Int16 | y | |||
| ) | [virtual] |
Mouse button release handler.
Definition at line 280 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().
00281 { 00282 switch (_currentMode) 00283 { 00284 case NONE: break; 00285 00286 case TRACKBALL: if (!_moved && _clickCenter) 00287 { 00288 IntersectAction * act = IntersectAction::create(); 00289 Line line; 00290 _vp->getCamera()->calcViewRay(line, x, y, *_vp); 00291 00292 Pnt3f lp1 = line.getPosition(); 00293 Vec3f ld1 = line.getDirection(); 00294 00295 act->setLine(line); 00296 act->apply(_vp->getRoot()); 00297 if (act->didHit()) 00298 { 00299 Pnt3f p1 = act->getHitPoint(); 00300 _trackball.setAt(p1); 00301 } 00302 00303 delete act; 00304 } 00305 break; 00306 00307 case FLY: break; 00308 case WALK: break; 00309 00310 default: FNOTICE(("Navigator: buttonRelease, unknown mode\n")); 00311 break; 00312 } 00313 _currentState=IDLE; 00314 }
| void Navigator::keyPress | ( | Int16 | key, | |
| Int16 | x, | |||
| Int16 | y | |||
| ) | [virtual] |
Key press handler.
Definition at line 318 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().
00319 { 00320 switch (_currentMode) 00321 { 00322 case NONE: 00323 break; 00324 00325 case TRACKBALL: 00326 00327 switch (key) 00328 { 00329 case LEFT : /*undefined*/ break; 00330 case RIGHT : /*undefined*/ break; 00331 case FORWARDS : _trackball.translateZ(-_rMotionFactor); break; 00332 case BACKWARDS : _trackball.translateZ(_rMotionFactor); break; 00333 default : FNOTICE(("Navigator: keyPress, unknown key\n")); 00334 } 00335 break; 00336 00337 case FLY: 00338 00339 switch (key) 00340 { 00341 case LEFTROT : _flyer.rotate(-_rRotationAngle, 0); break; 00342 case RIGHTROT : _flyer.rotate( _rRotationAngle, 0); break; 00343 case LEFT : _flyer.right( _rMotionFactor); break; 00344 case RIGHT : _flyer.right(-_rMotionFactor); break; 00345 case FORWARDS : _flyer.forward(-_rMotionFactor); break; 00346 case BACKWARDS : _flyer.forward( _rMotionFactor); break; 00347 default : FNOTICE(("Navigator: keyPress, unknown key\n")); 00348 } 00349 break; 00350 00351 case WALK: 00352 00353 switch (key) 00354 { 00355 case LEFTROT : _walker.rotate(-_rRotationAngle, 0); break; 00356 case RIGHTROT : _walker.rotate( _rRotationAngle, 0); break; 00357 case LEFT : _walker.right( _rMotionFactor); break; 00358 case RIGHT : _walker.right(-_rMotionFactor); break; 00359 case FORWARDS : _walker.forward(-_rMotionFactor); break; 00360 case BACKWARDS : _walker.forward( _rMotionFactor); break; 00361 default : FNOTICE(("Navigator: keyPress, unknown key\n")); 00362 } 00363 break; 00364 00365 default: 00366 00367 FNOTICE(("Navigator: keyPress, unknown mode\n")); 00368 break; 00369 } 00370 }
| void Navigator::moveTo | ( | Int16 | x, | |
| Int16 | y | |||
| ) | [virtual] |
Mouse motion handler.
Definition at line 374 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, 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().
00375 { 00376 _moved = true; 00377 00378 Real32 width = Real32(_vp->getPixelWidth()); 00379 Real32 height = Real32(_vp->getPixelHeight()); 00380 00381 if(width <= 0 || height <= 0) 00382 return; 00383 00384 WindowPtr par = _vp->getParent(); 00385 Real32 winHeight; 00386 00387 if(par != NullFC) 00388 winHeight = (Real32)par->getHeight(); 00389 else 00390 winHeight = height; 00391 00392 Real32 fromX = (2.0f * (_lastX - _vp->getPixelLeft())- width)/ width; 00393 Real32 fromY = (2.0f * (winHeight - _lastY - _vp->getPixelBottom()) 00394 - height) / height; 00395 Real32 toX = (2.0f * (x - _vp->getPixelLeft()) - width) / width; 00396 Real32 toY = (2.0f * (winHeight - y - _vp->getPixelBottom()) 00397 - height)/height; 00398 switch (_currentMode) 00399 { 00400 case NONE: 00401 FNOTICE(("Navigator: moveTo NONE mode\n")); 00402 break; 00403 00404 case TRACKBALL: 00405 00406 switch (_currentState) 00407 { 00408 case ROTATING :_trackball.rotate(fromX, fromY, toX, toY); 00409 break; 00410 00411 case TRANSLATING_XY:{ 00412 Real32 distanceX = 0,distanceY = 0; 00413 calcDeltas(Int16(_lastX), Int16(_lastY), x, y, 00414 distanceX, distanceY); 00415 _trackball.translateXY(distanceX, distanceY); 00416 } 00417 break; 00418 00419 case TRANSLATING_Z: { 00420 Real32 distance = osgSgn(toY-fromY)* 00421 100.f * 00422 osgPow(osgAbs(toY-fromY),2.f); 00423 _trackball.translateZ(distance * _rMotionFactor); 00424 } 00425 break; 00426 00427 default :;//IDLE 00428 } 00429 00430 break; 00431 00432 case FLY: 00433 00434 { 00435 Real32 distanceX = -(fromX-toX); 00436 Real32 distanceY = (fromY-toY); 00437 _flyer.rotate(distanceX, distanceY); 00438 00439 switch (_currentState) 00440 { 00441 case TRANSLATING_ZPLUS: _flyer.forward(-_rMotionFactor); 00442 break; 00443 00444 case TRANSLATING_ZMINUS: _flyer.forward(_rMotionFactor); 00445 break; 00446 00447 case ROTATING: break; 00448 00449 default: ;//IDLE 00450 } 00451 } 00452 break; 00453 00454 case WALK: 00455 00456 { 00457 Real32 distanceX = -(fromX-toX); 00458 Real32 distanceY = (fromY-toY); 00459 _walker.rotate(distanceX, distanceY); 00460 00461 switch (_currentState) 00462 { 00463 case TRANSLATING_ZPLUS: _walker.forward(-_rMotionFactor); 00464 break; 00465 00466 case TRANSLATING_ZMINUS: _walker.forward(_rMotionFactor); 00467 break; 00468 00469 case ROTATING: break; 00470 00471 default: ;//IDLE 00472 } 00473 } 00474 break; 00475 00476 default: 00477 00478 FNOTICE(("Navigator: moveTo, unknown mode\n")); 00479 break; 00480 } 00481 _lastX = x; 00482 _lastY = y; 00483 }
| void Navigator::idle | ( | Int16 | buttons, | |
| Int16 | x, | |||
| Int16 | y | |||
| ) | [virtual] |
Performs some idle operations, depending on the current navigation mode
Definition at line 487 of file OSGNavigator.cpp.
References _currentMode, FLY, moveTo(), NONE, TRACKBALL, and WALK.
Referenced by OSG::SimpleSceneManager::idle().
00488 { 00489 switch (_currentMode) 00490 { 00491 case NONE: 00492 case TRACKBALL: 00493 break; 00494 case FLY: 00495 case WALK: 00496 if (buttons) 00497 moveTo(x,y); 00498 break; 00499 } 00500 }
| void Navigator::updateCameraTransformation | ( | ) |
Updates the camera transformation matrix directly in the node specified as the cart.
Definition at line 505 of file OSGNavigator.cpp.
References _absolute, _cartN, _currentMode, _flyer, _NoneMatrix, _trackball, _walker, FFATAL, FLY, FNOTICE, FWARNING, getMatrix(), OSG::TrackballNavigator::getMatrix(), OSG::TransformationMatrix< ValueTypeT >::inverse(), OSG::TransformationMatrix< ValueTypeT >::mult(), NONE, NullFC, OSG::TransformationMatrix< ValueTypeT >::setIdentity(), theMatrix, TRACKBALL, and WALK.
Referenced by OSG::SimpleSceneManager::update().
00506 { 00507 theMatrix.setIdentity(); 00508 if(_absolute && _cartN != NullFC && _cartN->getParent() != NullFC) 00509 { 00510 _cartN->getParent()->getToWorld(theMatrix); 00511 theMatrix.inverse(theMatrix); 00512 } 00513 00514 switch(_currentMode) 00515 { 00516 case NONE: theMatrix.mult(_NoneMatrix); break; 00517 case TRACKBALL: theMatrix.mult(_trackball.getMatrix()); break; 00518 case FLY: theMatrix.mult(_flyer .getMatrix()); break; 00519 case WALK: theMatrix.mult(_walker .getMatrix()); break; 00520 default: FNOTICE(("Navigator: updateCamTrans, unknown mode\n")); 00521 break; 00522 } 00523 00524 if(_cartN != NullFC) 00525 { 00526 TransformPtr t = dynamic_cast<TransformPtr>(_cartN->getCore()); 00527 if(t == NullFC) 00528 { 00529 FWARNING (("Navigator: updateCamTrans, core is not TransformPtr\n")); 00530 } 00531 else 00532 { 00533 if(t->getMatrix() != theMatrix) 00534 { 00535 t->setMatrix(theMatrix); 00536 } 00537 } 00538 } 00539 else 00540 { 00541 FFATAL (("!_cartN in Navigator::updateCameraTrans\n")); 00542 } 00543 }
| void Navigator::setMode | ( | Mode | new_mode | ) |
Definition at line 549 of file OSGNavigator.cpp.
References _currentMode.
Referenced by OSG::SimpleSceneManager::initialize(), and OSG::SimpleSceneManager::setNavigationMode().
00550 { 00551 if (_currentMode == new_mode) return; 00552 00553 _currentMode = new_mode; 00554 }
| void Navigator::setViewport | ( | ViewportPtr | new_viewport | ) |
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 }
| void Navigator::setRotationAngle | ( | Real32 | new_angle | ) |
Set the rotation angle.
Definition at line 558 of file OSGNavigator.cpp.
References _rRotationAngle.
00559 { 00560 _rRotationAngle = new_angle; 00561 }
| void Navigator::setMotionFactor | ( | Real32 | new_factor | ) |
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 }
| void Navigator::setFrom | ( | Pnt3f | new_from | ) |
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;