cameraFXMgr.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _CAMERAFXMGR_H_
  23. #define _CAMERAFXMGR_H_
  24. #ifndef _TORQUE_LIST_
  25. #include "core/util/tList.h"
  26. #endif
  27. #ifndef _MPOINT3_H_
  28. #include "math/mPoint3.h"
  29. #endif
  30. #ifndef _MMATRIX_H_
  31. #include "math/mMatrix.h"
  32. #endif
  33. //**************************************************************************
  34. // Abstract camera effect template
  35. //**************************************************************************
  36. class CameraFX
  37. {
  38. protected:
  39. MatrixF mCamFXTrans;
  40. F32 mElapsedTime;
  41. F32 mDuration;
  42. public:
  43. CameraFX();
  44. MatrixF & getTrans(){ return mCamFXTrans; }
  45. virtual bool isExpired(){ return mElapsedTime >= mDuration; }
  46. void setDuration( F32 duration ){ mDuration = duration; }
  47. virtual void update( F32 dt );
  48. };
  49. //--------------------------------------------------------------------------
  50. // Camera shake effect
  51. //--------------------------------------------------------------------------
  52. class CameraShake : public CameraFX
  53. {
  54. typedef CameraFX Parent;
  55. VectorF mFreq; // these are vectors to represent these values in 3D
  56. VectorF mStartAmp;
  57. VectorF mAmp;
  58. VectorF mTimeOffset;
  59. F32 mFalloff;
  60. public:
  61. /// Is controlled by someone else, ignore duration and do not delete.
  62. bool remoteControlled;
  63. bool isAdded;
  64. CameraShake();
  65. void init();
  66. void fadeAmplitude();
  67. void setFalloff( F32 falloff ){ mFalloff = falloff; }
  68. void setFrequency( VectorF &freq ){ mFreq = freq; }
  69. void setAmplitude( VectorF &amp ){ mStartAmp = amp; }
  70. bool isExpired();
  71. virtual void update( F32 dt );
  72. };
  73. //**************************************************************************
  74. // CameraFXManager
  75. //**************************************************************************
  76. class CameraFXManager
  77. {
  78. typedef CameraFX * CameraFXPtr;
  79. MatrixF mCamFXTrans;
  80. typedef Torque::List<CameraFXPtr> CamFXList;
  81. CamFXList mFXList;
  82. public:
  83. void addFX( CameraFX *newFX );
  84. void removeFX( CameraFX *fx );
  85. void clear();
  86. MatrixF & getTrans(){ return mCamFXTrans; }
  87. void update( F32 dt );
  88. CameraFXManager();
  89. ~CameraFXManager();
  90. };
  91. extern CameraFXManager gCamFXMgr;
  92. #endif