00001 /* 00002 This source file is part of OgreHaptics 00003 (a library for wrapping haptics devices for use with the open-source 00004 graphics engine OGRE, http://www.ogre3d.org) 00005 00006 Copyright (c) 2006 - 2008 Jorrit de Vries 00007 Also see acknowledgements in Readme.html 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public License 00011 as published by the Free Software Foundation; either version 2.1 00012 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the 00021 Free Software Foundation, Inc., 00022 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 */ 00024 #ifndef _OgreHapticsForceEffect_H__ 00025 #define _OgreHapticsForceEffect_H__ 00026 00027 #include "OgreHapticsPrerequisites.h" 00028 #include "OgreHapticsAtomic.h" 00029 #include "OgreHapticsForceEffectAlgorithm.h" 00030 #include "OgreHapticsForceOutput.h" 00031 00032 namespace OgreHaptics { 00033 00035 enum ForceEffectState 00036 { 00041 FES_INACTIVE, 00046 FES_STARTING, 00048 FES_FADING_IN, 00050 FES_SUSTAINING, 00052 FES_FADING_OUT 00053 }; 00054 00056 enum ForceEffectSustainMode 00057 { 00062 FESM_TEMPORAL, 00067 FESM_PERSISTANT 00068 }; 00069 00074 enum ForceEffectTimeType 00075 { 00077 FETT_TOTAL, 00082 FETT_CURRENT_STATE 00083 }; 00084 00100 class _OgreHapticsExport ForceEffect : public StringInterface 00101 { 00102 // Allow manager full access 00103 friend class ForceEffectManager; 00104 public: 00106 class _OgreHapticsPrivate CmdSustainMode : public ParamCommand 00107 { 00108 public: 00109 String doGet(const void* target) const; 00110 void doSet(void* target, const String& value); 00111 }; 00113 class _OgreHapticsPrivate CmdSustainDuration : public ParamCommand 00114 { 00115 public: 00116 String doGet(const void* target) const; 00117 void doSet(void* target, const String& value); 00118 }; 00120 class _OgreHapticsPrivate CmdFadeInDuration : public ParamCommand 00121 { 00122 public: 00123 String doGet(const void* target) const; 00124 void doSet(void* target, const String& value); 00125 }; 00127 class _OgreHapticsPrivate CmdFadeOutDuration : public ParamCommand 00128 { 00129 public: 00130 String doGet(const void* target) const; 00131 void doSet(void* target, const String& value); 00132 }; 00133 00150 class Listener 00151 { 00152 public: 00154 virtual ~Listener() {} 00156 virtual void effectStarted(ForceEffect*) {} 00157 }; 00158 00160 ForceEffect(const String& name); 00162 virtual ~ForceEffect(); 00168 ForceEffect& operator = (const ForceEffect& rhs); 00169 00171 const String& getName(void) const { return mName; } 00172 00180 const String& getOrigin(void) const { return mOrigin; } 00182 void _notifyOrigin(const String& origin) { mOrigin = origin; } 00183 00196 void start(Device* device); 00204 void restart(void); 00214 void stop(bool immediate = false); 00220 bool isActive(void) const; 00222 ForceEffectState getState(void) const; 00232 void _notifyDeviceDisabled(void); 00233 00246 void setSustainMode(ForceEffectSustainMode mode); 00248 ForceEffectSustainMode getSustainMode(void) const { return mSustainMode; }; 00249 00258 void setSustainDuration(long duration); 00265 long getSustainDuration(void) const; 00273 void setFadeInDuration(long duration); 00278 long getFadeInDuration(void) const; 00286 void setFadeOutDuration(long duration); 00291 long getFadeOutDuration(void) const; 00297 long getRemainingTime(ForceEffectTimeType type = FETT_TOTAL) const; 00298 00305 void setListener(Listener* listener) { mListener = listener; } 00307 Listener* getListener(void) const { return mListener; } 00308 00336 void setAlgorithmParameter(unsigned short index, const String& name, 00337 const String& value); 00359 void setAlgorithmParameterList(unsigned short index, 00360 const NameValuePairList& paramList); 00379 void setAllAlgorithmsParameter(const String& name, const String& value); 00396 void setAllAlgorithmsParameterList(const NameValuePairList& paramList); 00397 00406 ForceEffectAlgorithm* addAlgorithm(const String& algorithmType); 00423 ForceEffectAlgorithm* getAlgorithm(unsigned short index) const; 00433 void removeAlgorithm(unsigned short index); 00438 void removeAllAlgorithms(void); 00440 unsigned short getNumAlgorithms(void) const; 00441 typedef VectorIterator<ForceEffectAlgorithmList> AlgorithmIterator; 00450 AlgorithmIterator getAlgorithmIterator(void); 00451 00456 void _applyAlgorithmParameters(void); 00464 void _setState(ForceEffectState state, double currentTime); 00466 void _resetAlgorithms(void); 00475 const ForceOutput& _calculateForces(const Vector3& position, 00476 const Quaternion& orientation, const Vector3& linearVelocity, 00477 const Vector3& angularVelocity, double timeElapsed); 00482 Real _getLerpFraction(double currentTime, bool fadingIn); 00483 protected: 00484 // Command objects 00485 static CmdSustainMode msSustainModeCmd; 00486 static CmdSustainDuration msSustainDurationCmd; 00487 static CmdFadeInDuration msFadeInDurationCmd; 00488 static CmdFadeOutDuration msFadeOutDurationCmd; 00489 00491 Device* mDevice; 00493 Listener* mListener; 00495 bool mhtIsMaxLerpFractionSet; 00497 long mhtCurrentStateDuration; 00499 double mhtCurrentStateStartTime; 00503 Real mhtMaxLerpFraction; 00505 ForceEffectSustainMode mSustainMode; 00507 String mName; 00509 String mOrigin; 00511 AtomicScalar<ForceEffectState> mState; 00513 AtomicScalar<long> mSustainDuration; 00516 AtomicScalar<long> mFadeInDuration; 00519 AtomicScalar<long> mFadeOutDuration; 00521 AtomicScalar<int> mDurationChanged; 00523 AtomicScalar<long> mCurrentStateRemainingTime; 00525 AtomicScalar<long> mTotalRemainingTime; 00527 ForceOutput mOutput; 00529 ForceEffectAlgorithmList mAlgorithms; 00530 typedef std::map<unsigned short, NameValuePairList> AlgorithmsParameterMap; 00532 AlgorithmsParameterMap mAlgorithmsParameterMap; 00533 00538 void updateRemainingTime(double timeElapsed); 00539 }; 00540 00541 } 00542 00543 #endif
Last modified Tue Jan 6 22:31:25 2009