afxCamera.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  23. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  24. // Copyright (C) 2015 Faust Logic, Inc.
  25. //
  26. // afxCamera implements a modified camera for demonstrating a third person camera style
  27. // which is more common to RPG games than the standard FPS style camera. For the most part,
  28. // it is a hybrid of the standard TGE camera and the third person mode of the Advanced Camera
  29. // resource, authored by Thomas "Man of Ice" Lund. This camera implements the bare minimum
  30. // required for demonstrating an RPG style camera and leaves tons of room for improvement.
  31. // It should be replaced with a better camera if possible.
  32. //
  33. // Advanced Camera Resource by Thomas "Man of Ice" Lund:
  34. // http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5471
  35. //
  36. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  37. #ifndef _AFX_CAMERA_H_
  38. #define _AFX_CAMERA_H_
  39. #ifndef _SHAPEBASE_H_
  40. #include "game/shapeBase.h"
  41. #endif
  42. //----------------------------------------------------------------------------
  43. struct afxCameraData: public ShapeBaseData {
  44. typedef ShapeBaseData Parent;
  45. static U32 sCameraCollisionMask;
  46. //
  47. DECLARE_CONOBJECT(afxCameraData);
  48. DECLARE_CATEGORY("AFX");
  49. static void initPersistFields();
  50. virtual void packData(BitStream* stream);
  51. virtual void unpackData(BitStream* stream);
  52. };
  53. //----------------------------------------------------------------------------
  54. // Implements a basic camera object.
  55. class afxCamera: public ShapeBase
  56. {
  57. typedef ShapeBase Parent;
  58. enum MaskBits {
  59. MoveMask = Parent::NextFreeMask,
  60. SubjectMask = Parent::NextFreeMask << 1,
  61. NextFreeMask = Parent::NextFreeMask << 2
  62. };
  63. struct StateDelta {
  64. Point3F pos;
  65. Point3F rot;
  66. VectorF posVec;
  67. VectorF rotVec;
  68. };
  69. enum
  70. {
  71. ThirdPersonMode = 1,
  72. FlyMode = 2,
  73. OrbitObjectMode = 3,
  74. OrbitPointMode = 4,
  75. CameraFirstMode = 0,
  76. CameraLastMode = 4
  77. };
  78. private:
  79. int mMode;
  80. Point3F mRot;
  81. StateDelta mDelta;
  82. SimObjectPtr<GameBase> mOrbitObject;
  83. F32 mMinOrbitDist;
  84. F32 mMaxOrbitDist;
  85. F32 mCurOrbitDist;
  86. Point3F mPosition;
  87. bool mObservingClientObject;
  88. SceneObject* mCam_subject;
  89. Point3F mCam_offset;
  90. Point3F mCoi_offset;
  91. F32 mCam_distance;
  92. F32 mCam_angle;
  93. bool mCam_dirty;
  94. bool mFlymode_saved;
  95. Point3F mFlymode_saved_pos;
  96. S8 mThird_person_snap_c;
  97. S8 mThird_person_snap_s;
  98. void set_cam_pos(const Point3F& pos, const Point3F& viewRot);
  99. void cam_update(F32 dt, bool on_server);
  100. public:
  101. /*C*/ afxCamera();
  102. /*D*/ ~afxCamera();
  103. Point3F& getPosition();
  104. void setFlyMode();
  105. void setOrbitMode(GameBase* obj, Point3F& pos, AngAxisF& rot, F32 minDist, F32 maxDist, F32 curDist, bool ownClientObject);
  106. void validateEyePoint(F32 pos, MatrixF *mat);
  107. GameBase* getOrbitObject() { return(mOrbitObject); }
  108. bool isObservingClientObject() { return(mObservingClientObject); }
  109. void snapToPosition(const Point3F& pos);
  110. void setCameraSubject(SceneObject* subject);
  111. void setThirdPersonOffset(const Point3F& offset);
  112. void setThirdPersonOffset(const Point3F& offset, const Point3F& coi_offset);
  113. const Point3F& getThirdPersonOffset() const { return mCam_offset; }
  114. const Point3F& getThirdPersonCOIOffset() const { return mCoi_offset; }
  115. void setThirdPersonDistance(F32 distance);
  116. F32 getThirdPersonDistance();
  117. void setThirdPersonAngle(F32 angle);
  118. F32 getThirdPersonAngle();
  119. void setThirdPersonMode();
  120. void setThirdPersonSnap();
  121. void setThirdPersonSnapClient();
  122. const char* getMode();
  123. bool isCamera() const { return true; }
  124. DECLARE_CONOBJECT(afxCamera);
  125. DECLARE_CATEGORY("AFX");
  126. private: // 3POV SECTION
  127. void cam_update_3pov(F32 dt, bool on_server);
  128. bool avoid_blocked_view(const Point3F& start, const Point3F& end, Point3F& newpos);
  129. bool test_blocked_line(const Point3F& start, const Point3F& end);
  130. public: // STD OVERRIDES SECTION
  131. virtual bool onAdd();
  132. virtual void onRemove();
  133. virtual void onDeleteNotify(SimObject *obj);
  134. virtual void advanceTime(F32 dt);
  135. virtual void processTick(const Move* move);
  136. virtual void interpolateTick(F32 delta);
  137. virtual void writePacketData(GameConnection *conn, BitStream *stream);
  138. virtual void readPacketData(GameConnection *conn, BitStream *stream);
  139. virtual U32 packUpdate(NetConnection *conn, U32 mask, BitStream *stream);
  140. virtual void unpackUpdate(NetConnection *conn, BitStream *stream);
  141. virtual void onCameraScopeQuery(NetConnection* cr, CameraScopeQuery*);
  142. virtual void getCameraTransform(F32* pos,MatrixF* mat);
  143. virtual void setTransform(const MatrixF& mat);
  144. virtual void onEditorEnable();
  145. virtual void onEditorDisable();
  146. virtual F32 getCameraFov();
  147. virtual F32 getDefaultCameraFov();
  148. virtual bool isValidCameraFov(F32 fov);
  149. virtual void setCameraFov(F32 fov);
  150. virtual F32 getDamageFlash() const;
  151. virtual F32 getWhiteOut() const;
  152. virtual void setControllingClient( GameConnection* connection );
  153. };
  154. #endif // _AFX_CAMERA_H_