Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

osg::Trackball Class Reference

Trackball class. Deprecated, use the TrackballNavigator instead. More...

#include <OSGTrackball.h>

List of all members.

Public Types

enum  TranslationGen { OSGOrientedTranslation = 0x01, OSGAbsoluteTranslation = 0x02 }
enum  Mode { OSGCamera = 0x01, OSGObject = 0x02 }
enum  TranslationMode { OSGFixedX, OSGFixedY, OSGFixedZ, OSGFree }

Public Member Functions

const char * getClassname (void)
 Trackball (Real32 rSize=1.0)
 ~Trackball (void)
void setSum (bool bVal)
void updateRotation (Real32 rLastX, Real32 rLastY, Real32 rCurrentX, Real32 rCurrentY)
void updatePosition (Real32 rLastX, Real32 rLastY, Real32 rCurrentX, Real32 rCurrentY)
void updatePositionNeg (Real32 rLastX, Real32 rLastY, Real32 rCurrentX, Real32 rCurrentY)
void setAutoPositionIncrement (Real32 rVal)
void setAutoPosition (bool bVal)
void setAutoPositionNeg (bool bVal)
void setMode (Mode gMode)
void setTranslationMode (TranslationMode gMode)
void setTranslationScale (Real32 rTranslationScale)
void setTranslationGen (TranslationGen gMode)
void reset (void)
void setStartPosition (Real32 rX, Real32 rY, Real32 rZ, bool bUpdate=false)
void setStartPosition (Vec3f &gStartPos, bool bUpdate=false)
Vec3fgetPosition (void)
void setStartRotation (Real32 rX, Real32 rY, Real32 rZ, Real32 rW, bool bUpdate=false)
void setStartRotation (Quaternion &gStartRot, bool bUpdate=false)
void setRotationCenter (const Pnt3f &pRotationCenter)
QuaterniongetRotation (void)
MatrixgetFullExamineMatrix (void)
MatrixgetFullTrackballMatrix (void)
void setSize (Real32 s)
Real32 getSize (void) const

Protected Member Functions

float projectToSphere (Real32 rRadius, Real32 rX, Real32 rY)

Private Member Functions

 Trackball (const Trackball &org)
void operator= (const Trackball &org)

Private Attributes

bool _bSum
bool _bAutoPosition
Mode _gMode
TranslationMode _gTransMode
TranslationGen _gTransGen
Real32 _rAutoPositionStep
Real32 _rAutoPositionIncrement
Real32 _rTrackballSize
Real32 _rTranslationScale
Quaternion _qVal
Vec3f _pVal
Quaternion _qValStart
Vec3f _pValStart
Pnt3f _pRotationCenter
Matrix _fullMatrix


Detailed Description

The old Trackball class. Use is deprecated, use the TrackballNavigator instead, it's a lot easier to use.

Definition at line 52 of file OSGTrackball.h.


Member Enumeration Documentation

enum osg::Trackball::TranslationGen
 

Enumerator:
OSGOrientedTranslation 
OSGAbsoluteTranslation 

Definition at line 56 of file OSGTrackball.h.

00057     {
00058         OSGOrientedTranslation = 0x01,
00059         OSGAbsoluteTranslation = 0x02
00060     };

enum osg::Trackball::Mode
 

Enumerator:
OSGCamera 
OSGObject 

Definition at line 62 of file OSGTrackball.h.

00063     {
00064         OSGCamera = 0x01,
00065         OSGObject = 0x02
00066     };

enum osg::Trackball::TranslationMode
 

Enumerator:
OSGFixedX 
OSGFixedY 
OSGFixedZ 
OSGFree 

Definition at line 68 of file OSGTrackball.h.

00069     {
00070         OSGFixedX,
00071         OSGFixedY,
00072         OSGFixedZ,        
00073 
00074         OSGFree
00075     };


Constructor & Destructor Documentation

Trackball::Trackball Real32  rSize = 1.0  ) 
 

Definition at line 58 of file OSGTrackball.cpp.

00058                                  :
00059     _bSum(false),
00060     _bAutoPosition(false),
00061     _gMode(OSGCamera),
00062     _gTransMode(OSGFixedZ),
00063     _gTransGen (OSGAbsoluteTranslation),
00064     _rAutoPositionStep(1.),
00065     _rAutoPositionIncrement(1.),
00066     _rTrackballSize(rSize),
00067     _rTranslationScale(1.),
00068     _qVal(),
00069     _pVal(),
00070     _qValStart(),
00071     _pValStart(),
00072     _pRotationCenter()
00073 {
00074 }

Trackball::~Trackball void   ) 
 

Definition at line 76 of file OSGTrackball.cpp.

00077 {
00078 }

osg::Trackball::Trackball const Trackball org  )  [private]
 


Member Function Documentation

const char* osg::Trackball::getClassname void   )  [inline]
 

Definition at line 78 of file OSGTrackball.h.

00078 { return "Trackball"; }

void Trackball::setSum bool  bVal  ) 
 

Definition at line 109 of file OSGTrackball.cpp.

References _bSum.

00110 {
00111     _bSum = bVal;
00112 }

void Trackball::updateRotation Real32  rLastX,
Real32  rLastY,
Real32  rCurrentX,
Real32  rCurrentY
 

Definition at line 114 of file OSGTrackball.cpp.

References _bSum, _gMode, _qVal, _rTrackballSize, osg::VectorInterface< ValueTypeT, StorageInterfaceT >::crossThis(), osg::Eps, osg::VectorInterface< ValueTypeT, StorageInterfaceT >::length(), osg::osgabs(), osg::osgasin(), OSGObject, projectToSphere(), osg::QuaternionBase< ValueTypeT >::setValueAsAxisRad(), and osg::VecStorage3< ValueTypeT >::setValues().

00116 {
00117     Quaternion qCurrVal;
00118 
00119     Vec3f gAxis; /* Axis of rotation */
00120     Real32    rPhi = 0;  /* how much to rotate about axis */
00121     Vec3f gP1;
00122     Vec3f gP2;
00123     Vec3f gDiff;
00124     Real32    rTmp;
00125 
00126     if( (osgabs(rLastX - rCurrentX) > Eps) ||
00127         (osgabs(rLastY - rCurrentY) > Eps))
00128     {
00129         /*
00130          * First, figure out z-coordinates for projection of P1 and P2 to
00131          * deformed sphere
00132          */
00133         
00134         gP1.setValues(  rLastX,
00135                         rLastY,
00136                          projectToSphere(_rTrackballSize, rLastX, rLastY));
00137 
00138         gP2.setValues(  rCurrentX,
00139                         rCurrentY,
00140                         projectToSphere(_rTrackballSize, rCurrentX, rCurrentY));
00141         
00142         /*
00143          *  Now, we want the cross product of P1 and P2
00144          */
00145 
00146         gAxis = gP2;
00147         gAxis.crossThis(gP1);
00148 
00149         /*
00150          *  Figure out how much to rotate around that axis.
00151          */
00152 
00153         gDiff = gP2;
00154         gDiff -= gP1;
00155 
00156         rTmp = gDiff.length() / (2.0f * _rTrackballSize);
00157 
00158 
00159         /*
00160          * Avoid problems with out-of-control values...
00161          */
00162         
00163         if(rTmp > 1.0) 
00164             rTmp = 1.0;
00165 
00166         if(rTmp < -1.0) 
00167             rTmp = -1.0;
00168 
00169         if(_gMode == OSGObject)
00170             rPhi = (Real32) -2.0 * osgasin(rTmp);
00171         else
00172             rPhi = (Real32)  2.0 * osgasin(rTmp);
00173 
00174     }
00175 
00176     if(_bSum == false)
00177     {
00178         _qVal.setValueAsAxisRad(gAxis, rPhi);
00179     }
00180     else
00181     {
00182         qCurrVal.setValueAsAxisRad(gAxis, rPhi);
00183         _qVal *= qCurrVal;
00184 //        _qVal.multLeft(qCurrVal);
00185     }
00186 }

void Trackball::updatePosition Real32  rLastX,
Real32  rLastY,
Real32  rCurrentX,
Real32  rCurrentY
 

Definition at line 188 of file OSGTrackball.cpp.

References _gTransGen, _gTransMode, _pVal, _rTranslationScale, getRotation(), osg::TransformationMatrix< ValueTypeT >::mult(), OSGAbsoluteTranslation, OSGFree, and osg::TransformationMatrix< ValueTypeT >::setRotate().

00190 {
00191     if(_gTransMode == OSGFree)
00192     {
00193         if(_gTransGen == OSGAbsoluteTranslation)
00194         {
00195             _pVal[0] += (rLastX - rCurrentX) * -_rTranslationScale;
00196             _pVal[1] += (rLastY - rCurrentY) * -_rTranslationScale;
00197         }
00198         else
00199         {
00200             Vec3f tmpVec((rLastX - rCurrentX) * -_rTranslationScale,
00201                          (rLastY - rCurrentY) * -_rTranslationScale,
00202                          0.);
00203                 
00204             Matrix m1;
00205 
00206             m1.setRotate(getRotation());
00207 
00208             m1.mult(tmpVec);
00209 
00210             _pVal[0] += tmpVec[0];
00211             _pVal[1] += tmpVec[1];
00212             _pVal[2] += tmpVec[2];
00213         }
00214     }   
00215 }

void Trackball::updatePositionNeg Real32  rLastX,
Real32  rLastY,
Real32  rCurrentX,
Real32  rCurrentY
 

Definition at line 217 of file OSGTrackball.cpp.

References _gTransGen, _gTransMode, _pVal, _rTranslationScale, getRotation(), osg::TransformationMatrix< ValueTypeT >::mult(), OSGAbsoluteTranslation, OSGFree, and osg::TransformationMatrix< ValueTypeT >::setRotate().

00219 {
00220     if(_gTransMode == OSGFree)
00221     {
00222         if(_gTransGen == OSGAbsoluteTranslation)
00223         {
00224             _pVal[2] += (rLastY - rCurrentY) * -_rTranslationScale;
00225         }
00226         else
00227         {
00228             Vec3f tmpVec(0.,
00229                          0.,
00230                          (rLastY - rCurrentY) * -_rTranslationScale);
00231             
00232             Matrix m1;
00233             
00234             m1.setRotate(getRotation());
00235 
00236             m1.mult(tmpVec);
00237 
00238             _pVal[0] += tmpVec[0];
00239             _pVal[1] += tmpVec[1];
00240             _pVal[2] += tmpVec[2];
00241         }
00242     }
00243 }

void Trackball::setAutoPositionIncrement Real32  rVal  ) 
 

Definition at line 245 of file OSGTrackball.cpp.

References _rAutoPositionIncrement.

00246 {
00247     _rAutoPositionIncrement = rVal;
00248 }

void Trackball::setAutoPosition bool  bVal  ) 
 

Definition at line 250 of file OSGTrackball.cpp.

References _bAutoPosition, _rAutoPositionIncrement, and _rAutoPositionStep.

00251 {
00252     _bAutoPosition = bVal;
00253     _rAutoPositionStep = -_rAutoPositionIncrement;
00254 }

void Trackball::setAutoPositionNeg bool  bVal  ) 
 

Definition at line 256 of file OSGTrackball.cpp.

References _bAutoPosition, _rAutoPositionIncrement, and _rAutoPositionStep.

00257 {
00258     _bAutoPosition = bVal;
00259     _rAutoPositionStep = _rAutoPositionIncrement;
00260 }

void Trackball::setMode Mode  gMode  ) 
 

Definition at line 262 of file OSGTrackball.cpp.

References _gMode.

00263 {
00264     _gMode = gMode;
00265 }

void Trackball::setTranslationMode TranslationMode  gMode  ) 
 

Definition at line 267 of file OSGTrackball.cpp.

References _gTransMode.

00268 {
00269     _gTransMode = gMode;
00270 }

void Trackball::setTranslationScale Real32  rTranslationScale  ) 
 

Definition at line 272 of file OSGTrackball.cpp.

References _rTranslationScale.

00273 {
00274     _rTranslationScale = rTranslationScale;
00275 }

void Trackball::setTranslationGen TranslationGen  gMode  ) 
 

Definition at line 277 of file OSGTrackball.cpp.

References _gTransGen, _pVal, getFullTrackballMatrix(), OSGAbsoluteTranslation, and OSGOrientedTranslation.

00278 {
00279     if(_gTransGen == OSGAbsoluteTranslation && 
00280         gMode     == OSGOrientedTranslation)
00281     {
00282         Matrix tmpMat = getFullTrackballMatrix();
00283 
00284         _pVal[0] = tmpMat[3][0];
00285         _pVal[1] = tmpMat[3][1];
00286         _pVal[2] = tmpMat[3][2];
00287     }
00288 
00289     _gTransGen = gMode;
00290 }

void Trackball::reset void   ) 
 

Definition at line 292 of file OSGTrackball.cpp.

References _pVal, _pValStart, _qVal, and _qValStart.

00293 {
00294     _qVal = _qValStart;
00295     _pVal = _pValStart;
00296 }

void Trackball::setStartPosition Real32  rX,
Real32  rY,
Real32  rZ,
bool  bUpdate = false
 

Definition at line 298 of file OSGTrackball.cpp.

References _pVal, _pValStart, and osg::VecStorage3< ValueTypeT >::setValues().

00300 {
00301     _pValStart.setValues(rX, rY, rZ);
00302     
00303     if(bUpdate == true)
00304         _pVal = _pValStart;
00305 }

void Trackball::setStartPosition Vec3f gStartPos,
bool  bUpdate = false
 

Definition at line 307 of file OSGTrackball.cpp.

References _pVal, and _pValStart.

00308 {
00309     _pValStart = gStartPos;
00310     
00311     if(bUpdate == true)
00312         _pVal = _pValStart;
00313 }

Vec3f & Trackball::getPosition void   ) 
 

Definition at line 315 of file OSGTrackball.cpp.

References _bAutoPosition, _gTransMode, _pVal, _rAutoPositionStep, OSGFixedX, OSGFixedY, and OSGFixedZ.

Referenced by getFullExamineMatrix(), and getFullTrackballMatrix().

00316 {
00317     /*
00318     if(_bAutoPosition == true)
00319         _pVal[2] += _rAutoPositionStep;
00320 
00321     return _pVal;
00322     */    
00323     if(_bAutoPosition == true)
00324     {
00325         switch(_gTransMode)
00326         {
00327             case OSGFixedX:
00328                 _pVal[0] += _rAutoPositionStep;
00329                 break;
00330                 
00331             case OSGFixedY:
00332                 _pVal[1] += _rAutoPositionStep;
00333                 break;
00334                 
00335             case OSGFixedZ:
00336                 _pVal[2] += _rAutoPositionStep;
00337                 break;
00338                 
00339             default:
00340                 break;
00341         }
00342     }
00343 
00344     return _pVal;
00345 }

void Trackball::setStartRotation Real32  rX,
Real32  rY,
Real32  rZ,
Real32  rW,
bool  bUpdate = false
 

Definition at line 347 of file OSGTrackball.cpp.

References _qVal, _qValStart, and osg::QuaternionBase< ValueTypeT >::setValueAsAxisDeg().

00349 {
00350     _qValStart.setValueAsAxisDeg(rX, rY, rZ, rW);
00351 
00352     if(bUpdate == true)
00353         _qVal = _qValStart;
00354 }

void Trackball::setStartRotation Quaternion gStartRot,
bool  bUpdate = false
 

Definition at line 356 of file OSGTrackball.cpp.

References _qVal, and _qValStart.

00357 {
00358     _qValStart = gStartRot;
00359 
00360     if(bUpdate == true)
00361         _qVal = _qValStart;
00362 }

void Trackball::setRotationCenter const Pnt3f pRotationCenter  ) 
 

Definition at line 364 of file OSGTrackball.cpp.

References _pRotationCenter.

00365 {
00366     _pRotationCenter = pRotationCenter;
00367 }

Quaternion & Trackball::getRotation void   ) 
 

Definition at line 369 of file OSGTrackball.cpp.

References _qVal.

Referenced by getFullExamineMatrix(), getFullTrackballMatrix(), updatePosition(), and updatePositionNeg().

00370 {
00371     return _qVal;
00372 }

Matrix & Trackball::getFullExamineMatrix void   ) 
 

Definition at line 374 of file OSGTrackball.cpp.

References _fullMatrix, _pVal, getPosition(), getRotation(), osg::TransformationMatrix< ValueTypeT >::mult(), and osg::TransformationMatrix< ValueTypeT >::setIdentity().

00375 {
00376     OSG::Matrix m1;
00377 
00378     _fullMatrix.setIdentity();
00379 
00380     _fullMatrix[3][0] = _pVal[0];
00381     _fullMatrix[3][1] = _pVal[1];
00382     _fullMatrix[3][2] = _pVal[2];
00383     
00384     m1.setRotate    (getRotation());
00385     _fullMatrix.mult(m1);
00386 
00387     m1.setIdentity ();
00388     m1.setTranslate(getPosition());
00389         
00390     _fullMatrix.mult(m1);
00391 
00392     m1.setIdentity();
00393 
00394     m1[3][0] = -_pVal[0];
00395     m1[3][1] = -_pVal[1];
00396     m1[3][2] = -_pVal[2];
00397 
00398     _fullMatrix.mult(m1);
00399 
00400     return _fullMatrix;
00401 }

Matrix & Trackball::getFullTrackballMatrix void   ) 
 

Definition at line 403 of file OSGTrackball.cpp.

References _fullMatrix, _pRotationCenter, getPosition(), getRotation(), osg::TransformationMatrix< ValueTypeT >::mult(), and osg::TransformationMatrix< ValueTypeT >::setIdentity().

Referenced by setTranslationGen().

00404 {
00405     OSG::Matrix m1;
00406 
00407     _fullMatrix.setIdentity();
00408 
00409     _fullMatrix[3][0] = _pRotationCenter[0];
00410     _fullMatrix[3][1] = _pRotationCenter[1];
00411     _fullMatrix[3][2] = _pRotationCenter[2];
00412     
00413     m1.setRotate    (getRotation());
00414     _fullMatrix.mult(m1);
00415 
00416     m1.setIdentity ();
00417     m1.setTranslate(getPosition());
00418         
00419     _fullMatrix.mult(m1);
00420 
00421     m1.setIdentity();
00422 
00423     m1[3][0] = -_pRotationCenter[0];
00424     m1[3][1] = -_pRotationCenter[1];
00425     m1[3][2] = -_pRotationCenter[2];
00426 
00427     _fullMatrix.mult(m1);
00428 
00429     return _fullMatrix;
00430 }

void Trackball::setSize Real32  s  ) 
 

Definition at line 80 of file OSGTrackball.cpp.

References _rTrackballSize.

00081 {
00082     _rTrackballSize = s;
00083 }

Real32 Trackball::getSize void   )  const
 

Definition at line 85 of file OSGTrackball.cpp.

References _rTrackballSize.

00086 {
00087     return _rTrackballSize;
00088 }

void osg::Trackball::operator= const Trackball org  )  [private]
 

Real32 Trackball::projectToSphere Real32  rRadius,
Real32  rX,
Real32  rY
[protected]
 

Definition at line 90 of file OSGTrackball.cpp.

Referenced by updateRotation().

00091 {
00092     Real32 d, t, z;
00093 
00094     d = sqrt(rX * rX + rY * rY);
00095 
00096     if (d < rRadius * 0.70710678118654752440f) 
00097     {    /* Inside sphere */
00098         z = sqrt(rRadius * rRadius - d * d);
00099     } 
00100     else 
00101     {           /* On hyperbola */
00102         t = rRadius / 1.41421356237309504880f;
00103         z = t * t / d;
00104     }
00105 
00106     return z;
00107 }


Member Data Documentation

bool osg::Trackball::_bSum [private]
 

Definition at line 126 of file OSGTrackball.h.

Referenced by setSum(), and updateRotation().

bool osg::Trackball::_bAutoPosition [private]
 

Definition at line 127 of file OSGTrackball.h.

Referenced by getPosition(), setAutoPosition(), and setAutoPositionNeg().

Mode osg::Trackball::_gMode [private]
 

Definition at line 129 of file OSGTrackball.h.

Referenced by setMode(), and updateRotation().

TranslationMode osg::Trackball::_gTransMode [private]
 

Definition at line 130 of file OSGTrackball.h.

Referenced by getPosition(), setTranslationMode(), updatePosition(), and updatePositionNeg().

TranslationGen osg::Trackball::_gTransGen [private]
 

Definition at line 131 of file OSGTrackball.h.

Referenced by setTranslationGen(), updatePosition(), and updatePositionNeg().

Real32 osg::Trackball::_rAutoPositionStep [private]
 

Definition at line 133 of file OSGTrackball.h.

Referenced by getPosition(), setAutoPosition(), and setAutoPositionNeg().

Real32 osg::Trackball::_rAutoPositionIncrement [private]
 

Definition at line 134 of file OSGTrackball.h.

Referenced by setAutoPosition(), setAutoPositionIncrement(), and setAutoPositionNeg().

Real32 osg::Trackball::_rTrackballSize [private]
 

Definition at line 136 of file OSGTrackball.h.

Referenced by getSize(), setSize(), and updateRotation().

Real32 osg::Trackball::_rTranslationScale [private]
 

Definition at line 137 of file OSGTrackball.h.

Referenced by setTranslationScale(), updatePosition(), and updatePositionNeg().

Quaternion osg::Trackball::_qVal [private]
 

Definition at line 139 of file OSGTrackball.h.

Referenced by getRotation(), reset(), setStartRotation(), and updateRotation().

Vec3f osg::Trackball::_pVal [private]
 

Definition at line 140 of file OSGTrackball.h.

Referenced by getFullExamineMatrix(), getPosition(), reset(), setStartPosition(), setTranslationGen(), updatePosition(), and updatePositionNeg().

Quaternion osg::Trackball::_qValStart [private]
 

Definition at line 142 of file OSGTrackball.h.

Referenced by reset(), and setStartRotation().

Vec3f osg::Trackball::_pValStart [private]
 

Definition at line 143 of file OSGTrackball.h.

Referenced by reset(), and setStartPosition().

Pnt3f osg::Trackball::_pRotationCenter [private]
 

Definition at line 145 of file OSGTrackball.h.

Referenced by getFullTrackballMatrix(), and setRotationCenter().

Matrix osg::Trackball::_fullMatrix [private]
 

Definition at line 147 of file OSGTrackball.h.

Referenced by getFullExamineMatrix(), and getFullTrackballMatrix().


The documentation for this class was generated from the following files:
Generated on Thu Aug 25 04:27:30 2005 for OpenSG by  doxygen 1.4.3