cameraFXMgr.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. virtual ~CameraFX() { }
  45. MatrixF & getTrans(){ return mCamFXTrans; }
  46. virtual bool isExpired(){ return mElapsedTime >= mDuration; }
  47. void setDuration( F32 duration ){ mDuration = duration; }
  48. virtual void update( F32 dt );
  49. };
  50. //--------------------------------------------------------------------------
  51. // Camera shake effect
  52. //--------------------------------------------------------------------------
  53. class CameraShake : public CameraFX
  54. {
  55. typedef CameraFX Parent;
  56. VectorF mFreq; // these are vectors to represent these values in 3D
  57. VectorF mStartAmp;
  58. VectorF mAmp;
  59. VectorF mTimeOffset;
  60. F32 mFalloff;
  61. public:
  62. /// Is controlled by someone else, ignore duration and do not delete.
  63. bool remoteControlled;
  64. bool isAdded;
  65. CameraShake();
  66. void init();
  67. void fadeAmplitude();
  68. void setFalloff( F32 falloff ){ mFalloff = falloff; }
  69. void setFrequency( VectorF &freq ){ mFreq = freq; }
  70. void setAmplitude( VectorF &amp ){ mStartAmp = amp; }
  71. bool isExpired();
  72. virtual void update( F32 dt );
  73. };
  74. //**************************************************************************
  75. // CameraFXManager
  76. //**************************************************************************
  77. class CameraFXManager
  78. {
  79. typedef CameraFX * CameraFXPtr;
  80. MatrixF mCamFXTrans;
  81. typedef Torque::List<CameraFXPtr> CamFXList;
  82. CamFXList mFXList;
  83. public:
  84. void addFX( CameraFX *newFX );
  85. void removeFX( CameraFX *fx );
  86. void clear();
  87. MatrixF & getTrans(){ return mCamFXTrans; }
  88. void update( F32 dt );
  89. CameraFXManager();
  90. ~CameraFXManager();
  91. };
  92. extern CameraFXManager gCamFXMgr;
  93. #endif