/indra/newview/llfollowcam.h
C++ Header | 232 lines | 130 code | 30 blank | 72 comment | 0 complexity | d8ebf0b8a20eff1aca8195008410d329 MD5 | raw file
Possible License(s): LGPL-2.1
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//-------------------------------------------------------------------- 29// FollowCam 30// 31// The FollowCam controls three dynamic variables which determine 32// a camera orientation and position for a "loose" third-person view 33// (orientation being derived from a combination of focus and up 34// vector). It is good for fast-moving vehicles that change 35// acceleration a lot, but it can also be general-purpose, like for 36// avatar navigation. It has a handful of parameters allowing it to 37// be tweaked to assume different styles of tracking objects. 38// 39//-------------------------------------------------------------------- 40#ifndef LL_FOLLOWCAM_H 41#define LL_FOLLOWCAM_H 42 43#include "llcoordframe.h" 44#include "indra_constants.h" 45#include "llmath.h" 46#include "lltimer.h" 47#include "llquaternion.h" 48#include "llcriticaldamp.h" 49#include <map> 50#include <vector> 51 52class LLFollowCamParams 53{ 54public: 55 LLFollowCamParams(); 56 virtual ~LLFollowCamParams(); 57 58 //-------------------------------------- 59 // setty setty set set 60 //-------------------------------------- 61 virtual void setPositionLag ( F32 ); 62 virtual void setFocusLag ( F32 ); 63 virtual void setFocusThreshold ( F32 ); 64 virtual void setPositionThreshold ( F32 ); 65 virtual void setDistance ( F32 ); 66 virtual void setPitch ( F32 ); 67 virtual void setFocusOffset ( const LLVector3& ); 68 virtual void setBehindnessAngle ( F32 ); 69 virtual void setBehindnessLag ( F32 ); 70 virtual void setPosition ( const LLVector3& ); 71 virtual void setFocus ( const LLVector3& ); 72 virtual void setPositionLocked ( bool ); 73 virtual void setFocusLocked ( bool ); 74 75 76 //-------------------------------------- 77 // getty getty get get 78 //-------------------------------------- 79 virtual F32 getPositionLag() const; 80 virtual F32 getFocusLag() const; 81 virtual F32 getPositionThreshold() const; 82 virtual F32 getFocusThreshold() const; 83 virtual F32 getDistance() const; 84 virtual F32 getPitch() const; 85 virtual LLVector3 getFocusOffset() const; 86 virtual F32 getBehindnessAngle() const; 87 virtual F32 getBehindnessLag() const; 88 virtual LLVector3 getPosition() const; 89 virtual LLVector3 getFocus() const; 90 virtual bool getFocusLocked() const; 91 virtual bool getPositionLocked() const; 92 virtual bool getUseFocus() const { return mUseFocus; } 93 virtual bool getUsePosition() const { return mUsePosition; } 94 95protected: 96 F32 mPositionLag; 97 F32 mFocusLag; 98 F32 mFocusThreshold; 99 F32 mPositionThreshold; 100 F32 mDistance; 101 F32 mPitch; 102 LLVector3 mFocusOffset; 103 F32 mBehindnessMaxAngle; 104 F32 mBehindnessLag; 105 F32 mMaxCameraDistantFromSubject; 106 107 bool mPositionLocked; 108 bool mFocusLocked; 109 bool mUsePosition; // specific camera point specified by script 110 bool mUseFocus; // specific focus point specified by script 111 LLVector3 mPosition; // where the camera is (in world-space) 112 LLVector3 mFocus; // what the camera is aimed at (in world-space) 113}; 114 115class LLFollowCam : public LLFollowCamParams 116{ 117public: 118 //-------------------- 119 // Contructor 120 //-------------------- 121 LLFollowCam(); 122 123 //-------------------- 124 // Destructor 125 //-------------------- 126 virtual ~LLFollowCam(); 127 128 //--------------------------------------------------------------------------------------- 129 // The following methods must be called every time step. However, if you know for 130 // sure that your subject matter (what the camera is looking at) is not moving, 131 // then you can get away with not calling "update" But keep in mind that "update" 132 // may still be needed after the subject matter has stopped moving because the 133 // camera may still need to animate itself catching up to its ideal resting place. 134 //--------------------------------------------------------------------------------------- 135 void setSubjectPositionAndRotation ( const LLVector3 p, const LLQuaternion r ); 136 void update(); 137 138 // initialize from another instance of llfollowcamparams 139 void copyParams(LLFollowCamParams& params); 140 141 //----------------------------------------------------------------------------------- 142 // this is how to bang the followCam into a specific configuration. Keep in mind 143 // that it will immediately try to adjust these values according to its attributes. 144 //----------------------------------------------------------------------------------- 145 void reset( const LLVector3 position, const LLVector3 focus, const LLVector3 upVector ); 146 147 void setMaxCameraDistantFromSubject ( F32 m ); // this should be determined by llAgent 148 bool isZoomedToMinimumDistance(); 149 LLVector3 getUpVector(); 150 void zoom( S32 ); 151 152 // overrides for setters and getters 153 virtual void setPitch( F32 ); 154 virtual void setDistance( F32 ); 155 virtual void setPosition(const LLVector3& pos); 156 virtual void setFocus(const LLVector3& focus); 157 virtual void setPositionLocked ( bool ); 158 virtual void setFocusLocked ( bool ); 159 160 LLVector3 getSimulatedPosition() const; 161 LLVector3 getSimulatedFocus() const; 162 163 //------------------------------------------ 164 // protected members of FollowCam 165 //------------------------------------------ 166protected: 167 F32 mPitchCos; // derived from mPitch 168 F32 mPitchSin; // derived from mPitch 169 LLGlobalVec mSimulatedPositionGlobal; // where the camera is (global coordinates), simulated 170 LLGlobalVec mSimulatedFocusGlobal; // what the camera is aimed at (global coordinates), simulated 171 F32 mSimulatedDistance; 172 173 //--------------------- 174 // dynamic variables 175 //--------------------- 176 bool mZoomedToMinimumDistance; 177 LLFrameTimer mTimer; 178 LLVector3 mSubjectPosition; // this is the position of what I'm looking at 179 LLQuaternion mSubjectRotation; // this is the rotation of what I'm looking at 180 LLVector3 mUpVector; // the camera's up vector in world-space (determines roll) 181 LLVector3 mRelativeFocus; 182 LLVector3 mRelativePos; 183 184 bool mPitchSineAndCosineNeedToBeUpdated; 185 186 //------------------------------------------ 187 // protected methods of FollowCam 188 //------------------------------------------ 189protected: 190 void calculatePitchSineAndCosine(); 191 BOOL updateBehindnessConstraint(LLVector3 focus, LLVector3& cam_position); 192 193};// end of FollowCam class 194 195 196class LLFollowCamMgr 197{ 198public: 199 static void cleanupClass ( ); 200 201 static void setPositionLag ( const LLUUID& source, F32 lag); 202 static void setFocusLag ( const LLUUID& source, F32 lag); 203 static void setFocusThreshold ( const LLUUID& source, F32 threshold); 204 static void setPositionThreshold ( const LLUUID& source, F32 threshold); 205 static void setDistance ( const LLUUID& source, F32 distance); 206 static void setPitch ( const LLUUID& source, F32 pitch); 207 static void setFocusOffset ( const LLUUID& source, const LLVector3& offset); 208 static void setBehindnessAngle ( const LLUUID& source, F32 angle); 209 static void setBehindnessLag ( const LLUUID& source, F32 lag); 210 static void setPosition ( const LLUUID& source, const LLVector3 position); 211 static void setFocus ( const LLUUID& source, const LLVector3 focus); 212 static void setPositionLocked ( const LLUUID& source, bool locked); 213 static void setFocusLocked ( const LLUUID& source, bool locked ); 214 215 static void setCameraActive ( const LLUUID& source, bool active ); 216 217 static LLFollowCamParams* getActiveFollowCamParams(); 218 static LLFollowCamParams* getParamsForID(const LLUUID& source); 219 static void removeFollowCamParams(const LLUUID& source); 220 static bool isScriptedCameraSource(const LLUUID& source); 221 static void dump(); 222 223protected: 224 225 typedef std::map<LLUUID, LLFollowCamParams*> param_map_t; 226 static param_map_t sParamMap; 227 228 typedef std::vector<LLFollowCamParams*> param_stack_t; 229 static param_stack_t sParamStack; 230}; 231 232#endif //LL_FOLLOWCAM_H