pathCamera.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 _PATHCAMERA_H_
  23. #define _PATHCAMERA_H_
  24. #ifndef _SHAPEBASE_H_
  25. #include "T3D/shapeBase.h"
  26. #endif
  27. #ifndef _CAMERASPLINE_H_
  28. #include "T3D/cameraSpline.h"
  29. #endif
  30. //----------------------------------------------------------------------------
  31. struct PathCameraData: public ShapeBaseData {
  32. typedef ShapeBaseData Parent;
  33. //
  34. DECLARE_CONOBJECT(PathCameraData);
  35. static void consoleInit();
  36. static void initPersistFields();
  37. virtual void packData(BitStream* stream);
  38. virtual void unpackData(BitStream* stream);
  39. };
  40. //----------------------------------------------------------------------------
  41. class PathCamera: public ShapeBase
  42. {
  43. public:
  44. enum State {
  45. Forward,
  46. Backward,
  47. Stop,
  48. StateBits = 3
  49. };
  50. private:
  51. typedef ShapeBase Parent;
  52. enum MaskBits {
  53. WindowMask = Parent::NextFreeMask,
  54. PositionMask = Parent::NextFreeMask + 1,
  55. TargetMask = Parent::NextFreeMask + 2,
  56. StateMask = Parent::NextFreeMask + 3,
  57. NextFreeMask = Parent::NextFreeMask << 1
  58. };
  59. struct StateDelta {
  60. F32 time;
  61. F32 timeVec;
  62. };
  63. StateDelta delta;
  64. enum Constants {
  65. NodeWindow = 128 // Maximum number of active nodes
  66. };
  67. //
  68. PathCameraData* mDataBlock;
  69. CameraSpline mSpline;
  70. S32 mNodeBase;
  71. S32 mNodeCount;
  72. F32 mPosition;
  73. S32 mState;
  74. F32 mTarget;
  75. bool mTargetSet;
  76. void interpolateMat(F32 pos,MatrixF* mat);
  77. void advancePosition(S32 ms);
  78. public:
  79. DECLARE_CONOBJECT(PathCamera);
  80. DECLARE_CALLBACK( void, onNode, (S32 node));
  81. PathCamera();
  82. ~PathCamera();
  83. static void initPersistFields();
  84. static void consoleInit();
  85. void onEditorEnable();
  86. void onEditorDisable();
  87. bool onAdd();
  88. void onRemove();
  89. bool onNewDataBlock( GameBaseData *dptr, bool reload );
  90. void onNode(S32 node);
  91. void processTick(const Move*);
  92. void interpolateTick(F32 dt);
  93. void getCameraTransform(F32* pos,MatrixF* mat);
  94. U32 packUpdate(NetConnection *, U32 mask, BitStream *stream);
  95. void unpackUpdate(NetConnection *, BitStream *stream);
  96. void reset(F32 speed = 1);
  97. void pushFront(CameraSpline::Knot *knot);
  98. void pushBack(CameraSpline::Knot *knot);
  99. void popFront();
  100. void setPosition(F32 pos);
  101. void setTarget(F32 pos);
  102. void setState(State s);
  103. };
  104. #endif