llfollowcam.h

Go to the documentation of this file.
00001 
00033 //--------------------------------------------------------------------
00034 // FollowCam
00035 //
00036 // The FollowCam controls three dynamic variables which determine 
00037 // a camera orientation and position for a "loose" third-person view
00038 // (orientation being derived from a combination of focus and up 
00039 // vector). It is good for fast-moving vehicles that change 
00040 // acceleration a lot, but it can also be general-purpose, like for 
00041 // avatar navigation. It has a handful of parameters allowing it to 
00042 // be tweaked to assume different styles of tracking objects.
00043 //
00044 //--------------------------------------------------------------------
00045 #ifndef LL_FOLLOWCAM_H
00046 #define LL_FOLLOWCAM_H
00047 
00048 #include "llcoordframe.h"
00049 #include "indra_constants.h"
00050 #include "llmath.h"
00051 #include "lltimer.h"
00052 #include "llquaternion.h"
00053 #include "llcriticaldamp.h"
00054 #include <map>
00055 #include <vector>
00056 
00057 class LLFollowCamParams
00058 {
00059 public:
00060         LLFollowCamParams();
00061         virtual ~LLFollowCamParams();
00062         
00063         //--------------------------------------
00064         // setty setty set set
00065         //--------------------------------------
00066         virtual void setPositionLag                     ( F32 );
00067         virtual void setFocusLag                        ( F32 );
00068         virtual void setFocusThreshold          ( F32 );
00069         virtual void setPositionThreshold       ( F32 );
00070         virtual void setDistance                        ( F32 );
00071         virtual void setPitch                           ( F32 );
00072         virtual void setFocusOffset                     ( const LLVector3& );
00073         virtual void setBehindnessAngle         ( F32 );
00074         virtual void setBehindnessLag           ( F32 );
00075         virtual void setPosition                        ( const LLVector3& );
00076         virtual void setFocus                           ( const LLVector3& );
00077         virtual void setPositionLocked          ( bool );
00078         virtual void setFocusLocked                     ( bool );
00079 
00080 
00081         //--------------------------------------
00082         // getty getty get get
00083         //--------------------------------------
00084         virtual F32                     getPositionLag() const;
00085         virtual F32                     getFocusLag() const;
00086         virtual F32                     getPositionThreshold() const;
00087         virtual F32                     getFocusThreshold() const;
00088         virtual F32                     getDistance() const;
00089         virtual F32                     getPitch() const;
00090         virtual LLVector3       getFocusOffset() const;
00091         virtual F32                     getBehindnessAngle() const;
00092         virtual F32                     getBehindnessLag() const;
00093         virtual LLVector3       getPosition() const;
00094         virtual LLVector3       getFocus() const;
00095         virtual bool            getFocusLocked() const;
00096         virtual bool            getPositionLocked() const;
00097         virtual bool            getUseFocus() const { return mUseFocus; }
00098         virtual bool            getUsePosition() const { return mUsePosition; }
00099 
00100 protected:
00101         F32             mPositionLag;
00102         F32             mFocusLag;
00103         F32             mFocusThreshold;
00104         F32             mPositionThreshold;
00105         F32             mDistance;      
00106         F32             mPitch;
00107         LLVector3       mFocusOffset;
00108         F32             mBehindnessMaxAngle;
00109         F32             mBehindnessLag;
00110         F32             mMaxCameraDistantFromSubject;
00111 
00112         bool                    mPositionLocked;
00113         bool                    mFocusLocked;
00114         bool                    mUsePosition; // specific camera point specified by script
00115         bool                    mUseFocus; // specific focus point specified by script
00116         LLVector3               mPosition;                      // where the camera is (in world-space)
00117         LLVector3               mFocus;                         // what the camera is aimed at (in world-space)
00118 };
00119 
00120 class LLFollowCam : public LLFollowCamParams
00121 {
00122 public:
00123         //--------------------
00124         // Contructor
00125         //--------------------
00126         LLFollowCam();
00127 
00128         //--------------------
00129         // Destructor
00130         //--------------------
00131         virtual ~LLFollowCam();
00132 
00133         //---------------------------------------------------------------------------------------
00134         // The following methods must be called every time step. However, if you know for 
00135         // sure that your  subject matter (what the camera is looking at) is not moving, 
00136         // then you can get away with not calling "update" But keep in mind that "update" 
00137         // may still be needed after the subject matter has stopped moving because the 
00138         // camera may still need to animate itself catching up to its ideal resting place. 
00139         //---------------------------------------------------------------------------------------
00140         void setSubjectPositionAndRotation      ( const LLVector3 p, const LLQuaternion r );
00141         void update();
00142 
00143         // initialize from another instance of llfollowcamparams
00144         void copyParams(LLFollowCamParams& params);
00145 
00146         //-----------------------------------------------------------------------------------
00147         // this is how to bang the followCam into a specific configuration. Keep in mind 
00148         // that it will immediately try to adjust these values according to its attributes. 
00149         //-----------------------------------------------------------------------------------
00150         void reset( const LLVector3 position, const LLVector3 focus, const LLVector3 upVector );
00151 
00152         void setMaxCameraDistantFromSubject     ( F32 m ); // this should be determined by llAgent
00153         bool isZoomedToMinimumDistance();
00154         LLVector3       getUpVector();
00155         void zoom( S32 );
00156 
00157         // overrides for setters and getters
00158         virtual void setPitch( F32 );
00159         virtual void setDistance( F32 );
00160         virtual void setPosition(const LLVector3& pos);
00161         virtual void setFocus(const LLVector3& focus);
00162         virtual void setPositionLocked          ( bool );
00163         virtual void setFocusLocked                     ( bool );
00164 
00165         LLVector3       getSimulatedPosition() const;
00166         LLVector3       getSimulatedFocus() const;
00167 
00168         //------------------------------------------
00169         // protected members of FollowCam
00170         //------------------------------------------
00171 protected:
00172         F32             mPositionLagTimeScale;          // derived from mPositionLag
00173         F32             mFocusLagTimeScale;                     // derived from mFocusLag
00174         F32             mPitchCos;                                      // derived from mPitch
00175         F32             mPitchSin;                                      // derived from mPitch
00176         LLGlobalVec             mSimulatedPositionGlobal;               // where the camera is (global coordinates), simulated
00177         LLGlobalVec             mSimulatedFocusGlobal;          // what the camera is aimed at (global coordinates), simulated
00178         F32                             mSimulatedDistance;
00179 
00180         //---------------------
00181         // dynamic variables
00182         //---------------------
00183         bool                    mZoomedToMinimumDistance;
00184         LLFrameTimer    mTimer;
00185         LLVector3               mSubjectPosition;       // this is the position of what I'm looking at
00186         LLQuaternion    mSubjectRotation;       // this is the rotation of what I'm looking at
00187         LLVector3               mUpVector;                      // the camera's up vector in world-space (determines roll)
00188         LLVector3               mRelativeFocus;
00189         LLVector3               mRelativePos;
00190 
00191         bool mPitchSineAndCosineNeedToBeUpdated;
00192 
00193         //------------------------------------------
00194         // protected methods of FollowCam
00195         //------------------------------------------
00196 protected:
00197                 void    calculatePitchSineAndCosine();
00198                 BOOL    updateBehindnessConstraint(LLVector3 focus, LLVector3& cam_position);
00199 
00200 };// end of FollowCam class
00201 
00202 
00203 class LLFollowCamMgr
00204 {
00205 public:
00206         static void cleanupClass                        ( );
00207         
00208         static void setPositionLag                      ( const LLUUID& source, F32 lag);
00209         static void setFocusLag                         ( const LLUUID& source, F32 lag);
00210         static void setFocusThreshold           ( const LLUUID& source, F32 threshold);
00211         static void setPositionThreshold        ( const LLUUID& source, F32 threshold);
00212         static void setDistance                         ( const LLUUID& source, F32 distance);
00213         static void setPitch                            ( const LLUUID& source, F32 pitch);
00214         static void setFocusOffset                      ( const LLUUID& source, const LLVector3& offset);
00215         static void setBehindnessAngle          ( const LLUUID& source, F32 angle);
00216         static void setBehindnessLag            ( const LLUUID& source, F32 lag);
00217         static void setPosition                         ( const LLUUID& source, const LLVector3 position);
00218         static void setFocus                            ( const LLUUID& source, const LLVector3 focus);
00219         static void setPositionLocked           ( const LLUUID& source, bool locked);
00220         static void setFocusLocked                      ( const LLUUID& source, bool locked );
00221 
00222         static void setCameraActive                     ( const LLUUID& source, bool active );
00223 
00224         static LLFollowCamParams* getActiveFollowCamParams();
00225         static LLFollowCamParams* getParamsForID(const LLUUID& source);
00226         static void removeFollowCamParams(const LLUUID& source);
00227         static bool isScriptedCameraSource(const LLUUID& source);
00228         static void dump();
00229 
00230 protected:
00231 
00232         typedef std::map<LLUUID, LLFollowCamParams*> param_map_t;
00233         static param_map_t sParamMap;
00234 
00235         typedef std::vector<LLFollowCamParams*> param_stack_t;
00236         static param_stack_t sParamStack;
00237 };
00238 
00239 #endif //LL_FOLLOWCAM_H

Generated on Thu Jul 1 06:08:38 2010 for Second Life Viewer by  doxygen 1.4.7