5 #ifndef COMPILE_PHANTOM_DEVICE
10 #ifdef COMPILE_PHANTOM_DEVICE
20 #include <HDU/hduVector.h>
21 #include <HDU/hduError.h>
25 namespace vreckoDP_PHANToM {
27 class DP_EXPORT PHANToMFilter;
33 osg::Vec3 acceleration;
34 HDint nCurrentButtons;
39 osg::Vec3 absolutePosition;
40 osg::Matrix absoluteOrientation;
44 struct PHANTOM_HELD_OBJECT {
45 unsigned long objectID;
46 osg::Matrix transform;
48 PHANTOM_HELD_OBJECT & operator= (
const PHANTOM_HELD_OBJECT &
other) {
49 objectID = other.objectID;
50 transform = other.transform;
56 typedef DynamicArray<PHANTOM_HELD_OBJECT> PHANTOM_HELD_OBJECTS_ARRAY;
65 virtual bool loadXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER
DOMNode *);
67 virtual void preInitialize(
void);
68 virtual void postInitialize(
void);
70 void processEvent(
const std::string &input_name,
void *value);
72 virtual int openDevice(
void);
73 int closeDevice(
void);
74 int calibrateDevice(
void);
79 void addFilter(PHANToMFilter* newFilter);
83 void removeFilter(
unsigned int);
84 void removeFilter(PHANToMFilter*);
86 void applyFilters(PHANToMSTATE &pState, osg::Vec3 &temp_force, osg::Vec3 &temp_torque);
88 void resetFilters(
void);
92 bool isForceApplied() {
return !bDontApplyForce; }
94 inline void acquireMainLock() { filterVectorLock.lock(); }
95 inline void releaseMainLock() { filterVectorLock.unlock(); }
97 void setHeldObjects(PHANTOM_HELD_OBJECTS_ARRAY * newHeldObjects);
103 PHANTOM_HELD_OBJECTS_ARRAY * getHeldObjects(
bool *bIsDefault = NULL);
110 inline PHANTOM_HELD_OBJECTS_ARRAY * getDefaultHeldObjects(
void) {
return &defaultHeldObjects; }
119 inline const osg::Matrix &getHeldObjectsTransform()
const {
return heldObjectsTransform; }
120 inline void setHeldObjectsTransform(osg::Matrix
const &newTransform) { heldObjectsTransform = newTransform; }
123 void setLastPhantomTrans(osg::Matrix &newMat);
126 void getLastPhantomTrans(osg::Matrix *outMat);
131 void setCollisionOccurred(
bool bNewValue) { bCollisionOccurred = bNewValue; }
132 bool getCollisionOccurred() {
return bCollisionOccurred; }
135 float workspace_scale;
136 bool bRelativeToCamera;
141 bool avatarPosModifiedByUs;
145 osg::Vec3 avatarLookAt;
148 bool bInitializeHeldObjectsTransform;
152 bool stopMotion(
bool state);
157 HDSchedulerHandle hHSCallback;
158 osg::Vec3 position, velocity;
162 bool last_button_state;
166 bool bDontApplyForce;
171 std::vector<PHANToMFilter*> filters;
174 osg::Matrix heldObjectsTransform;
176 PHANTOM_HELD_OBJECTS_ARRAY heldObjects;
177 PHANTOM_HELD_OBJECTS_ARRAY defaultHeldObjects;
183 bool bCollisionOccurred;
187 osg::Matrix lastPhantomTrans;
192 void readHeldObjectsFromXML( XERCES_CPP_NAMESPACE_QUALIFIER
DOMNode * tmpNode, PHANTOM_HELD_OBJECTS_ARRAY* defaultHeldObjects );
194 virtual int processNotification(
BaseClass *sender,
unsigned long notificationType,
195 void *notificationData);
205 PHANToMFilter(
const char* abName) : Ability(abName), filter_enabled(true), bIsAfterReset(true), bActiveAfterReset(true), resetTime(0) {};
208 virtual void apply(PHANToMSTATE &pState, osg::Vec3 &force, osg::Vec3 &torque) {};
210 void enableFilter(
void) {filter_enabled =
true;}
211 void disableFilter(
void) {filter_enabled =
false;}
212 bool isFilterEnabled(
void) {
return filter_enabled;}
214 inline bool isAfterReset(
void) {
return bIsAfterReset; }
215 inline void setIsAfterReset(
bool bNewAfterReset) { bIsAfterReset = bNewAfterReset;
if (bNewAfterReset) { resetTime = osg::Timer::instance()->tick(); } }
216 inline osg::Timer_t getResetTime() {
return resetTime; }
218 inline bool isActiveFirstTime() {
return bActiveAfterReset; }
219 inline void setActiveAfterReset(
bool bNewActiveAfterReset) { bActiveAfterReset = bNewActiveAfterReset; }
230 bool bActiveAfterReset;
234 osg::Timer_t resetTime;
241 #endif //COMPILE_PHANTOM_DEVICE