#include <OSGTrackballNavigator.h>
Public Types | |
| enum | State { IDLE = 0, ROTATING, TRANSLATING_XY, TRANSLATING_Z } |
Public Member Functions | |
Constructors | |
| * | TrackballNavigator (Real32 rSize=0.8) |
Destructors | |
| * | ~TrackballNavigator () |
Class Get | |
| *const char * | getClassname (void) |
Get | |
| *Matrix & | getMatrix () |
| Pnt3f & | getFrom () |
| Pnt3f & | getAt () |
| Vec3f & | getUp () |
| Real32 | getDistance () |
Set | |
| *void | setAt (Pnt3f new_at) |
| void | setFrom (Pnt3f new_from) |
| void | setDistance (Real32 new_distance) |
| void | setUp (Vec3f new_up) |
| void | set (Pnt3f new_from, Pnt3f new_center, Vec3f new_up) |
| void | set (Matrix new_matrix) |
Trackball Transformations | |
| *void | rotate (Real32 fromX, Real32 fromY, Real32 toX, Real32 toY) |
| void | translateXY (Real32 distanceX, Real32 distanceY) |
| void | translateZ (Real32 distance) |
Private Member Functions | |
| void | updateFinalMatrix () |
| Real32 | projectToSphere (Real32 rRadius, Real32 rX, Real32 rY) |
Private Attributes | |
Members | |
| *Real32 | _rRadius |
| *Real32 | _rDistance |
| Matrix | _tMatrix |
| Matrix | _finalMatrix |
| State | _currentState |
| Pnt3f | _pFrom |
| Pnt3f | _pAt |
| Vec3f | _vUp |
Dev:
Definition at line 54 of file OSGTrackballNavigator.h.
|
|
Definition at line 59 of file OSGTrackballNavigator.h. 00060 { 00061 IDLE=0, 00062 ROTATING, 00063 TRANSLATING_XY, 00064 TRANSLATING_Z 00065 };
|
|
|
Definition at line 110 of file OSGTrackballNavigator.cpp. References _finalMatrix, _pAt, _pFrom, _rDistance, _tMatrix, _vUp, osg::TransformationMatrix< ValueTypeT >::setIdentity(), and osg::VecStorage3< ValueTypeT >::setValues(). 00110 : _rRadius(rSize) 00111 { 00112 _finalMatrix.setIdentity(); 00113 _tMatrix.setIdentity(); 00114 _pFrom.setValues(0,0,0); 00115 _pAt .setValues(0,0,1); 00116 _vUp .setValues(0,1,0); 00117 _rDistance=(_pAt-_pFrom).length(); 00118 }
|
|
|
Definition at line 122 of file OSGTrackballNavigator.cpp.
|
|
|
Definition at line 86 of file OSGTrackballNavigator.h.
|
|
|
Get the current transformation matrix. Definition at line 130 of file OSGTrackballNavigator.cpp. References _finalMatrix, and updateFinalMatrix(). Referenced by osg::Navigator::calcDeltas(), osg::Navigator::getMatrix(), and osg::Navigator::updateCameraTransformation(). 00131 { 00132 updateFinalMatrix(); 00133 return _finalMatrix; 00134 }
|
|
|
Get the viewer position. The final matrix needs to be valid for this to work, if in doubt, call updateFinalMatrix() beforehand. Definition at line 140 of file OSGTrackballNavigator.cpp. References _finalMatrix, and _pFrom. Referenced by osg::Navigator::getFrom(), setAt(), and setUp(). 00141 { 00142 _pFrom = (Pnt3f)_finalMatrix[3]; 00143 return _pFrom; 00144 }
|
|
|
Get the target position. The final matrix needs to be valid for this to work, if in doubt, call updateFinalMatrix() beforehand. Definition at line 150 of file OSGTrackballNavigator.cpp. References _finalMatrix, _pAt, and _rDistance. Referenced by osg::Navigator::getAt(), setFrom(), and setUp(). 00151 { 00152 _pAt = (Pnt3f)(_finalMatrix[3] - (_rDistance*_finalMatrix[2])); 00153 return _pAt; 00154 }
|
|
|
Get the up direction. The final matrix needs to be valid for this to work, if in doubt, call updateFinalMatrix() beforehand. Definition at line 160 of file OSGTrackballNavigator.cpp. References _finalMatrix, and _vUp. Referenced by osg::Navigator::getUp(), setAt(), and setFrom(). 00161 { 00162 _vUp = (Vec3f)_finalMatrix[1]; 00163 return _vUp; 00164 }
|
|
|
Get the current transformation matrix. Definition at line 166 of file OSGTrackballNavigator.cpp. References _rDistance. Referenced by osg::Navigator::getDistance(). 00167 { 00168 return _rDistance; 00169 }
|
|
|
Sets the at point, the target point and center of the window. Definition at line 183 of file OSGTrackballNavigator.cpp. References getFrom(), getUp(), and set(). Referenced by osg::Navigator::buttonRelease(), and osg::Navigator::setAt().
|
|
|
Sets the from point, i.e. the viewer position. Definition at line 176 of file OSGTrackballNavigator.cpp. References getAt(), getUp(), and set(). Referenced by osg::Navigator::setFrom().
|
|
|
Sets the distance from the target point in the view direction. Definition at line 190 of file OSGTrackballNavigator.cpp. References _rDistance, and updateFinalMatrix(). Referenced by osg::Navigator::setDistance(). 00191 { 00192 _rDistance = new_distance; 00193 updateFinalMatrix(); 00194 }
|
|
|
Sets the up vector. Definition at line 198 of file OSGTrackballNavigator.cpp. References getAt(), getFrom(), and set(). Referenced by osg::Navigator::setUp().
|
|
||||||||||||||||
|
Set all viewer parameters of the navigator separately. Definition at line 205 of file OSGTrackballNavigator.cpp. References _rDistance, _tMatrix, FNOTICE, osg::MatrixLookAt(), and updateFinalMatrix(). Referenced by set(), osg::Navigator::set(), setAt(), setFrom(), and setUp(). 00206 { 00207 bool b = MatrixLookAt(_tMatrix, new_at, new_at+(new_at-new_from), new_up); 00208 if(!b) 00209 { 00210 _rDistance = (new_at - new_from).length(); 00211 updateFinalMatrix(); 00212 } 00213 else 00214 { 00215 FNOTICE(("TrackballNavigator: set(.,.,.), failed")); 00216 } 00217 }
|
|
|
Set all viewer parameters of the navigator with a single matrix. Definition at line 221 of file OSGTrackballNavigator.cpp. References _pAt, _pFrom, _rDistance, _vUp, and set(). 00222 { 00223 _pFrom = (Pnt3f) new_matrix[3]; 00224 _pAt = (Pnt3f)(new_matrix[3] - (_rDistance * new_matrix[2])); 00225 _vUp = (Vec3f) new_matrix[1]; 00226 set(_pFrom, _pAt, _vUp); 00227 }
|
|
||||||||||||||||||||
|
Rotate the trackball sphere for a mouse movement from fromX, fromY to toX, toY. Definition at line 234 of file OSGTrackballNavigator.cpp. References _rRadius, _tMatrix, osg::VectorInterface< ValueTypeT, StorageInterfaceT >::crossThis(), osg::Eps, osg::QuaternionBase< ValueTypeT >::getValue(), osg::VectorInterface< ValueTypeT, StorageInterfaceT >::length(), osg::TransformationMatrix< ValueTypeT >::mult(), osg::osgabs(), osg::osgasin(), osg::osgClamp(), projectToSphere(), osg::QuaternionBase< ValueTypeT >::setValueAsAxisRad(), and osg::VecStorage3< ValueTypeT >::setValues(). Referenced by osg::Navigator::moveTo(). 00235 { 00236 Quaternion qCurrVal; 00237 00238 Vec3f vAxis; 00239 Real32 rPhi; 00240 00241 Vec3f vP1, vP2, vDiff; 00242 00243 Real32 rTmp; 00244 00245 if(osgabs(fromX - toX) > Eps || osgabs(fromY - toY) > Eps) 00246 { 00247 vP1.setValues(fromX, fromY, projectToSphere(_rRadius, fromX, fromY)); 00248 vP2.setValues(toX, toY, projectToSphere(_rRadius, toX, toY)); 00249 00250 vAxis = vP2; 00251 vAxis.crossThis(vP1); 00252 00253 vDiff = vP1; 00254 vDiff -= vP2; 00255 00256 rTmp = osgClamp(-1.0f, vDiff.length() / (2.0f * _rRadius), 1.0f); 00257 00258 rPhi = 2.0f * osgasin(rTmp); 00259 qCurrVal.setValueAsAxisRad(vAxis, rPhi); 00260 00261 Matrix temp; 00262 qCurrVal.getValue(temp); 00263 00264 _tMatrix.mult(temp); 00265 } 00266 }
|
|
||||||||||||
|
Translate in the XY plane. Definition at line 270 of file OSGTrackballNavigator.cpp. References _tMatrix, osg::TransformationMatrix< ValueTypeT >::mult(), osg::TransformationMatrix< ValueTypeT >::setIdentity(), and osg::TransformationMatrix< ValueTypeT >::setTranslate(). Referenced by osg::Navigator::moveTo(). 00271 { 00272 Matrix temp; 00273 temp.setIdentity(); 00274 temp.setTranslate(distanceX,distanceY,0); 00275 _tMatrix.mult(temp); 00276 }
|
|
|
Translate along the Z-axis. Definition at line 281 of file OSGTrackballNavigator.cpp. References _rDistance. Referenced by osg::Navigator::buttonPress(), osg::Navigator::keyPress(), and osg::Navigator::moveTo(). 00282 { 00283 _rDistance+=distance; 00284 // don't navigate beyond the at point. 00285 //if(_rDistance < 0.0f) 00286 // _rDistance = 0.0f; 00287 }
|
|
|
Calculate the final matrix, the matrix that reflects the actual state of the TrackballNavigator. Definition at line 315 of file OSGTrackballNavigator.cpp. References _finalMatrix, _rDistance, _tMatrix, osg::TransformationMatrix< ValueTypeT >::mult(), osg::TransformationMatrix< ValueTypeT >::setIdentity(), and osg::TransformationMatrix< ValueTypeT >::setTranslate(). Referenced by getMatrix(), set(), and setDistance(). 00316 { 00317 Matrix temp; 00318 _finalMatrix=_tMatrix; 00319 temp.setIdentity(); 00320 temp.setTranslate(0,0,_rDistance); 00321 00322 _finalMatrix.mult(temp); 00323 }
|
|
||||||||||||||||
|
Project a point on the virtual trackball. If it is inside the sphere, map it to the sphere, if it outside map it to a hyperbola. Definition at line 293 of file OSGTrackballNavigator.cpp. Referenced by rotate(). 00294 { 00295 Real32 d, t, z; 00296 00297 d = sqrt(rX * rX + rY * rY); 00298 00299 if (d < rRadius * 0.70710678118654752440f) 00300 { /* Inside sphere */ 00301 z = sqrt(rRadius * rRadius - d * d); 00302 } 00303 else 00304 { /* On hyperbola */ 00305 t = rRadius / 1.41421356237309504880f; 00306 z = t * t / d; 00307 } 00308 00309 return z; 00310 }
|
|
|
The size of the trackball, relative to the screen size. Per default it is 0.8. Referenced by rotate(). |
|
|
The distance of the viewer from the target point. Referenced by getAt(), getDistance(), set(), setDistance(), TrackballNavigator(), translateZ(), and updateFinalMatrix(). |
|
|
Temporary matrix for calculation. Referenced by rotate(), set(), TrackballNavigator(), translateXY(), and updateFinalMatrix(). |
|
|
The resulting matrix for the final transformation. Referenced by getAt(), getFrom(), getMatrix(), getUp(), TrackballNavigator(), and updateFinalMatrix(). |
|
|
The current state of the trackball, whether it is currently rotating, translating in xy or in z. |
|
|
The viewer position. Referenced by getFrom(), set(), and TrackballNavigator(). |
|
|
The target position. Referenced by getAt(), set(), and TrackballNavigator(). |
|
|
The Up direction. Referenced by getUp(), set(), and TrackballNavigator(). |
1.4.3