afxCamera.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. static void initPersistFields();
  49. void packData(BitStream* stream) override;
  50. void unpackData(BitStream* stream) override;
  51. };
  52. //----------------------------------------------------------------------------
  53. // Implements a basic camera object.
  54. class afxCamera: public ShapeBase
  55. {
  56. typedef ShapeBase Parent;
  57. enum MaskBits {
  58. MoveMask = Parent::NextFreeMask,
  59. SubjectMask = Parent::NextFreeMask << 1,
  60. NextFreeMask = Parent::NextFreeMask << 2
  61. };
  62. struct StateDelta {
  63. Point3F pos;
  64. Point3F rot;
  65. VectorF posVec;
  66. VectorF rotVec;
  67. };
  68. enum
  69. {
  70. ThirdPersonMode = 1,
  71. FlyMode = 2,
  72. OrbitObjectMode = 3,
  73. OrbitPointMode = 4,
  74. CameraFirstMode = 0,
  75. CameraLastMode = 4
  76. };
  77. private:
  78. int mMode;
  79. Point3F mRot;
  80. StateDelta mDelta;
  81. SimObjectPtr<GameBase> mOrbitObject;
  82. F32 mMinOrbitDist;
  83. F32 mMaxOrbitDist;
  84. F32 mCurOrbitDist;
  85. Point3F mPosition;
  86. bool mObservingClientObject;
  87. SceneObject* mCam_subject;
  88. Point3F mCam_offset;
  89. Point3F mCoi_offset;
  90. F32 mCam_distance;
  91. F32 mCam_angle;
  92. bool mCam_dirty;
  93. bool mFlymode_saved;
  94. Point3F mFlymode_saved_pos;
  95. S8 mThird_person_snap_c;
  96. S8 mThird_person_snap_s;
  97. void set_cam_pos(const Point3F& pos, const Point3F& viewRot);
  98. void cam_update(F32 dt, bool on_server);
  99. public:
  100. /*C*/ afxCamera();
  101. /*D*/ ~afxCamera();
  102. Point3F& getPosition();
  103. void setFlyMode();
  104. void setOrbitMode(GameBase* obj, Point3F& pos, AngAxisF& rot, F32 minDist, F32 maxDist, F32 curDist, bool ownClientObject);
  105. void validateEyePoint(F32 pos, MatrixF *mat);
  106. GameBase* getOrbitObject() { return(mOrbitObject); }
  107. bool isObservingClientObject() { return(mObservingClientObject); }
  108. void snapToPosition(const Point3F& pos);
  109. void setCameraSubject(SceneObject* subject);
  110. void setThirdPersonOffset(const Point3F& offset);
  111. void setThirdPersonOffset(const Point3F& offset, const Point3F& coi_offset);
  112. const Point3F& getThirdPersonOffset() const { return mCam_offset; }
  113. const Point3F& getThirdPersonCOIOffset() const { return mCoi_offset; }
  114. void setThirdPersonDistance(F32 distance);
  115. F32 getThirdPersonDistance();
  116. void setThirdPersonAngle(F32 angle);
  117. F32 getThirdPersonAngle();
  118. void setThirdPersonMode();
  119. void setThirdPersonSnap();
  120. void setThirdPersonSnapClient();
  121. const char* getMode();
  122. bool isCamera() const override { return true; }
  123. DECLARE_CONOBJECT(afxCamera);
  124. DECLARE_CATEGORY("UNLISTED");
  125. private: // 3POV SECTION
  126. void cam_update_3pov(F32 dt, bool on_server);
  127. bool avoid_blocked_view(const Point3F& start, const Point3F& end, Point3F& newpos);
  128. bool test_blocked_line(const Point3F& start, const Point3F& end);
  129. public: // STD OVERRIDES SECTION
  130. bool onAdd() override;
  131. void onRemove() override;
  132. void onDeleteNotify(SimObject *obj) override;
  133. void advanceTime(F32 dt) override;
  134. void processTick(const Move* move) override;
  135. void interpolateTick(F32 delta) override;
  136. void writePacketData(GameConnection *conn, BitStream *stream) override;
  137. void readPacketData(GameConnection *conn, BitStream *stream) override;
  138. U32 packUpdate(NetConnection *conn, U32 mask, BitStream *stream) override;
  139. void unpackUpdate(NetConnection *conn, BitStream *stream) override;
  140. void onCameraScopeQuery(NetConnection* cr, CameraScopeQuery*) override;
  141. void getCameraTransform(F32* pos,MatrixF* mat) override;
  142. void setTransform(const MatrixF& mat) override;
  143. void onEditorEnable() override;
  144. void onEditorDisable() override;
  145. F32 getCameraFov() override;
  146. F32 getDefaultCameraFov() override;
  147. bool isValidCameraFov(F32 fov) override;
  148. void setCameraFov(F32 fov) override;
  149. F32 getDamageFlash() const override;
  150. F32 getWhiteOut() const override;
  151. void setControllingClient( GameConnection* connection ) override;
  152. };
  153. #endif // _AFX_CAMERA_H_