#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 |
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 };
| TrackballNavigator::TrackballNavigator | ( | Real32 | rSize = 0.8 |
) |
Definition at line 110 of file OSGTrackballNavigator.cpp.
References _finalMatrix, _pAt, _pFrom, _rDistance, _tMatrix, _vUp, and osg::TransformationMatrix< ValueTypeT >::setIdentity().
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 }
| TrackballNavigator::~TrackballNavigator | ( | ) |
| const char* osg::TrackballNavigator::getClassname | ( | void | ) | [inline] |
| Matrix & TrackballNavigator::getMatrix | ( | void | ) |
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 }
| Pnt3f & TrackballNavigator::getFrom | ( | void | ) |
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 }
| Pnt3f & TrackballNavigator::getAt | ( | void | ) |
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 }
| Vec3f & TrackballNavigator::getUp | ( | void | ) |
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 }
| Real32 TrackballNavigator::getDistance | ( | void | ) |
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 }
| void TrackballNavigator::setAt | ( | Pnt3f | new_at | ) |
Sets the at point, the target point and center of the window.
Definition at line 183 of file OSGTrackballNavigator.cpp.
References getFrom(), and getUp().
Referenced by osg::Navigator::buttonRelease(), and osg::Navigator::setAt().
| void TrackballNavigator::setFrom | ( | Pnt3f | new_from | ) |
Sets the from point, i.e. the viewer position.
Definition at line 176 of file OSGTrackballNavigator.cpp.
References getAt(), and getUp().
Referenced by osg::Navigator::setFrom().
| void TrackballNavigator::setDistance | ( | Real32 | new_distance | ) |
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 }
| void TrackballNavigator::setUp | ( | Vec3f | new_up | ) |
Sets the up vector.
Definition at line 198 of file OSGTrackballNavigator.cpp.
References getAt(), and getFrom().
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 osg::Navigator::set().
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 }
| void TrackballNavigator::set | ( | Matrix | new_matrix | ) |
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 osg::VectorInterface< ValueTypeT, StorageInterfaceT >::length().
00222 { 00223 // get distance 00224 Vec3f translation( new_matrix[3][0], new_matrix[3][1], new_matrix[3][2] ); 00225 _rDistance = translation.length(); 00226 00227 _pFrom = (Pnt3f) new_matrix[3]; 00228 _pAt = (Pnt3f)(new_matrix[3] - (_rDistance * new_matrix[2])); 00229 _vUp = (Vec3f) new_matrix[1]; 00230 set(_pFrom, _pAt, _vUp); 00231 }
Rotate the trackball sphere for a mouse movement from fromX, fromY to toX, toY.
Definition at line 238 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(), and osg::QuaternionBase< ValueTypeT >::setValueAsAxisRad().
Referenced by osg::Navigator::moveTo().
00239 { 00240 Quaternion qCurrVal; 00241 00242 Vec3f vAxis; 00243 Real32 rPhi; 00244 00245 Vec3f vP1, vP2, vDiff; 00246 00247 Real32 rTmp; 00248 00249 if(osgabs(fromX - toX) > Eps || osgabs(fromY - toY) > Eps) 00250 { 00251 vP1.setValues(fromX, fromY, projectToSphere(_rRadius, fromX, fromY)); 00252 vP2.setValues(toX, toY, projectToSphere(_rRadius, toX, toY)); 00253 00254 vAxis = vP2; 00255 vAxis.crossThis(vP1); 00256 00257 vDiff = vP1; 00258 vDiff -= vP2; 00259 00260 rTmp = osgClamp(-1.0f, vDiff.length() / (2.0f * _rRadius), 1.0f); 00261 00262 rPhi = 2.0f * osgasin(rTmp); 00263 qCurrVal.setValueAsAxisRad(vAxis, rPhi); 00264 00265 Matrix temp; 00266 qCurrVal.getValue(temp); 00267 00268 _tMatrix.mult(temp); 00269 } 00270 }
Translate in the XY plane.
Definition at line 274 of file OSGTrackballNavigator.cpp.
References _tMatrix, osg::TransformationMatrix< ValueTypeT >::mult(), osg::TransformationMatrix< ValueTypeT >::setIdentity(), and osg::TransformationMatrix< ValueTypeT >::setTranslate().
Referenced by osg::Navigator::moveTo().
00275 { 00276 Matrix temp; 00277 temp.setIdentity(); 00278 temp.setTranslate(distanceX,distanceY,0); 00279 _tMatrix.mult(temp); 00280 }
| void TrackballNavigator::translateZ | ( | Real32 | distance | ) |
Translate along the Z-axis.
Definition at line 285 of file OSGTrackballNavigator.cpp.
References _rDistance.
Referenced by osg::Navigator::buttonPress(), osg::Navigator::keyPress(), and osg::Navigator::moveTo().
00286 { 00287 _rDistance+=distance; 00288 // don't navigate beyond the at point. 00289 //if(_rDistance < 0.0f) 00290 // _rDistance = 0.0f; 00291 }
| void TrackballNavigator::updateFinalMatrix | ( | ) | [private] |
Calculate the final matrix, the matrix that reflects the actual state of the TrackballNavigator.
Definition at line 319 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().
00320 { 00321 Matrix temp; 00322 _finalMatrix=_tMatrix; 00323 temp.setIdentity(); 00324 temp.setTranslate(0,0,_rDistance); 00325 00326 _finalMatrix.mult(temp); 00327 }
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 297 of file OSGTrackballNavigator.cpp.
Referenced by rotate().
00298 { 00299 Real32 d, t, z; 00300 00301 d = sqrt(rX * rX + rY * rY); 00302 00303 if (d < rRadius * 0.70710678118654752440f) 00304 { /* Inside sphere */ 00305 z = sqrt(rRadius * rRadius - d * d); 00306 } 00307 else 00308 { /* On hyperbola */ 00309 t = rRadius / 1.41421356237309504880f; 00310 z = t * t / d; 00311 } 00312 00313 return z; 00314 }
Real32 TrackballNavigator::_rRadius [private] |
The size of the trackball, relative to the screen size. Per default it is 0.8.
Definition at line 129 of file OSGTrackballNavigator.h.
Referenced by rotate().
Real32 TrackballNavigator::_rDistance [private] |
The distance of the viewer from the target point.
Definition at line 129 of file OSGTrackballNavigator.h.
Referenced by getAt(), getDistance(), set(), setDistance(), TrackballNavigator(), translateZ(), and updateFinalMatrix().
Matrix TrackballNavigator::_tMatrix [private] |
Temporary matrix for calculation.
Definition at line 130 of file OSGTrackballNavigator.h.
Referenced by rotate(), set(), TrackballNavigator(), translateXY(), and updateFinalMatrix().
Matrix TrackballNavigator::_finalMatrix [private] |
The resulting matrix for the final transformation.
Definition at line 130 of file OSGTrackballNavigator.h.
Referenced by getAt(), getFrom(), getMatrix(), getUp(), TrackballNavigator(), and updateFinalMatrix().
State TrackballNavigator::_currentState [private] |
The current state of the trackball, whether it is currently rotating, translating in xy or in z.
Definition at line 131 of file OSGTrackballNavigator.h.
Pnt3f TrackballNavigator::_pFrom [private] |
The viewer position.
Definition at line 132 of file OSGTrackballNavigator.h.
Referenced by getFrom(), set(), and TrackballNavigator().
Pnt3f TrackballNavigator::_pAt [private] |
The target position.
Definition at line 132 of file OSGTrackballNavigator.h.
Referenced by getAt(), set(), and TrackballNavigator().
Vec3f TrackballNavigator::_vUp [private] |
The Up direction.
Definition at line 133 of file OSGTrackballNavigator.h.
Referenced by getUp(), set(), and TrackballNavigator().
1.5.5