Changeset 1021 for trunk/Source/System/Window/Utilities/OSGFlyEngine.cpp
- Timestamp:
- 11/26/07 22:53:32 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Source/System/Window/Utilities/OSGFlyEngine.cpp
r785 r1021 3 3 * * 4 4 * * 5 * Copyright (C) 2000 ,2001by the OpenSG Forum *5 * Copyright (C) 2000-2002 by the OpenSG Forum * 6 6 * * 7 7 * www.opensg.org * … … 42 42 #include "OSGMatrixUtility.h" 43 43 44 #include "OSGFlyNavigator.h" 44 #include "OSGFlyEngine.h" 45 46 #include "OSGNode.h" 47 #include "OSGCamera.h" 48 #include "OSGBackground.h" 45 49 46 50 OSG_USING_NAMESPACE … … 50 54 \***************************************************************************/ 51 55 52 /*! \class OSG::Fly Navigator56 /*! \class OSG::FlyEngine 53 57 \ingroup GrpSystemWindowNavigators 54 58 55 The Fly Navigatormodels a simple flying navigation model, see \ref59 The FlyEngine models a simple flying navigation model, see \ref 56 60 PageSystemWindowNavigatorsFly for a description. 57 61 58 62 */ 59 63 60 /*! \var OSG::Fly Navigator::_rFrom64 /*! \var OSG::FlyEngine::_rFrom 61 65 62 66 The from point, i.e. the viewer position. 63 67 */ 64 68 65 /*! \var OSG::Fly Navigator::_rAt69 /*! \var OSG::FlyEngine::_rAt 66 70 67 71 The at point, i.e. the target position. 68 72 */ 69 73 70 /*! \var OSG::Fly Navigator::_vUp74 /*! \var OSG::FlyEngine::_vUp 71 75 72 76 The up vector. 73 77 */ 74 78 75 /*! \var OSG::Fly Navigator::_tMatrix79 /*! \var OSG::FlyEngine::_tMatrix 76 80 77 81 The transformation matrix for this navigator. 78 82 */ 79 83 80 81 84 /*------------------------- constructors ----------------------------------*/ 82 85 83 Fly Navigator::FlyNavigator()86 FlyEngine::FlyEngine(void) : Inherited() 84 87 { 85 88 _rFrom .setValues(0,0,0); … … 89 92 } 90 93 91 92 94 /*-------------------------- destructors ----------------------------------*/ 93 95 94 Fly Navigator::~FlyNavigator()96 FlyEngine::~FlyEngine() 95 97 { 96 98 } … … 98 100 /*------------------------------ get --------------------------------------*/ 99 101 102 /*! Get the from point. 103 */ 104 const Pnt3f &FlyEngine::getFrom() 105 { 106 return _rFrom; 107 } 108 109 /*! Get the at point. 110 */ 111 const Pnt3f &FlyEngine::getAt() 112 { 113 return _rAt; 114 } 115 116 /*! Get the up vector. 117 */ 118 const Vec3f &FlyEngine::getUp() 119 { 120 return _vUp; 121 } 122 100 123 /*! Get the current transformation matrix. 101 124 */ 102 Matrix &FlyNavigator::getMatrix()125 const Matrix &FlyEngine::getMatrix() 103 126 { 104 127 MatrixLookAt(_tMatrix,_rFrom,_rAt,_vUp); … … 106 129 } 107 130 108 /*! Get the from point. 109 */ 110 Pnt3f &FlyNavigator::getFrom() 111 { 112 return _rFrom; 113 } 114 115 /*! Get the at point. 116 */ 117 Pnt3f &FlyNavigator::getAt() 118 { 119 return _rAt; 120 } 121 122 /*! Get the up vector. 123 */ 124 Vec3f &FlyNavigator::getUp() 125 { 126 return _vUp; 127 } 128 131 /*! Not needed by FlyEngine!!! 132 */ 133 // FIXME: remove getDistance() from NavigatorEngine??? 134 Real32 FlyEngine::getDistance() 135 { 136 return 0.0f; 137 } 129 138 130 139 /*------------------------------ set --------------------------------------*/ … … 133 142 of all transformations). 134 143 */ 135 void Fly Navigator::setFrom(Pnt3f new_from)144 void FlyEngine::setFrom(Pnt3f new_from) 136 145 { 137 146 _rFrom=new_from; … … 140 149 /*! Sets the target point at which the viewer is looking. 141 150 */ 142 void Fly Navigator::setAt(Pnt3f new_At)151 void FlyEngine::setAt(Pnt3f new_At) 143 152 { 144 153 _rAt=new_At; … … 147 156 /*! Sets the up vector, i.e. the direction that point up on the screen. 148 157 */ 149 void Fly Navigator::setUp(Vec3f new_up)158 void FlyEngine::setUp(Vec3f new_up) 150 159 { 151 160 _vUp=new_up; … … 154 163 /*! Set the position and the orientation at once. 155 164 */ 156 void Fly Navigator::set(Pnt3f new_from,Pnt3f new_At,Vec3f new_up)165 void FlyEngine::set(Pnt3f new_from,Pnt3f new_At,Vec3f new_up) 157 166 { 158 167 _rFrom=new_from; … … 163 172 /*! Set the position and the orientation at once using a matrix. 164 173 */ 165 void Fly Navigator::set(Matrixnew_matrix)174 void FlyEngine::set(const Matrix& new_matrix) 166 175 { 167 176 _rFrom= (Pnt3f) new_matrix[3]; … … 171 180 } 172 181 182 /*! Moves \var dist steps forward 183 */ 184 void FlyEngine::setDistance(Real32 dist) 185 { 186 forward(dist); 187 } 188 189 /*---------------------- navigator engine callbacks ------------------------*/ 190 191 void FlyEngine::buttonPress(Int16 button, Int16 x, Int16 y, Navigator* nav) 192 { 193 switch (button) 194 { 195 case Navigator::LEFT_MOUSE: 196 _currentState = Navigator::TRANSLATING_ZPLUS; 197 break; 198 case Navigator::MIDDLE_MOUSE: 199 _currentState = Navigator::ROTATING; 200 break; 201 case Navigator::RIGHT_MOUSE: 202 _currentState = Navigator::TRANSLATING_ZMINUS; 203 break; 204 case Navigator::UP_MOUSE: 205 _currentState = Navigator::IDLE; 206 forward(-nav->getMotionFactor()); 207 break; 208 case Navigator::DOWN_MOUSE: 209 _currentState = Navigator::IDLE; 210 forward(nav->getMotionFactor()); 211 break; 212 default: 213 FNOTICE(("FlyEngine: buttonPress, unknown button\n")); 214 break; 215 } 216 } 217 218 void FlyEngine::buttonRelease(Int16 button, Int16 x,Int16 y,Navigator* nav) 219 { 220 _currentState = Navigator::IDLE; 221 } 222 223 void FlyEngine::keyPress(Int16 key, Int16 x,Int16 y,Navigator* nav) 224 { 225 switch (key) 226 { 227 case Navigator::LEFTROT: 228 rotate(-nav->getRotationAngle(), 0); 229 break; 230 case Navigator::RIGHTROT: 231 rotate(nav->getRotationAngle(), 0); 232 break; 233 case Navigator::LEFT: 234 right(nav->getMotionFactor()); 235 break; 236 case Navigator::RIGHT: 237 right(-nav->getMotionFactor()); 238 break; 239 case Navigator::FORWARDS: 240 forward(-nav->getMotionFactor()); 241 break; 242 case Navigator::BACKWARDS: 243 forward( nav->getMotionFactor()); 244 break; 245 default: 246 FNOTICE(("FlyEngine: keyPress, unknown key\n")); 247 break; 248 } 249 } 250 251 void FlyEngine::moveTo(Int16 x,Int16 y,Navigator* nav) 252 { 253 Real32 fromX,fromY, toX,toY; 254 255 nav->calcFromTo(x,y, fromX,fromY, toX,toY); 256 257 Real32 distanceX = -(fromX-toX); 258 Real32 distanceY = (fromY-toY); 259 rotate(distanceX, distanceY); 260 261 switch (_currentState) 262 { 263 case Navigator::TRANSLATING_ZPLUS: 264 forward(-nav->getMotionFactor()); 265 break; 266 case Navigator::TRANSLATING_ZMINUS: 267 forward(nav->getMotionFactor()); 268 break; 269 case Navigator::ROTATING: 270 break; 271 default: 272 //IDLE 273 break; 274 } 275 } 276 277 void FlyEngine::idle(Int16 buttons, Int16 x,Int16 y,Navigator* nav) 278 { 279 } 280 281 void FlyEngine::onViewportChanged(ViewportPtr new_viewport) 282 { 283 // nothing to do here 284 } 285 173 286 /*---------------------- Flyer Transformations ----------------------------*/ 174 287 … … 176 289 left/right axis. \a deltaX and \a deltaY should be between -Pi and Pi. 177 290 */ 178 void Fly Navigator::rotate(Real32 deltaX, Real32 deltaY)291 void FlyEngine::rotate(Real32 deltaX, Real32 deltaY) 179 292 { 180 293 // rotate around the up vector … … 219 332 /*! Flies forward, i.e. translation \a step units along the view vector. 220 333 */ 221 Real32 Fly Navigator::forward(Real32 step)334 Real32 FlyEngine::forward(Real32 step) 222 335 { 223 336 Vec3f lv; … … 235 348 /*! Strafes to the right, i.e. translates along the side vector. 236 349 */ 237 Real32 Fly Navigator::right(Real32 step)350 Real32 FlyEngine::right(Real32 step) 238 351 { 239 352 Vec3f sv;
