00001
00026 #ifndef _HAPTICS_
00027 #define _HAPTICS_
00028
00029 #include <windows.h>
00030 #include <hdl/hdl.h>
00031 #include <hdlu/hdlu.h>
00032 #include <Vector3D.h>
00033 #include <time.h>
00034 #include <Level2D.h>
00035 #include <disableWarnings.h>
00036
00037 namespace sonus
00038 {
00039
00040 typedef int HapticsButton;
00041
00042 struct WallMaterial
00043 {
00044 int servoResolution;
00045 double frequency;
00046 double scale;
00047 int accuracy;
00048 Vector3D force;
00049
00050 WallMaterial()
00051 {
00052 servoResolution = 1;
00053 frequency = 5;
00054 scale = 0.3;
00055 accuracy = 10000000;
00056 };
00057 };
00058
00075 class Haptics
00076 {
00077 public:
00078
00083 Haptics();
00084
00090 void getPosition( Vector3D* vec );
00091
00097 void getVelocity( Vector3D* vec );
00098
00104 void getAcceleration( Vector3D* vec );
00105
00111 void setForce( Vector3D force );
00112
00118 void getForce( Vector3D* force );
00119
00125 void addForce( Vector3D force );
00126
00135 void initLevel( Level2D* level );
00136
00146 void update( Level2D* level );
00147
00152 void endLevel();
00153
00160 bool buttonPressed( HapticsButton button );
00161
00168 bool buttonPressed();
00169
00173 ~Haptics();
00174
00189 friend HDLServoOpExitCode HapticsServoOp( void *data );
00190
00191 static const int BUTTON_MIDDLE = 1;
00192 static const int BUTTON_LEFT = 2;
00193 static const int BUTTON_FRONT = 4;
00194 static const int BUTTON_RIGHT = 8;
00195
00196 float BOUNDARIES_MULTIPLIER;
00197 float WALL_MULTIPLIER;
00198
00199 bool active;
00200
00201 WallMaterial wallMaterial;
00202
00203 private:
00204
00213 void setWall( Vector3D position, double yRotation = 0 );
00214
00220 void deleteWall();
00221
00228 void addForceForBoundariesTo( Vector3D* force );
00229
00238 void addForceForWallTo( Vector3D* force );
00239
00246 void addForceForWalkTo( Vector3D* force );
00247
00253 void addForceForPortalTo( Vector3D* force );
00254
00255 double scaleFactor;
00256 Vector2D* transformationVector;
00257
00258 Vector3D position;
00259 Vector3D oldPosition;
00260 Vector3D velocity;
00261 Vector3D oldVelocity;
00262 Vector3D acceleration;
00263
00264 Vector2D playerPosition;
00265
00266 bool playerReachedPortal;
00267
00268 float portalForce;
00269 float portalForceIncrement;
00270 long portalTimer;
00271
00272 Vector2D wallForce;
00273 Vector3D wallPosition;
00274 Vector2D wallCollisionNormal;
00275 double wallYRotation;
00276 double wallSlideDistance;
00277 Vector2D wallSlideStartPosition;
00278 bool wallExists;
00279 long wallCollisionTimeout;
00280 long wallCollisionTimeoutMax;
00281
00282 long walkForceTimer;
00283 long walkForceCycle;
00284 long walkForceCycleDuration;
00285 long walkForceAmplitude;
00286 bool walkForceActive;
00287 bool walkForceEnabled;
00288
00289 Vector3D force;
00290 Vector3D savedForce;
00291
00292 int servoResolution;
00293 int servoCount;
00294 long servoTimer;
00295
00296 HDLDeviceHandle hHandle;
00297 HDLOpHandle servoOp;
00298
00299 int buttonsState;
00300
00301 double forceBoundaries[ 6 ];
00302 double workspace[ 6 ];
00303 double gamespace[ 6 ];
00304 double transmatrix[ 16 ];
00305 };
00306
00307 HDLServoOpExitCode HapticsServoOp( void *data );
00308
00309 }
00310
00311 #endif