HapticManager< T > Class Template Reference

#include <TAPsHapticManager.hpp>

Inheritance diagram for HapticManager< T >:

Inheritance graph
[legend]
Collaboration diagram for HapticManager< T >:

Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual void Cleanup ()
virtual void Cleanup ()
virtual void DrawCursor (OpenGL::Enum::DrawMode DM=OpenGL::Enum::POLYGON)
virtual void DrawCursor ()
virtual void DrawHapticObjects (OpenGL::Enum::DrawMode DM=OpenGL::Enum::POLYGON)
virtual void DrawTooltipSphere (OpenGL::Enum::DrawMode DM=OpenGL::Enum::POLYGON)
virtual void FeelObjects (OpenGL::Enum::DrawMode DM=OpenGL::Enum::POLYGON)
virtual void FeelPoints ()
virtual void FeelPoints ()
 HapticManager (const char *toolOneFileName)
 HapticManager ()
 HapticManager ()
virtual bool IsManipulating () const
virtual bool IsManipulating () const
virtual void Setup (TAPs::OpenGL::BaseModelManager< T > *pModelManager, TAPs::OpenGL::BaseOpenGLViewManager< T > *pViewManager)
virtual void Setup (TAPs::OpenGL::BasePointManager< T > *pPointManager, TAPs::OpenGL::OpenGLBaseViewManager< T > *pViewManager)
virtual void UpdateWorkSpace ()
virtual void UpdateWorkSpace ()
virtual ~HapticManager ()
virtual ~HapticManager ()

Protected Member Functions

int GetPointIndexFromTouchID (HLuint id) const
int GetPointIndexFromTouchID (HLuint id) const
void InitCursor (const char *toolOneFile)
void InitCursor ()
void InitHapticData ()
void PopWorkSpaceOffset ()
void PopWorkSpaceOffset ()
void PushWorkSpaceOffset (const TAPs::Vector3< T > &offsetWC)
void PushWorkSpaceOffset (const TAPs::Vector3< T > &offsetWC)
void StartManipulating (int i)
void StartManipulating (int i)
void StopManipulating ()
void StopManipulating ()
void UpdateManipPoint (const TAPs::Vector3< T > &proxyPos, const TAPs::Matrix4x4< T > &proxyTransform)
void UpdateManipPoint (const TAPs::Vector3< T > &proxyPos)

Static Protected Member Functions

static void HLCALLBACK hlButtonDownCB (HLenum event, HLuint object, HLenum thread, HLcache *cache, void *userData)
static void HLCALLBACK hlButtonDownCB (HLenum event, HLuint object, HLenum thread, HLcache *cache, void *userData)
static void HLCALLBACK hlButtonUpCB (HLenum event, HLuint object, HLenum thread, HLcache *cache, void *userData)
static void HLCALLBACK hlButtonUpCB (HLenum event, HLuint object, HLenum thread, HLcache *cache, void *userData)
static void HLCALLBACK hlMotionCB (HLenum event, HLuint object, HLenum thread, HLcache *cache, void *userData)
static void HLCALLBACK hlMotionCB (HLenum event, HLuint object, HLenum thread, HLcache *cache, void *userData)
static void HLCALLBACK hlTouchCB (HLenum event, HLuint object, HLenum thread, HLcache *cache, void *userData)
static void HLCALLBACK hlTouchCB (HLenum event, HLuint object, HLenum thread, HLcache *cache, void *userData)

Protected Attributes

bool m_bHapticAxisSnapOn
bool m_bHapticRotateOn
HHD m_hHD
HHLRC m_hHLRC
int m_iManipPoint
TAPs::OpenGL::BaseModelManager
< T > * 
m_pModelManager
TAPs::OpenGL::BasePointManager
< T > * 
m_pPointManager
TAPs::OpenGL::BaseOpenGLViewManager
< T > * 
m_pViewManager
TAPs::OpenGL::OpenGLBaseViewManager
< T > * 
m_pViewManager
m_tCursorScale
GLuint m_uiCursorDisplayList
HLuint m_uiEffectName
HLuint m_uiPointNameBase
TAPs::Matrix3x3< T > startDragProxyRotation
TAPs::Matrix4x4< T > startDragProxyTransform

Static Protected Attributes

static T g_tSnapDistance = g_tSnapDistanceConst
static const T g_tSnapDistanceConst = 2.0


Detailed Description

template<typename T>
class HapticManager< T >

Definition at line 19 of file TAPsHapticManager.hpp.


Constructor & Destructor Documentation

template<typename T>
HapticManager< T >::HapticManager (  )  [inline]

Definition at line 27 of file TAPsHapticManager.cpp.

00028     : BaseHapticManager<T>(),
00029       m_pPointManager( NULL ),
00030       m_pViewManager( NULL ),
00031       m_iManipPoint( -1 ),
00032       m_uiPointNameBase( 0 ),
00033       m_uiEffectName( 0 ),
00034       m_tCursorScale( 1.0 ),
00035       m_uiCursorDisplayList( 0 ),
00036       m_hHD( HD_INVALID_HANDLE ),
00037       m_hHLRC( NULL )
00038 {}

template<typename T>
HapticManager< T >::~HapticManager (  )  [inline, virtual]

Definition at line 42 of file TAPsHapticManager.cpp.

00043 {}

template<typename T>
HapticManager< T >::HapticManager (  ) 

template<typename T>
HapticManager< T >::HapticManager ( const char *  toolOneFileName  )  [inline]

Definition at line 50 of file TAPsHapticManager.cpp.

00051     : BaseHapticManager<T>(),
00052       m_pModelManager( NULL ),
00053       m_pViewManager( NULL ),
00054       m_iManipPoint( -1 ), 
00055       m_uiPointNameBase( 0 ),
00056       m_uiEffectName( 0 ),
00057       m_tCursorScale( 1.0 ),
00058       m_uiCursorDisplayList( 0 ),
00059       m_hHD( HD_INVALID_HANDLE ),
00060       m_hHLRC( NULL )
00061 {
00062     m_uiHapticObjects = 0;
00063     InitHapticData();
00064     InitCursor( toolOneFileName );
00065 }

template<typename T>
virtual HapticManager< T >::~HapticManager (  )  [virtual]


Member Function Documentation

template<typename T>
virtual void HapticManager< T >::Cleanup (  )  [virtual]

template<typename T>
void HapticManager< T >::Cleanup (  )  [inline, virtual]

Implements BaseHapticManager< T >.

Definition at line 102 of file TAPsHapticManager.cpp.

00103 {
00104     if ( m_hHLRC != NULL ) {
00105         assert( m_pPointManager );
00106         //hlBeginFrame();
00107         //  hlStopEffect( m_uiEffectName );
00108         //hlEndFrame();
00109         //------------------------------------------------------
00110         //hlDeleteEffects( m_uiEffectName, 1 );
00111         int iNumPoints = m_pPointManager->GetNumPoints();
00112         for ( int i = 0; i < iNumPoints; ++i ) {
00113             // Unregister event callbacks for all of the points
00114             HLuint uiPointName = m_uiPointNameBase + i;
00115             hlRemoveEventCallback(  HL_EVENT_TOUCH, uiPointName,
00116                                     HL_CLIENT_THREAD, hlTouchCB );
00117             hlRemoveEventCallback(  HL_EVENT_UNTOUCH, uiPointName,
00118                                     HL_CLIENT_THREAD, hlTouchCB );
00119             hlRemoveEventCallback(  HL_EVENT_1BUTTONDOWN, uiPointName,
00120                                     HL_CLIENT_THREAD, hlButtonDownCB );
00121         }
00122         //------------------------------------------------------
00123         hlRemoveEventCallback(  HL_EVENT_1BUTTONUP, HL_OBJECT_ANY, 
00124                                 HL_CLIENT_THREAD, hlButtonUpCB );
00125         hlDeleteShapes( m_uiPointNameBase, iNumPoints );
00126         hlMakeCurrent( NULL );
00127         hlDeleteContext( m_hHLRC );
00128     }
00129     //----------------------------------------------------------------
00130     if ( m_hHD != HD_INVALID_HANDLE )   hdDisableDevice( m_hHD );
00131 }

template<typename T>
void HapticManager< T >::DrawCursor ( OpenGL::Enum::DrawMode  DM = OpenGL::Enum::POLYGON  )  [inline, virtual]

Implements BaseHapticManager< T >.

Definition at line 207 of file TAPsHapticManager.cpp.

00208 {
00209     static const double K_CURSOR_SIZE_PIXELS = 15;
00210     static const double K_CURSOR_RADIUS = 0.5;
00211     static const double K_CURSOR_HEIGHT = 5.0;
00212     static const int K_CURSOR_TESS = 15;
00213     HLdouble transform[16];
00214     GLUquadricObj *qObj = NULL;
00215     //--------------------------------------------------------------------
00216     glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT );
00217     glPushMatrix();
00218     //--------------------------------------------------------------------
00219     if ( !m_uiCursorDisplayList ) {
00220         m_uiCursorDisplayList = glGenLists( 2 );
00221         //------------------------------------------------------------
00222         // Cone Cursor
00223         glNewList( m_uiCursorDisplayList, GL_COMPILE );
00224             qObj = gluNewQuadric();
00225             glScaled( 0.2, 0.2, 0.2 );
00226             //gluSphere( qObj, K_CURSOR_RADIUS, K_CURSOR_TESS, K_CURSOR_TESS );
00227             gluCylinder( qObj, 0.0, K_CURSOR_RADIUS, K_CURSOR_HEIGHT, 
00228                                     K_CURSOR_TESS, K_CURSOR_TESS );
00229             glTranslated( 0.0, 0.0, K_CURSOR_HEIGHT );
00230             gluCylinder( qObj, K_CURSOR_RADIUS, 0.0, K_CURSOR_HEIGHT/5.0, 
00231                                     K_CURSOR_TESS, K_CURSOR_TESS );
00232             gluDeleteQuadric( qObj );
00233         glEndList();
00234         //------------------------------------------------------------
00235         // Tool One Cursor
00236         glNewList( m_uiCursorDisplayList+1, GL_COMPILE );
00237             ToolOne->DisplayGL( DM );
00238         glEndList();
00239     }
00240     //--------------------------------------------------------------------
00241     // Apply the local position/rotation transform of the haptic device 
00242     // proxy
00243     // I.e. get the proxy transform in world coordinates
00244     hlGetDoublev( HL_PROXY_TRANSFORM, transform );
00245     //glCallList( m_uiCursorDisplayList+1 );
00246     Matrix4x4<T> tooloneTransformMatrix( 
00247         transform[ 0], transform[ 4], transform[ 8], transform[12], 
00248         transform[ 1], transform[ 5], transform[ 9], transform[13], 
00249         transform[ 2], transform[ 6], transform[10], transform[14], 
00250         transform[ 3], transform[ 7], transform[11], transform[15]
00251     );
00252     ToolOne->GetTransform().SetMatrixTransform( tooloneTransformMatrix );
00253     glMultMatrixd( transform );
00254     //--------------------------------------------------------------------
00255     // Apply the local cursor scale factor
00256     //double scale = m_pViewManager->GetWindowToWorldScale() * K_CURSOR_SIZE_PIXELS;
00257     //glScaled( scale, scale, scale );
00258     //glEnable( GL_NORMALIZE );
00259     //ToolOne->DisplayGL( DM );
00260     glCallList( m_uiCursorDisplayList+1 );          // Tool One Cursor
00261     //ToolOne->GetBVHTree()->DrawByOpenGL( 0, 0, 10 );
00262     //glPushAttrib( GL_DEPTH_BUFFER_BIT );
00264     //glEnable( GL_COLOR_MATERIAL );
00265     //glColor3f( 0.0, 0.5, 1.0 );
00266     //glCallList( m_uiCursorDisplayList );          // Cone Cursor
00267     //glDisable( GL_COLOR_MATERIAL );
00268     //glPopAttrib();
00269     //--------------------------------------------------------------------
00270     glPopMatrix();
00271     glPopAttrib();
00272 }

template<typename T>
void HapticManager< T >::DrawCursor (  )  [inline, virtual]

Implements BaseHapticManager< T >.

Definition at line 159 of file TAPsHapticManager.cpp.

00160 {
00161     static const double K_CURSOR_SIZE_PIXELS = 15;
00162     static const double K_CURSOR_RADIUS = 0.5;
00163     static const int K_CURSOR_TESS = 15;
00164     HLdouble transform[16];
00165     GLUquadricObj *qObj = NULL;
00166     //-------------------------------------------------------------------
00167     glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT );
00168     glPushMatrix();
00169     //-------------------------------------------------------------------
00170     if ( !m_uiCursorDisplayList ) {
00171         m_uiCursorDisplayList = glGenLists( 1 );
00172         glNewList( m_uiCursorDisplayList, GL_COMPILE );
00173         qObj = gluNewQuadric();
00174         gluSphere( qObj, K_CURSOR_RADIUS, K_CURSOR_TESS, K_CURSOR_TESS );
00175         gluDeleteQuadric( qObj );
00176         glEndList();
00177     }
00178     //-------------------------------------------------------------------
00179     // Apply the local position/rotation transform of the haptic device 
00180     // proxy
00181     hlGetDoublev( HL_PROXY_TRANSFORM, transform );
00182     glMultMatrixd( transform );
00183     //-------------------------------------------------------------------
00184     // Apply the local cursor scale factor
00185     double scale = m_pViewManager->GetWindowToWorldScale() * K_CURSOR_SIZE_PIXELS;
00186     glScaled( scale, scale, scale );
00187     glEnable( GL_NORMALIZE );
00188     glEnable( GL_COLOR_MATERIAL );
00189     glColor3f( 1.0, 1.0, 1.0 );
00190     glCallList( m_uiCursorDisplayList );
00191     //-------------------------------------------------------------------
00192     glPopMatrix();
00193     glPopAttrib();
00194 }

template<typename T>
void HapticManager< T >::DrawHapticObjects ( OpenGL::Enum::DrawMode  DM = OpenGL::Enum::POLYGON  )  [inline, virtual]

Implements BaseHapticManager< T >.

Definition at line 308 of file TAPsHapticManager.cpp.

00309 {
00310     //---------------------------------------------------------------
00311     hlBeginFrame();
00312     //---------------------------------------------------------------
00313     FeelPoints();
00314     FeelObjects();
00315     //---------------------------------------------------------------
00316     hlEndFrame();
00317 }

template<typename T>
void HapticManager< T >::DrawTooltipSphere ( OpenGL::Enum::DrawMode  DM = OpenGL::Enum::POLYGON  )  [inline, virtual]

Implements BaseHapticManager< T >.

Definition at line 278 of file TAPsHapticManager.cpp.

00279 {
00280     //--------------------------------------------------------------------
00281     // Apply the local position/rotation transform of the haptic device 
00282     // proxy
00283     // I.e. get the proxy transform in world coordinates
00284     hlGetDoublev( HL_PROXY_TRANSFORM, transform );
00285     //glCallList( m_uiCursorDisplayList+1 );
00286     Matrix4x4<T> tooloneTransformMatrix( 
00287         transform[ 0], transform[ 4], transform[ 8], transform[12], 
00288         transform[ 1], transform[ 5], transform[ 9], transform[13], 
00289         transform[ 2], transform[ 6], transform[10], transform[14], 
00290         transform[ 3], transform[ 7], transform[11], transform[15]
00291     );
00292     //--------------------------------------------------------------------
00293     glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT );
00294     glPushMatrix();
00295     //--------------------------------------------------------------------
00296     glMultMatrixd( transform );
00297     glTranslatef( 0, 0, ToolOneSphereTip[3] / 2 );
00298     pModelManager->ReturnPtrToOpenGLUsefulObj()->DrawSphere( 
00299         Vector3<Real>( ToolOneSphereTip[3], ToolOneSphereTip[3], ToolOneSphereTip[3] ) );
00300     //--------------------------------------------------------------------
00301     glPopMatrix();
00302     glPopAttrib();
00303 }

template<typename T>
void HapticManager< T >::FeelObjects ( OpenGL::Enum::DrawMode  DM = OpenGL::Enum::POLYGON  )  [inline, virtual]

Definition at line 322 of file TAPsHapticManager.cpp.

00323 {
00324     //hlBeginFrame();
00325     int iNumPoints = m_pModelManager->strandObj->GetNumberOfLinks() + 1;
00326     hlBeginShape( HL_SHAPE_FEEDBACK_BUFFER, m_uiPointNameBase + iNumPoints );
00327         hlTouchModel( HL_CONTACT );
00328         hlMaterialf( HL_FRONT, HL_STIFFNESS, 0.5 );
00329         hlMaterialf( HL_FRONT, HL_DAMPING, 0.5 );
00330         hlMaterialf( HL_FRONT, HL_STATIC_FRICTION, 0.3 );
00331         hlMaterialf( HL_FRONT, HL_DYNAMIC_FRICTION, 0.2 );
00332         // Use OpenGL commands to create geometry.
00333         m_pModelManager->leftTube->DisplayGL( DM );
00334     hlEndShape();
00335     hlBeginShape( HL_SHAPE_FEEDBACK_BUFFER, m_uiPointNameBase + iNumPoints + 1);
00336         hlTouchModel( HL_CONTACT );
00337         hlMaterialf( HL_FRONT, HL_STIFFNESS, 0.7 );
00338         hlMaterialf( HL_FRONT, HL_DAMPING, 0.1 );
00339         hlMaterialf( HL_FRONT, HL_STATIC_FRICTION, 0.2 );
00340         hlMaterialf( HL_FRONT, HL_DYNAMIC_FRICTION, 0.3 );
00341         // Use OpenGL commands to create geometry.
00342         m_pModelManager->rightTube->DisplayGL( DM );
00343     hlEndShape();
00344     //-------------------------------------------------------------------
00345     //hlEndFrame();
00346 }

template<typename T>
virtual void HapticManager< T >::FeelPoints (  )  [virtual]

template<typename T>
void HapticManager< T >::FeelPoints (  )  [inline, virtual]

Implements BaseHapticManager< T >.

Definition at line 199 of file TAPsHapticManager.cpp.

00200 {
00201     hlBeginFrame();
00202     //-------------------------------------------------------------------
00203     int iNumPoints = m_pPointManager->GetNumPoints();
00204     for ( int i = 0; i < iNumPoints; ++i ) {
00205         //------------------------------------------------------
00206         // Don't haptically draw a selected point, since it's 
00207         // being manipulated
00208         if ( m_iManipPoint == i )   continue;
00209         //------------------------------------------------------
00210         // Draw a shape that represents the projection of the 
00211         // points to the near and far planes
00212         hlHinti( HL_SHAPE_FEEDBACK_BUFFER_VERTICES, 3 );
00213         hlBeginShape( HL_SHAPE_FEEDBACK_BUFFER, m_uiPointNameBase + i );
00214             hlTouchModel( HL_CONSTRAINT );
00215             hlTouchModelf( HL_SNAP_DISTANCE, 3.5 );
00216             hlMaterialf( HL_FRONT_AND_BACK, HL_STIFFNESS, 0.5 );
00217             hlMaterialf( HL_FRONT_AND_BACK, HL_DAMPING, 0.0 );
00218             hlMaterialf( HL_FRONT_AND_BACK, HL_STATIC_FRICTION, 0.0 );
00219             hlMaterialf( HL_FRONT_AND_BACK, HL_DYNAMIC_FRICTION, 0.0 );
00220             const TAPs::Vector3<T> &pt = m_pPointManager->GetPointPosition(i);
00221             //---------------------------------------------
00222             // Draw a line that represents the projection 
00223             // of the point to the near and far of the view 
00224             // volume
00225             TAPs::Vector3<T> winPt, nearPt, farPt;
00226             m_pViewManager->ToScreen( pt, winPt );
00227             winPt[2] = 0;
00228             m_pViewManager->FromScreen( winPt, nearPt );
00229             winPt[2] = 1;
00230             m_pViewManager->FromScreen( winPt, farPt );
00231             glBegin( GL_LINES );
00232                 glVertex3dv( nearPt );
00233                 glVertex3dv( farPt );
00234             glEnd();
00235             glBegin( GL_POINTS );
00236                 glVertex3dv( pt );
00237             glEnd();
00238         hlEndShape();
00239     }
00240     //-------------------------------------------------------------------
00241     // Call any event callbacks that have been triggered
00242     hlCheckEvents();
00243     //-------------------------------------------------------------------
00244     hlEndFrame();
00245 }

template<typename T>
int HapticManager< T >::GetPointIndexFromTouchID ( HLuint  id  )  const [protected]

template<typename T>
int HapticManager< T >::GetPointIndexFromTouchID ( HLuint  id  )  const [inline, protected]

Definition at line 340 of file TAPsHapticManager.cpp.

00341 {
00342     int i = id - m_uiPointNameBase;
00343     assert( 0 <= i && i < m_pPointManager->GetNumPoints() );
00344     return i;
00345 }

template<typename T>
static void HLCALLBACK HapticManager< T >::hlButtonDownCB ( HLenum  event,
HLuint  object,
HLenum  thread,
HLcache *  cache,
void *  userData 
) [static, protected]

template<typename T>
void HLCALLBACK HapticManager< T >::hlButtonDownCB ( HLenum  event,
HLuint  object,
HLenum  thread,
HLcache *  cache,
void *  userData 
) [inline, static, protected]

Definition at line 365 of file TAPsHapticManager.cpp.

00368 {
00369     HapticManager *pThis = static_cast<HapticManager *>(userData);
00370     int i = pThis->GetPointIndexFromTouchID( object );
00371     if ( !pThis->IsManipulating() ) {
00372         pThis->StartManipulating( i );
00373     }
00374 }

template<typename T>
static void HLCALLBACK HapticManager< T >::hlButtonUpCB ( HLenum  event,
HLuint  object,
HLenum  thread,
HLcache *  cache,
void *  userData 
) [static, protected]

template<typename T>
void HLCALLBACK HapticManager< T >::hlButtonUpCB ( HLenum  event,
HLuint  object,
HLenum  thread,
HLcache *  cache,
void *  userData 
) [inline, static, protected]

Definition at line 378 of file TAPsHapticManager.cpp.

00381 {
00382     HapticManager *pThis = static_cast<HapticManager *>(userData);
00383     if ( pThis->IsManipulating() ) {
00384         pThis->StopManipulating();
00385     }
00386 }

template<typename T>
static void HLCALLBACK HapticManager< T >::hlMotionCB ( HLenum  event,
HLuint  object,
HLenum  thread,
HLcache *  cache,
void *  userData 
) [static, protected]

template<typename T>
void HLCALLBACK HapticManager< T >::hlMotionCB ( HLenum  event,
HLuint  object,
HLenum  thread,
HLcache *  cache,
void *  userData 
) [inline, static, protected]

Definition at line 390 of file TAPsHapticManager.cpp.

00393 {
00394     HapticManager *pThis = static_cast<HapticManager *>(userData);
00395 
00396     if ( pThis->IsManipulating() ) {
00397         // Get the position of the proxy when the motion was detected
00398         TAPs::Vector3<T> proxyPos;
00399         hlCacheGetDoublev( cache, HL_PROXY_POSITION, proxyPos );
00400         pThis->UpdateManipPoint( proxyPos );
00401     }
00402 }

template<typename T>
static void HLCALLBACK HapticManager< T >::hlTouchCB ( HLenum  event,
HLuint  object,
HLenum  thread,
HLcache *  cache,
void *  userData 
) [static, protected]

template<typename T>
void HLCALLBACK HapticManager< T >::hlTouchCB ( HLenum  event,
HLuint  object,
HLenum  thread,
HLcache *  cache,
void *  userData 
) [inline, static, protected]

Definition at line 349 of file TAPsHapticManager.cpp.

00352 {
00353     HapticManager *pThis = static_cast<HapticManager *>(userData);
00354     int i = pThis->GetPointIndexFromTouchID( object );
00355     if ( event == HL_EVENT_TOUCH ) {
00356         pThis->m_pPointManager->SetPointHighlighted( i, true );
00357     }
00358     else if ( event == HL_EVENT_UNTOUCH ) {
00359         pThis->m_pPointManager->SetPointHighlighted( i, false );
00360     }
00361 }

template<typename T>
void HapticManager< T >::InitCursor ( const char *  toolOneFile  )  [inline, protected]

Definition at line 626 of file TAPsHapticManager.cpp.

00627 {
00628     //----------------------------------------------------------------
00629     // Set Center, then Rotations of x,y,z axes, and Scale
00630     T scale = 1.5;
00631     Vector3<T> vCenter( 0, 0, 0 );
00632     Vector3<T> vRotationAngle( 0, 0, 0 );
00633     Vector3<T> vScale( scale, scale, scale);
00634     //----------------------------------------------------------------
00635     ToolOne  = new TAPs::OpenGL::OpenGLHalfEdgeModel<T>();
00636     //ToolRight = new OpenGLHalfEdgeModel<T>();
00637     //----------------------------------------------------------------
00638     if ( !ReadModels<Real>::readFile( toolOneFile, ToolOne ) ) {
00639         std::cout << "ERROR: In File Reading! for Tool#1" << std::endl;
00640         exit ( EXIT_FAILURE );
00641     }
00642     else {
00643         std::cout << "Create Tool#1" << std::endl;
00644         ToolOne->SetMaterial( OpenGL::Enum::METAL_SILVER );
00645         ToolOne->GetTransform().SetTranslation( vCenter );
00646         ToolOne->GetTransform().SetRotationAngles( vRotationAngle );
00647         ToolOne->GetTransform().SetScale( vScale );
00648         ToolOne->TransformByTranslationRatationAndScale();
00649         ToolOne->BuildBVHTree( TAPs::Enum::BVH_TREE_BINARY_SPHERE );
00650         ToolOne->GetTransform().SetStatusApplyTransformation( true );
00651     }
00652 }

template<typename T>
void HapticManager< T >::InitCursor (  )  [inline, protected]

Definition at line 617 of file TAPsHapticManager.cpp.

00618 {
00619     char toolOneFile[] = "Data/3dsMax/Tweezers.ASE";
00620     InitCursor( toolOneFile );
00621 }

template<typename T>
void HapticManager< T >::InitHapticData (  )  [inline, protected]

Definition at line 603 of file TAPsHapticManager.cpp.

00604 {
00605     // Flag for enabling/disabling axis snap on drag
00606     m_bHapticAxisSnapOn = true;
00607     // Flag for enabling/disabling rotation
00608     m_bHapticRotateOn = true;
00609 
00610     // Generate ID's for haptic objects
00611     //m_uiHapticObjects = hlGenShapes(2);
00612 }

template<typename T>
virtual bool HapticManager< T >::IsManipulating (  )  const [virtual]

template<typename T>
bool HapticManager< T >::IsManipulating (  )  const [inline, virtual]

Implements BaseHapticManager< T >.

Definition at line 249 of file TAPsHapticManager.cpp.

00250 {
00251     return  m_iManipPoint != -1;
00252 }

template<typename T>
void HapticManager< T >::PopWorkSpaceOffset (  )  [protected]

template<typename T>
void HapticManager< T >::PopWorkSpaceOffset (  )  [inline, protected]

Definition at line 332 of file TAPsHapticManager.cpp.

00333 {
00334     hlMatrixMode( HL_TOUCHWORKSPACE );
00335     hlPopMatrix();
00336 }

template<typename T>
void HapticManager< T >::PushWorkSpaceOffset ( const TAPs::Vector3< T > &  offsetWC  )  [protected]

template<typename T>
void HapticManager< T >::PushWorkSpaceOffset ( const TAPs::Vector3< T > &  offsetWC  )  [inline, protected]

Definition at line 298 of file TAPsHapticManager.cpp.

00299 {
00300     const TAPs::Matrix4x4<T> &mWorldToView = m_pViewManager->GetViewTransform();
00301     TAPs::Matrix4x4<T> mViewToTouch;
00302     TAPs::Matrix4x4<T> mTouchToWorkSpace;
00303     hlGetDoublev( HL_VIEWTOUCH_MATRIX, mViewToTouch );
00304     hlGetDoublev( HL_TOUCHWORKSPACE_MATRIX, mTouchToWorkSpace );
00305     TAPs::Matrix4x4<T> mWorldToWorkSpace = mWorldToView * mViewToTouch * mTouchToWorkSpace;
00306     TAPs::Vector3<T> offsetWS;
00307     //mWorldToWorkSpace.multDirMatrix( offsetWC, offsetWS );
00308     offsetWS[0] =   mWorldToWorkSpace[ 0]*offsetWC[0] + 
00309                     mWorldToWorkSpace[ 4]*offsetWC[1] + 
00310                     mWorldToWorkSpace[ 8]*offsetWC[2];
00311     offsetWS[1] =   mWorldToWorkSpace[ 1]*offsetWC[0] + 
00312                     mWorldToWorkSpace[ 5]*offsetWC[1] + 
00313                     mWorldToWorkSpace[ 9]*offsetWC[2];
00314     offsetWS[2] =   mWorldToWorkSpace[ 2]*offsetWC[0] + 
00315                     mWorldToWorkSpace[ 6]*offsetWC[1] + 
00316                     mWorldToWorkSpace[10]*offsetWC[2];
00317     //----------------------------------------------------------------
00318     // Apply the translation in the local coordinates of the workspace
00319     //TAPs::Matrix4x4<T> mTranslateWS = hduMatrix::createTranslation( -offsetWS );
00320     TAPs::Matrix4x4<T> mTranslateWS( 1, 0, 0, 0, 
00321                                      0, 1, 0, 0,
00322                                      0, 0, 1, 0,
00323                                      -offsetWS[0], -offsetWS[1], -offsetWS[2], 1 );
00324     mTouchToWorkSpace.MultRight( mTranslateWS );
00325     hlMatrixMode( HL_TOUCHWORKSPACE );
00326     hlPushMatrix();
00327     hlLoadMatrixd( mTouchToWorkSpace );
00328 }

template<typename T>
void HapticManager< T >::Setup ( TAPs::OpenGL::BaseModelManager< T > *  pModelManager,
TAPs::OpenGL::BaseOpenGLViewManager< T > *  pViewManager 
) [inline, virtual]

Implements BaseHapticManager< T >.

Definition at line 75 of file TAPsHapticManager.cpp.

00078 {
00079     m_pModelManager = pModelManager;
00080     assert( m_pModelManager );
00081     m_pViewManager = pViewManager;
00082     assert( m_pViewManager );
00083     //----------------------------------------------------------------
00084     // Check Haptic Device
00085     HDErrorInfo error;
00086     m_hHD = hdInitDevice( HD_DEFAULT_DEVICE );
00087     if ( HD_DEVICE_ERROR( error = hdGetError() ) ) {
00088         hduPrintError( stderr, &error, 
00089             "Failed to initialize haptic device!" );
00090         fprintf( stderr, "Press any key to exit" );
00091         getchar();
00092         exit(1);
00093     }
00094     //----------------------------------------------------------------
00095     // Create a haptic context for the device.
00096     // The haptic context maintains the state that persists between 
00097     // frame intervals and is used for haptic rendering.
00098     m_hHLRC = hlCreateContext( m_hHD );
00099     hlMakeCurrent( m_hHLRC );
00100     //----------------------------------------------------------------
00101     // Enable optimization of the viewing parameters when rendering
00102     // geometry for OpenHaptics.
00103     //hlEnable(HL_HAPTIC_CAMERA_VIEW);
00104     //----------------------------------------------------------------
00105     // Front face touchable only - no need to feel back faces
00106     hlTouchableFace( HL_FRONT );
00107     //----------------------------------------------------------------
00108     int iNumPoints = pModelManager->strandObj->GetNumberOfLinks() + 1;
00109     m_uiPointNameBase = hlGenShapes( iNumPoints + 2 );
00110     for ( int i = 0; i < iNumPoints; ++i ) {
00111         // Register event callbacks for all of the points, so we can 
00112         // be notified when the points are touched and untouched.
00113         HLuint uiPointName = m_uiPointNameBase + i;
00114         hlAddEventCallback( HL_EVENT_TOUCH, uiPointName, 
00115                             HL_CLIENT_THREAD, hlTouchCB, this );
00116         hlAddEventCallback( HL_EVENT_UNTOUCH, uiPointName, 
00117                             HL_CLIENT_THREAD, hlTouchCB, this );
00118         hlAddEventCallback( HL_EVENT_1BUTTONDOWN, uiPointName, 
00119                             HL_CLIENT_THREAD, hlButtonDownCB, this );
00120     }
00121     //----------------------------------------------------------------
00122     // Add a callback to handle button up in the collision thread
00123     hlAddEventCallback( HL_EVENT_1BUTTONUP, HL_OBJECT_ANY,
00124                         HL_CLIENT_THREAD, hlButtonUpCB, this );
00125     //----------------------------------------------------------------
00126     // Add a callback to handle button down in the collision thread
00127 //  hlAddEventCallback( HL_EVENT_1BUTTONDOWN, HL_OBJECT_ANY, 
00128 //                      HL_COLLISION_THREAD, 
00129 //                      buttonDownCollisionThreadCallback, NULL );
00130     //----------------------------------------------------------------
00131     // Start an ambient drag friction effect
00132     m_uiEffectName = hlGenEffects( 1 );
00133     hlBeginFrame();
00134         hlEffectd( HL_EFFECT_PROPERTY_GAIN, 0.4 );
00135         hlEffectd( HL_EFFECT_PROPERTY_MAGNITUDE, 0.1 );
00136         hlStartEffect( HL_EFFECT_FRICTION, m_uiEffectName );
00137     hlEndFrame();
00138     //----------------------------------------------------------------
00139     // Tie Cursor with ToolOne of pModelManager (BaseModelManager)
00140     pModelManager->ToolOne = ToolOne;
00141     //----------------------------------------------------------------
00142 }

template<typename T>
void HapticManager< T >::Setup ( TAPs::OpenGL::BasePointManager< T > *  pPointManager,
TAPs::OpenGL::OpenGLBaseViewManager< T > *  pViewManager 
) [inline, virtual]

Implements BaseHapticManager< T >.

Definition at line 48 of file TAPsHapticManager.cpp.

00051 {
00052     m_pPointManager = pPointManager;
00053     assert( m_pPointManager );
00054     m_pViewManager = pViewManager;
00055     assert( m_pViewManager );
00056     //----------------------------------------------------------------
00057     // Check Haptic Device
00058     HDErrorInfo error;
00059     m_hHD = hdInitDevice( HD_DEFAULT_DEVICE );
00060     if ( HD_DEVICE_ERROR( error = hdGetError() ) ) {
00061         hduPrintError( stderr, &error, 
00062             "Failed to initialize haptic device!" );
00063         fprintf( stderr, "Press any key to exit" );
00064         getchar();
00065         exit(1);
00066     }
00067     //----------------------------------------------------------------
00068     // Create a haptic context for the device.
00069     // The haptic context maintains the state that persists between 
00070     // frame intervals and is used for haptic rendering.
00071     m_hHLRC = hlCreateContext( m_hHD );
00072     hlMakeCurrent( m_hHLRC );
00073     int iNumPoints = pPointManager->GetNumPoints();
00074     m_uiPointNameBase = hlGenShapes( iNumPoints );
00075     for ( int i = 0; i < iNumPoints; ++i ) {
00076         // Register event callbacks for all of the points, so we can 
00077         // be notified when the points are touched and untouched.
00078         HLuint uiPointName = m_uiPointNameBase + i;
00079         hlAddEventCallback( HL_EVENT_TOUCH, uiPointName, 
00080                             HL_CLIENT_THREAD, hlTouchCB, this );
00081         hlAddEventCallback( HL_EVENT_UNTOUCH, uiPointName, 
00082                             HL_CLIENT_THREAD, hlTouchCB, this );
00083         hlAddEventCallback( HL_EVENT_1BUTTONDOWN, uiPointName, 
00084                             HL_CLIENT_THREAD, hlButtonDownCB, this );
00085     }
00086     //----------------------------------------------------------------
00087     hlAddEventCallback( HL_EVENT_1BUTTONUP, HL_OBJECT_ANY,
00088                         HL_CLIENT_THREAD, hlButtonUpCB, this );
00089     //----------------------------------------------------------------
00090     // Start an ambient drag friction effect
00091     //m_uiEffectName = hlGenEffects( 1 );
00092     //hlBeginFrame();
00093     //  hlEffectd( HL_EFFECT_PROPERTY_GAIN, 0.4 );
00094     //  hlEffectd( HL_EFFECT_PROPERTY_MAGNITUDE, 0.1 );
00095     //  hlStartEffect( HL_EFFECT_FRICTION, m_uiEffectName );
00096     //hlEndFrame();
00097     //----------------------------------------------------------------
00098 }

template<typename T>
void HapticManager< T >::StartManipulating ( int  i  )  [protected]

template<typename T>
void HapticManager< T >::StartManipulating ( int  i  )  [inline, protected]

Definition at line 259 of file TAPsHapticManager.cpp.

00260 {
00261     assert( !IsManipulating() );
00262     assert( 0 <= i && i < m_pPointManager->GetNumPoints() );
00263     m_pPointManager->SetPointSelected( i, true );
00264     hlAddEventCallback( HL_EVENT_MOTION, HL_OBJECT_ANY,
00265                         HL_CLIENT_THREAD, hlMotionCB, this );
00266     m_iManipPoint = i;
00267     TAPs::Vector3<T> proxyPos;
00268     hlGetDoublev( HL_PROXY_POSITION, proxyPos );
00269     TAPs::Vector3<T> offsetWC = m_pPointManager->GetPointPosition(i) - proxyPos;
00270     //----------------------------------------------------------------
00271     // This is a very useful technique for offsetting the user in 
00272     // space so that they begin their manipulation exactly at the 
00273     // location of the selected point.
00274     PushWorkSpaceOffset( offsetWC );
00275 }

template<typename T>
void HapticManager< T >::StopManipulating (  )  [protected]

template<typename T>
void HapticManager< T >::StopManipulating (  )  [inline, protected]

Definition at line 279 of file TAPsHapticManager.cpp.

00280 {
00281     assert( IsManipulating() );
00282     m_pPointManager->SetPointSelected( m_iManipPoint, false );
00283     hlRemoveEventCallback(  HL_EVENT_MOTION, HL_OBJECT_ANY,
00284                             HL_CLIENT_THREAD, hlMotionCB );
00285     m_iManipPoint = -1;
00286     PopWorkSpaceOffset();
00287 }

template<typename T>
void HapticManager< T >::UpdateManipPoint ( const TAPs::Vector3< T > &  proxyPos,
const TAPs::Matrix4x4< T > &  proxyTransform 
) [inline, protected]

Definition at line 464 of file TAPsHapticManager.cpp.

00467 {
00468     // Current Rotation of this motion
00469     TAPs::Matrix3x3<T> currRotation( 
00470         proxyTransform[0], proxyTransform[4], proxyTransform[8], 
00471         proxyTransform[1], proxyTransform[5], proxyTransform[9], 
00472         proxyTransform[2], proxyTransform[6], proxyTransform[10] 
00473     );
00474     //--------------------------------------------------------------------
00475     TAPs::Matrix3x3<T> rotation =  currRotation * startDragProxyRotation;
00476     //rotation = m_pModelManager->strandObj->m_mRotMatForLeftNeedle * rotation;
00477     //rotation = m_pModelManager->strandObj->m_mRotMatForLeftNeedle.GetTranspose();
00478     m_pModelManager->strandObj->SetPointPosition( m_iManipPoint, proxyPos, rotation );
00479     if ( m_pModelManager->CollisionDetection() ) {
00480         //gModelManager->strandObj->RestorePreviousPositions();
00481         //gModelManager->strandObj->SetPointPosition( gManipPoint, oldPosition );
00482     }
00483 }

template<typename T>
void HapticManager< T >::UpdateManipPoint ( const TAPs::Vector3< T > &  proxyPos  )  [inline, protected]

Definition at line 291 of file TAPsHapticManager.cpp.

00292 {
00293     m_pPointManager->SetPointPosition( m_iManipPoint, proxyPos );
00294 }

template<typename T>
virtual void HapticManager< T >::UpdateWorkSpace (  )  [virtual]

template<typename T>
void HapticManager< T >::UpdateWorkSpace (  )  [inline, virtual]

Implements BaseHapticManager< T >.

Definition at line 137 of file TAPsHapticManager.cpp.

00138 {
00139     GLdouble modelview[16];
00140     GLdouble projection[16];
00141     GLint viewport[4];
00142     glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
00143     glGetDoublev( GL_PROJECTION_MATRIX, projection );
00144     glGetIntegerv( GL_VIEWPORT, viewport );
00145     hlMatrixMode( HL_TOUCHWORKSPACE );
00146     hlLoadIdentity();
00147     // Use of a non-uniform workspace fit, which offer a maximal fit to the view 
00148     // frustum but introduces non-uniform scale in the workspace.
00149     // This non-uniform scale is fine for point and line based haptics, like 
00150     // this example, but can introduct distortion when actually feeling surfaces 
00151     // (i.e. a sphere might feel like an ellipsoid)
00152     hluFitWorkspaceNonUniform( projection );
00153 }


Member Data Documentation

template<typename T>
T HapticManager< T >::g_tSnapDistance = g_tSnapDistanceConst [inline, static, protected]

Definition at line 77 of file TAPsHapticManager.hpp.

template<typename T>
BEGIN_NAMESPACE_TAPs__Haptic const T HapticManager< T >::g_tSnapDistanceConst = 2.0 [inline, static, protected]

Definition at line 76 of file TAPsHapticManager.hpp.

template<typename T>
bool HapticManager< T >::m_bHapticAxisSnapOn [protected]

Definition at line 96 of file TAPsHapticManager.hpp.

template<typename T>
bool HapticManager< T >::m_bHapticRotateOn [protected]

Definition at line 99 of file TAPsHapticManager.hpp.

template<typename T>
HHD HapticManager< T >::m_hHD [protected]

Definition at line 59 of file TAPsHapticManager.hpp.

template<typename T>
HHLRC HapticManager< T >::m_hHLRC [protected]

Definition at line 60 of file TAPsHapticManager.hpp.

template<typename T>
int HapticManager< T >::m_iManipPoint [protected]

Definition at line 61 of file TAPsHapticManager.hpp.

template<typename T>
TAPs::OpenGL::BaseModelManager<T>* HapticManager< T >::m_pModelManager [protected]

Definition at line 81 of file TAPsHapticManager.hpp.

template<typename T>
TAPs::OpenGL::BasePointManager<T>* HapticManager< T >::m_pPointManager [protected]

Definition at line 66 of file TAPsHapticManager.hpp.

template<typename T>
TAPs::OpenGL::BaseOpenGLViewManager<T>* HapticManager< T >::m_pViewManager [protected]

Definition at line 82 of file TAPsHapticManager.hpp.

template<typename T>
TAPs::OpenGL::OpenGLBaseViewManager<T>* HapticManager< T >::m_pViewManager [protected]

Definition at line 67 of file TAPsHapticManager.hpp.

template<typename T>
T HapticManager< T >::m_tCursorScale [protected]

Definition at line 63 of file TAPsHapticManager.hpp.

template<typename T>
GLuint HapticManager< T >::m_uiCursorDisplayList [protected]

Definition at line 64 of file TAPsHapticManager.hpp.

template<typename T>
HLuint HapticManager< T >::m_uiEffectName [protected]

Definition at line 65 of file TAPsHapticManager.hpp.

template<typename T>
HLuint HapticManager< T >::m_uiPointNameBase [protected]

Definition at line 62 of file TAPsHapticManager.hpp.

template<typename T>
TAPs::Matrix3x3<T> HapticManager< T >::startDragProxyRotation [protected]

Definition at line 90 of file TAPsHapticManager.hpp.

template<typename T>
TAPs::Matrix4x4<T> HapticManager< T >::startDragProxyTransform [protected]

Definition at line 89 of file TAPsHapticManager.hpp.


The documentation for this class was generated from the following files:

Generated on Mon Oct 13 11:44:57 2008 for TAPs by  doxygen 1.5.6