/indra/newview/llfollowcam.h

https://bitbucket.org/lindenlab/viewer-beta/ · C++ Header · 232 lines · 130 code · 30 blank · 72 comment · 0 complexity · d8ebf0b8a20eff1aca8195008410d329 MD5 · raw file

  1. /**
  2. * @file llfollowcam.h
  3. * @author Jeffrey Ventrella
  4. * @brief LLFollowCam class definition
  5. *
  6. * $LicenseInfo:firstyear=2005&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. //--------------------------------------------------------------------
  28. // FollowCam
  29. //
  30. // The FollowCam controls three dynamic variables which determine
  31. // a camera orientation and position for a "loose" third-person view
  32. // (orientation being derived from a combination of focus and up
  33. // vector). It is good for fast-moving vehicles that change
  34. // acceleration a lot, but it can also be general-purpose, like for
  35. // avatar navigation. It has a handful of parameters allowing it to
  36. // be tweaked to assume different styles of tracking objects.
  37. //
  38. //--------------------------------------------------------------------
  39. #ifndef LL_FOLLOWCAM_H
  40. #define LL_FOLLOWCAM_H
  41. #include "llcoordframe.h"
  42. #include "indra_constants.h"
  43. #include "llmath.h"
  44. #include "lltimer.h"
  45. #include "llquaternion.h"
  46. #include "llcriticaldamp.h"
  47. #include <map>
  48. #include <vector>
  49. class LLFollowCamParams
  50. {
  51. public:
  52. LLFollowCamParams();
  53. virtual ~LLFollowCamParams();
  54. //--------------------------------------
  55. // setty setty set set
  56. //--------------------------------------
  57. virtual void setPositionLag ( F32 );
  58. virtual void setFocusLag ( F32 );
  59. virtual void setFocusThreshold ( F32 );
  60. virtual void setPositionThreshold ( F32 );
  61. virtual void setDistance ( F32 );
  62. virtual void setPitch ( F32 );
  63. virtual void setFocusOffset ( const LLVector3& );
  64. virtual void setBehindnessAngle ( F32 );
  65. virtual void setBehindnessLag ( F32 );
  66. virtual void setPosition ( const LLVector3& );
  67. virtual void setFocus ( const LLVector3& );
  68. virtual void setPositionLocked ( bool );
  69. virtual void setFocusLocked ( bool );
  70. //--------------------------------------
  71. // getty getty get get
  72. //--------------------------------------
  73. virtual F32 getPositionLag() const;
  74. virtual F32 getFocusLag() const;
  75. virtual F32 getPositionThreshold() const;
  76. virtual F32 getFocusThreshold() const;
  77. virtual F32 getDistance() const;
  78. virtual F32 getPitch() const;
  79. virtual LLVector3 getFocusOffset() const;
  80. virtual F32 getBehindnessAngle() const;
  81. virtual F32 getBehindnessLag() const;
  82. virtual LLVector3 getPosition() const;
  83. virtual LLVector3 getFocus() const;
  84. virtual bool getFocusLocked() const;
  85. virtual bool getPositionLocked() const;
  86. virtual bool getUseFocus() const { return mUseFocus; }
  87. virtual bool getUsePosition() const { return mUsePosition; }
  88. protected:
  89. F32 mPositionLag;
  90. F32 mFocusLag;
  91. F32 mFocusThreshold;
  92. F32 mPositionThreshold;
  93. F32 mDistance;
  94. F32 mPitch;
  95. LLVector3 mFocusOffset;
  96. F32 mBehindnessMaxAngle;
  97. F32 mBehindnessLag;
  98. F32 mMaxCameraDistantFromSubject;
  99. bool mPositionLocked;
  100. bool mFocusLocked;
  101. bool mUsePosition; // specific camera point specified by script
  102. bool mUseFocus; // specific focus point specified by script
  103. LLVector3 mPosition; // where the camera is (in world-space)
  104. LLVector3 mFocus; // what the camera is aimed at (in world-space)
  105. };
  106. class LLFollowCam : public LLFollowCamParams
  107. {
  108. public:
  109. //--------------------
  110. // Contructor
  111. //--------------------
  112. LLFollowCam();
  113. //--------------------
  114. // Destructor
  115. //--------------------
  116. virtual ~LLFollowCam();
  117. //---------------------------------------------------------------------------------------
  118. // The following methods must be called every time step. However, if you know for
  119. // sure that your subject matter (what the camera is looking at) is not moving,
  120. // then you can get away with not calling "update" But keep in mind that "update"
  121. // may still be needed after the subject matter has stopped moving because the
  122. // camera may still need to animate itself catching up to its ideal resting place.
  123. //---------------------------------------------------------------------------------------
  124. void setSubjectPositionAndRotation ( const LLVector3 p, const LLQuaternion r );
  125. void update();
  126. // initialize from another instance of llfollowcamparams
  127. void copyParams(LLFollowCamParams& params);
  128. //-----------------------------------------------------------------------------------
  129. // this is how to bang the followCam into a specific configuration. Keep in mind
  130. // that it will immediately try to adjust these values according to its attributes.
  131. //-----------------------------------------------------------------------------------
  132. void reset( const LLVector3 position, const LLVector3 focus, const LLVector3 upVector );
  133. void setMaxCameraDistantFromSubject ( F32 m ); // this should be determined by llAgent
  134. bool isZoomedToMinimumDistance();
  135. LLVector3 getUpVector();
  136. void zoom( S32 );
  137. // overrides for setters and getters
  138. virtual void setPitch( F32 );
  139. virtual void setDistance( F32 );
  140. virtual void setPosition(const LLVector3& pos);
  141. virtual void setFocus(const LLVector3& focus);
  142. virtual void setPositionLocked ( bool );
  143. virtual void setFocusLocked ( bool );
  144. LLVector3 getSimulatedPosition() const;
  145. LLVector3 getSimulatedFocus() const;
  146. //------------------------------------------
  147. // protected members of FollowCam
  148. //------------------------------------------
  149. protected:
  150. F32 mPitchCos; // derived from mPitch
  151. F32 mPitchSin; // derived from mPitch
  152. LLGlobalVec mSimulatedPositionGlobal; // where the camera is (global coordinates), simulated
  153. LLGlobalVec mSimulatedFocusGlobal; // what the camera is aimed at (global coordinates), simulated
  154. F32 mSimulatedDistance;
  155. //---------------------
  156. // dynamic variables
  157. //---------------------
  158. bool mZoomedToMinimumDistance;
  159. LLFrameTimer mTimer;
  160. LLVector3 mSubjectPosition; // this is the position of what I'm looking at
  161. LLQuaternion mSubjectRotation; // this is the rotation of what I'm looking at
  162. LLVector3 mUpVector; // the camera's up vector in world-space (determines roll)
  163. LLVector3 mRelativeFocus;
  164. LLVector3 mRelativePos;
  165. bool mPitchSineAndCosineNeedToBeUpdated;
  166. //------------------------------------------
  167. // protected methods of FollowCam
  168. //------------------------------------------
  169. protected:
  170. void calculatePitchSineAndCosine();
  171. BOOL updateBehindnessConstraint(LLVector3 focus, LLVector3& cam_position);
  172. };// end of FollowCam class
  173. class LLFollowCamMgr
  174. {
  175. public:
  176. static void cleanupClass ( );
  177. static void setPositionLag ( const LLUUID& source, F32 lag);
  178. static void setFocusLag ( const LLUUID& source, F32 lag);
  179. static void setFocusThreshold ( const LLUUID& source, F32 threshold);
  180. static void setPositionThreshold ( const LLUUID& source, F32 threshold);
  181. static void setDistance ( const LLUUID& source, F32 distance);
  182. static void setPitch ( const LLUUID& source, F32 pitch);
  183. static void setFocusOffset ( const LLUUID& source, const LLVector3& offset);
  184. static void setBehindnessAngle ( const LLUUID& source, F32 angle);
  185. static void setBehindnessLag ( const LLUUID& source, F32 lag);
  186. static void setPosition ( const LLUUID& source, const LLVector3 position);
  187. static void setFocus ( const LLUUID& source, const LLVector3 focus);
  188. static void setPositionLocked ( const LLUUID& source, bool locked);
  189. static void setFocusLocked ( const LLUUID& source, bool locked );
  190. static void setCameraActive ( const LLUUID& source, bool active );
  191. static LLFollowCamParams* getActiveFollowCamParams();
  192. static LLFollowCamParams* getParamsForID(const LLUUID& source);
  193. static void removeFollowCamParams(const LLUUID& source);
  194. static bool isScriptedCameraSource(const LLUUID& source);
  195. static void dump();
  196. protected:
  197. typedef std::map<LLUUID, LLFollowCamParams*> param_map_t;
  198. static param_map_t sParamMap;
  199. typedef std::vector<LLFollowCamParams*> param_stack_t;
  200. static param_stack_t sParamStack;
  201. };
  202. #endif //LL_FOLLOWCAM_H