00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00107
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
00223
00224
00225 HapticEffectVector current_force_effects;
00226
00227
00228 HapticEffectVector last_force_effects;
00229
00230
00231 HapticShapeVector current_shapes;
00232 #endif
00233 };
00234 }
00235
00236 #endif