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 __H3DTHREADEDHAPTICSDEVICE_H__
00030 #define __H3DTHREADEDHAPTICSDEVICE_H__
00031
00032 #include "H3DHapticsDevice.h"
00033 #include "ThreadSafeFields.h"
00034
00035 namespace H3D {
00036
00051 class H3DAPI_API H3DThreadedHapticsDevice: public H3DHapticsDevice {
00052 public:
00053
00055 H3DThreadedHapticsDevice(
00056 Inst< ThreadSafeSField< SFVec3f > > _devicePosition = 0,
00057 Inst< ThreadSafeSField< SFRotation > > _deviceOrientation = 0,
00058 Inst< TrackerPosition > _trackerPosition = 0,
00059 Inst< TrackerOrientation > _trackerOrientation = 0,
00060 Inst< PosCalibration > _positionCalibration = 0,
00061 Inst< OrnCalibration > _orientationCalibration = 0,
00062 Inst< SFVec3f > _proxyPosition = 0,
00063 Inst< WeightedProxy > _weightedProxyPosition = 0,
00064 Inst< SFFloat > _proxyWeighting = 0,
00065 Inst< ThreadSafeSField< SFBool > > _main_button = 0,
00066 Inst< ThreadSafeSField< SFVec3f > > _force = 0,
00067 Inst< ThreadSafeSField< SFVec3f > > _torque = 0,
00068 Inst< SFInt32 > _inputDOF = 0,
00069 Inst< SFInt32 > _outputDOF = 0,
00070 Inst< SFInt32 > _hapticsRate = 0,
00071 Inst< SFNode > _stylus = 0,
00072 Inst< SFBool > _initialized = 0 );
00073
00075 virtual ~H3DThreadedHapticsDevice() {
00076 disableDevice();
00077 }
00078
00081 virtual void initDevice();
00082
00086 virtual void disableDevice();
00087
00088 #ifdef USE_HAPTICS
00094 virtual void renderShapes( const HapticShapeVector &shapes ) {};
00095
00101 virtual void renderEffects( const HapticEffectVector &effects );
00102 #endif
00103
00105 static H3DNodeDatabase database;
00106
00107 #ifdef USE_HAPTICS
00110 inline HapticEffectVector &getCurrentForceEffects() {
00111 return current_force_effects;
00112 }
00113
00116 inline HapticEffectVector &getLastForceEffects() {
00117 return last_force_effects;
00118 }
00119 #endif
00120
00124 virtual void updateDeviceValues();
00125
00126 protected:
00129 virtual Vec3f getPosition() = 0;
00130
00133 virtual Vec3f getVelocity() = 0;
00134
00137 virtual Rotation getOrientation() = 0;
00138
00141 virtual bool getButtonStatus() = 0;
00142
00145 virtual void sendForce( const Vec3f &f ) = 0;
00146
00149 virtual void sendTorque( const Vec3f &f ) = 0;
00150
00151 #ifdef USE_HAPTICS
00152
00153
00154
00155 HapticEffectVector current_force_effects;
00156
00157
00158 HapticEffectVector last_force_effects;
00159
00160
00161 HapticShapeVector current_shapes;
00162 #endif
00163
00164 unsigned int nr_haptics_loops;
00165
00166
00167 TimeStamp last_update_values;
00168
00171 TimeStamp last_effect_change;
00172
00174 TimeStamp last_loop_time;
00175
00177 static PeriodicThread::CallbackCode forceEffectCallback( void *data );
00178
00181 static PeriodicThread::CallbackCode changeForceEffects( void *_data );
00182 };
00183 }
00184
00185 #endif