HLHapticsDevice.h

Go to the documentation of this file.
00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
00022 //
00023 //
00027 //
00029 #ifndef __HLHAPTICSDEVICE_H__
00030 #define __HLHAPTICSDEVICE_H__
00031 
00032 #include "H3DHapticsDevice.h"
00033 #include "DeviceLog.h"
00034 #include "SFString.h" 
00035 #ifdef HAVE_OPENHAPTICS
00036 #include <HL/hl.h>
00037 #endif
00038 #include "GL/glew.h"
00039 namespace H3D {
00047   class H3DAPI_API HLHapticsDevice : public H3DHapticsDevice {
00048   public:
00049     typedef TypedSFNode< DeviceLog > SFDeviceLog;
00050 
00051     H3D_VALUE_EXCEPTION( string, CouldNotInitHapticsDevice );
00052     
00054     HLHapticsDevice( Inst< SFVec3f         > _devicePosition         = 0,
00055                      Inst< SFRotation      > _deviceOrientation      = 0,
00056                      Inst< TrackerPosition > _trackerPosition        = 0,
00057                      Inst< TrackerOrientation > _trackerOrientation  = 0,
00058                      Inst< PosCalibration  > _positionCalibration    = 0,
00059                      Inst< OrnCalibration  > _orientationCalibration = 0,
00060                      Inst< SFVec3f         > _proxyPosition          = 0,
00061                      Inst< WeightedProxy   > _weightedProxyPosition  = 0,     
00062                      Inst< SFFloat         > _proxyWeighting         = 0,
00063                      Inst< SFBool          > _mainButton             = 0,
00064                      Inst< SFVec3f         > _force                  = 0,
00065                      Inst< SFVec3f         > _torque                 = 0,
00066                      Inst< SFInt32         > _inputDOF               = 0,
00067                      Inst< SFInt32         > _outputDOF              = 0,
00068                      Inst< SFInt32         > _hapticsRate            = 0,
00069                      Inst< SFNode          > _stylus                 = 0,
00070                      Inst< SFBool          > _initialized            = 0,
00071                      Inst< SFString        > _deviceName             = 0,
00072                      Inst< SFBool          > _secondaryButton        = 0,
00073                      Inst< SFDeviceLog     > _deviceLog              = 0 ):
00074       H3DHapticsDevice( _devicePosition, _deviceOrientation, _trackerPosition,
00075                         _trackerOrientation, _positionCalibration, 
00076                         _orientationCalibration, _proxyPosition,
00077                         _weightedProxyPosition, _proxyWeighting,
00078                         _mainButton, _force, _torque,
00079                         _inputDOF, _outputDOF, _hapticsRate, _stylus, _initialized ),
00080       deviceName( _deviceName ),
00081       secondaryButton( _secondaryButton ),
00082       deviceLog( _deviceLog )
00083 #ifdef HAVE_OPENHAPTICS
00084      ,last_effect_change( TimeStamp() ),
00085       last_loop_time( (H3DFloat) 0.1 ), 
00086       log( NULL ),
00087       device_handle( 0 ),
00088       haptic_context( NULL )
00089 #endif
00090 {
00091 
00092       type_name = "HLHapticsDevice";
00093       database.initFields( this );
00094       deviceName->setValue( "Default PHANToM" );
00095       secondaryButton->setValue( false, id );
00096     }
00097 
00099     virtual ~HLHapticsDevice() {
00100       if( initialized->getValue() )
00101         disableDevice();
00102     }
00103 
00104 #ifdef HAVE_OPENHAPTICS
00105 
00106     // Callback function for setting the button fields when button events
00107     // occurs.
00108     static void HLCALLBACK hlButtonCallback( HLenum event,
00109                                              HLuint object,
00110                                              HLenum thread,
00111                                              HLcache *cache,
00112                                              void *data );
00113 
00114 
00116     virtual void preRender();
00117 
00119     virtual void postRender();
00120 
00123     virtual void initDevice();
00124 
00125         virtual void initHLLayer();
00126 
00128     virtual void resetDevice() {}
00129 
00133     virtual void disableDevice();
00134 
00138     virtual void updateDeviceValues();
00139 
00142     virtual void renderShapes( const HapticShapeVector &shapes );
00143 
00147     virtual void renderEffects( const HapticEffectVector &effects );
00148 #endif
00155     auto_ptr< SFString > deviceName;
00156 
00164     auto_ptr< SFBool > secondaryButton;
00165 
00173     auto_ptr< SFDeviceLog > deviceLog;
00174 
00176     static H3DNodeDatabase database;
00177 #ifdef HAVE_OPENHAPTICS
00180     inline HapticEffectVector &getCurrentForceEffects() {
00181       return current_force_effects;
00182     }
00183 
00186     inline HapticEffectVector &getLastForceEffects() {
00187       return last_force_effects;
00188     }
00189 
00191     inline HHD getDeviceHandle() { 
00192       return device_handle;
00193     }
00194 
00197     inline HHLRC getHapticContext() {
00198       return haptic_context;
00199     }
00200     
00203     TimeStamp last_effect_change;
00204     
00206     TimeStamp last_loop_time;
00207 
00209     AutoRef< DeviceLog > log;
00210 
00211   protected:
00213     HHD device_handle;
00214     
00216     HHLRC haptic_context;
00217 
00219     vector< HDCallbackCode > hd_handles; 
00220     
00221   private:
00222     // the force effects that are currently rendered in the realtime loop.
00223     // Should not be changed directly from the scenegraph loop but instead
00224     // use the renderEffects function to set the effects.
00225     HapticEffectVector current_force_effects;
00226 
00227     // the force effects that was current in the last scene graph loop.
00228     HapticEffectVector last_force_effects;
00229 
00230     // the shapes that are currently being rendered in the realtime loop.
00231     HapticShapeVector current_shapes;
00232 #endif
00233   };
00234 }
00235 
00236 #endif

Generated on Thu Aug 24 12:38:33 2006 for H3D API by  doxygen 1.4.5