PageRenderTime 42ms CodeModel.GetById 15ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llagentcamera.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 394 lines | 247 code | 45 blank | 102 comment | 10 complexity | f9ed6c21b333c1e245778706e46f5337 MD5 | raw file
  1/** 
  2 * @file llagent.h
  3 * @brief LLAgent class header file
  4 *
  5 * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLAGENTCAMERA_H
 28#define LL_LLAGENTCAMERA_H
 29
 30#include "llfollowcam.h" 			// Ventrella
 31#include "llhudeffectlookat.h" 		// EPointAtType
 32#include "llhudeffectpointat.h" 	// ELookAtType
 33
 34class LLPickInfo;
 35class LLVOAvatarSelf;
 36class LLControlVariable;
 37
 38//--------------------------------------------------------------------
 39// Types
 40//--------------------------------------------------------------------
 41enum ECameraMode
 42{
 43	CAMERA_MODE_THIRD_PERSON,
 44	CAMERA_MODE_MOUSELOOK,
 45	CAMERA_MODE_CUSTOMIZE_AVATAR,
 46	CAMERA_MODE_FOLLOW
 47};
 48
 49/** Camera Presets for CAMERA_MODE_THIRD_PERSON */
 50enum ECameraPreset 
 51{
 52	/** Default preset, what the Third Person Mode actually was */
 53	CAMERA_PRESET_REAR_VIEW,
 54	
 55	/** "Looking at the Avatar from the front" */
 56	CAMERA_PRESET_FRONT_VIEW, 
 57
 58	/** "Above and to the left, over the shoulder, pulled back a little on the zoom" */
 59	CAMERA_PRESET_GROUP_VIEW
 60};
 61
 62//------------------------------------------------------------------------
 63// LLAgentCamera
 64//------------------------------------------------------------------------
 65class LLAgentCamera
 66{
 67	LOG_CLASS(LLAgentCamera);
 68
 69public:
 70	//--------------------------------------------------------------------
 71	// Constructors / Destructors
 72	//--------------------------------------------------------------------
 73public:
 74	LLAgentCamera();
 75	virtual 		~LLAgentCamera();
 76	void			init();
 77	void			cleanup();
 78	void		    setAvatarObject(LLVOAvatarSelf* avatar);
 79	bool			isInitialized() { return mInitialized; }
 80private:
 81	bool			mInitialized;
 82
 83
 84	//--------------------------------------------------------------------
 85	// Mode
 86	//--------------------------------------------------------------------
 87public:
 88	void			changeCameraToDefault();
 89	void			changeCameraToMouselook(BOOL animate = TRUE);
 90	void			changeCameraToThirdPerson(BOOL animate = TRUE);
 91	void			changeCameraToCustomizeAvatar(); // Trigger transition animation
 92	void			changeCameraToFollow(BOOL animate = TRUE); 	// Ventrella
 93	BOOL			cameraThirdPerson() const		{ return (mCameraMode == CAMERA_MODE_THIRD_PERSON && mLastCameraMode == CAMERA_MODE_THIRD_PERSON); }
 94	BOOL			cameraMouselook() const			{ return (mCameraMode == CAMERA_MODE_MOUSELOOK && mLastCameraMode == CAMERA_MODE_MOUSELOOK); }
 95	BOOL			cameraCustomizeAvatar() const	{ return (mCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR /*&& !mCameraAnimating*/); }
 96	BOOL			cameraFollow() const			{ return (mCameraMode == CAMERA_MODE_FOLLOW && mLastCameraMode == CAMERA_MODE_FOLLOW); }
 97	ECameraMode		getCameraMode() const 			{ return mCameraMode; }
 98	ECameraMode		getLastCameraMode() const 		{ return mLastCameraMode; }
 99	void			updateCamera();					// Call once per frame to update camera location/orientation
100	void			resetCamera(); 					// Slam camera into its default position
101	void			updateLastCamera();				// Set last camera to current camera
102
103private:
104	ECameraMode		mCameraMode;					// Target mode after transition animation is done
105	ECameraMode		mLastCameraMode;
106
107	//--------------------------------------------------------------------
108	// Preset
109	//--------------------------------------------------------------------
110public:
111	void switchCameraPreset(ECameraPreset preset);
112private:
113	/** Determines default camera offset depending on the current camera preset */
114	LLVector3 getCameraOffsetInitial();
115
116	/** Camera preset in Third Person Mode */
117	ECameraPreset mCameraPreset; 
118
119	/** Initial camera offsets */
120	std::map<ECameraPreset, LLPointer<LLControlVariable> > mCameraOffsetInitial;
121
122	/** Initial focus offsets */
123	std::map<ECameraPreset, LLPointer<LLControlVariable> > mFocusOffsetInitial;
124
125	//--------------------------------------------------------------------
126	// Position
127	//--------------------------------------------------------------------
128public:
129	LLVector3d		getCameraPositionGlobal() const;
130	const LLVector3 &getCameraPositionAgent() const;
131	LLVector3d		calcCameraPositionTargetGlobal(BOOL *hit_limit = NULL); // Calculate the camera position target
132	F32				getCameraMinOffGround(); 		// Minimum height off ground for this mode, meters
133	void			setCameraCollidePlane(const LLVector4 &plane) { mCameraCollidePlane = plane; }
134	BOOL			calcCameraMinDistance(F32 &obj_min_distance);
135	F32				getCurrentCameraBuildOffset() 	{ return (F32)mCameraFocusOffset.length(); }
136	void			clearCameraLag() { mCameraLag.clearVec(); }
137private:
138	F32				mCurrentCameraDistance;	 		// Current camera offset from avatar
139	F32				mTargetCameraDistance;			// Target camera offset from avatar
140	F32				mCameraFOVZoomFactor;			// Amount of fov zoom applied to camera when zeroing in on an object
141	F32				mCameraCurrentFOVZoomFactor;	// Interpolated fov zoom
142	F32				mCameraFOVDefault;				// Default field of view that is basis for FOV zoom effect
143	LLVector4		mCameraCollidePlane;			// Colliding plane for camera
144	F32				mCameraZoomFraction;			// Mousewheel driven fraction of zoom
145	LLVector3		mCameraPositionAgent;			// Camera position in agent coordinates
146	LLVector3		mCameraVirtualPositionAgent;	// Camera virtual position (target) before performing FOV zoom
147	LLVector3d      mCameraSmoothingLastPositionGlobal;    
148	LLVector3d      mCameraSmoothingLastPositionAgent;
149	bool            mCameraSmoothingStop;
150	LLVector3		mCameraLag;						// Third person camera lag
151	LLVector3		mCameraUpVector;				// Camera's up direction in world coordinates (determines the 'roll' of the view)
152
153	//--------------------------------------------------------------------
154	// Follow
155	//--------------------------------------------------------------------
156public:
157	void			setUsingFollowCam(bool using_follow_cam);
158private:
159	LLFollowCam 	mFollowCam; 			// Ventrella
160
161	//--------------------------------------------------------------------
162	// Sit
163	//--------------------------------------------------------------------
164public:
165	void			setupSitCamera();
166	BOOL			sitCameraEnabled() 		{ return mSitCameraEnabled; }
167	void			setSitCamera(const LLUUID &object_id, 
168								 const LLVector3 &camera_pos = LLVector3::zero, const LLVector3 &camera_focus = LLVector3::zero);
169private:
170	LLPointer<LLViewerObject> mSitCameraReferenceObject; // Object to which camera is related when sitting
171	BOOL			mSitCameraEnabled;		// Use provided camera information when sitting?
172	LLVector3		mSitCameraPos;			// Root relative camera pos when sitting
173	LLVector3		mSitCameraFocus;		// Root relative camera target when sitting
174
175	//--------------------------------------------------------------------
176	// Animation
177	//--------------------------------------------------------------------
178public:
179	void			setCameraAnimating(BOOL b)			{ mCameraAnimating = b; }
180	BOOL			getCameraAnimating()				{ return mCameraAnimating; }
181	void			setAnimationDuration(F32 seconds);
182	void			startCameraAnimation();
183	void			stopCameraAnimation();
184private:
185	LLFrameTimer	mAnimationTimer; 	// Seconds that transition animation has been active
186	F32				mAnimationDuration;	// In seconds
187	BOOL			mCameraAnimating;					// Camera is transitioning from one mode to another
188	LLVector3d		mAnimationCameraStartGlobal;		// Camera start position, global coords
189	LLVector3d		mAnimationFocusStartGlobal;			// Camera focus point, global coords
190
191	//--------------------------------------------------------------------
192	// Focus
193	//--------------------------------------------------------------------
194public:
195	LLVector3d		calcFocusPositionTargetGlobal();
196	LLVector3		calcFocusOffset(LLViewerObject *object, LLVector3 pos_agent, S32 x, S32 y);
197	BOOL			getFocusOnAvatar() const		{ return mFocusOnAvatar; }
198	LLPointer<LLViewerObject>&	getFocusObject() 	{ return mFocusObject; }
199	F32				getFocusObjectDist() const		{ return mFocusObjectDist; }
200	void			updateFocusOffset();
201	void			validateFocusObject();
202	void			setFocusGlobal(const LLPickInfo& pick);
203	void			setFocusGlobal(const LLVector3d &focus, const LLUUID &object_id = LLUUID::null);
204	void			setFocusOnAvatar(BOOL focus, BOOL animate);
205	void			setCameraPosAndFocusGlobal(const LLVector3d& pos, const LLVector3d& focus, const LLUUID &object_id);
206	void			clearFocusObject();
207	void			setFocusObject(LLViewerObject* object);
208	void			setObjectTracking(BOOL track) 	{ mTrackFocusObject = track; }
209	const LLVector3d &getFocusGlobal() const		{ return mFocusGlobal; }
210	const LLVector3d &getFocusTargetGlobal() const	{ return mFocusTargetGlobal; }
211private:
212	LLVector3d		mCameraFocusOffset;				// Offset from focus point in build mode
213	LLVector3d		mCameraFocusOffsetTarget;		// Target towards which we are lerping the camera's focus offset
214	BOOL			mFocusOnAvatar;					
215	LLVector3d		mFocusGlobal;
216	LLVector3d		mFocusTargetGlobal;
217	LLPointer<LLViewerObject> mFocusObject;
218	F32				mFocusObjectDist;
219	LLVector3		mFocusObjectOffset;
220	F32				mFocusDotRadius; 				// Meters
221	BOOL			mTrackFocusObject;
222	
223	//--------------------------------------------------------------------
224	// Lookat / Pointat
225	//--------------------------------------------------------------------
226public:
227	void			updateLookAt(const S32 mouse_x, const S32 mouse_y);
228	BOOL			setLookAt(ELookAtType target_type, LLViewerObject *object = NULL, LLVector3 position = LLVector3::zero);
229	ELookAtType		getLookAtType();
230	void			lookAtLastChat();
231	void 			slamLookAt(const LLVector3 &look_at); // Set the physics data
232	BOOL			setPointAt(EPointAtType target_type, LLViewerObject *object = NULL, LLVector3 position = LLVector3::zero);
233	EPointAtType	getPointAtType();
234public:
235	LLPointer<LLHUDEffectLookAt> mLookAt;
236	LLPointer<LLHUDEffectPointAt> mPointAt;
237
238	//--------------------------------------------------------------------
239	// Third person
240	//--------------------------------------------------------------------
241public:
242	LLVector3d		calcThirdPersonFocusOffset();
243	void			setThirdPersonHeadOffset(LLVector3 offset) 	{ mThirdPersonHeadOffset = offset; }	
244private:
245	LLVector3		mThirdPersonHeadOffset;						// Head offset for third person camera position
246
247	//--------------------------------------------------------------------
248	// Orbit
249	//--------------------------------------------------------------------
250public:
251	void			cameraOrbitAround(const F32 radians);	// Rotate camera CCW radians about build focus point
252	void			cameraOrbitOver(const F32 radians);		// Rotate camera forward radians over build focus point
253	void			cameraOrbitIn(const F32 meters);		// Move camera in toward build focus point
254
255	//--------------------------------------------------------------------
256	// Zoom
257	//--------------------------------------------------------------------
258public:
259	void			handleScrollWheel(S32 clicks); 			// Mousewheel driven zoom
260	void			cameraZoomIn(const F32 factor);			// Zoom in by fraction of current distance
261	F32				getCameraZoomFraction();				// Get camera zoom as fraction of minimum and maximum zoom
262	void			setCameraZoomFraction(F32 fraction);	// Set camera zoom as fraction of minimum and maximum zoom
263	F32				calcCameraFOVZoomFactor();
264
265	//--------------------------------------------------------------------
266	// Pan
267	//--------------------------------------------------------------------
268public:
269	void			cameraPanIn(const F32 meters);
270	void			cameraPanLeft(const F32 meters);
271	void			cameraPanUp(const F32 meters);
272	
273	//--------------------------------------------------------------------
274	// View
275	//--------------------------------------------------------------------
276public:
277	// Called whenever the agent moves.  Puts camera back in default position, deselects items, etc.
278	void			resetView(BOOL reset_camera = TRUE, BOOL change_camera = FALSE);
279	// Called on camera movement.  Unlocks camera from the default position behind the avatar.
280	void			unlockView();
281public:
282	F32				mDrawDistance;
283
284	//--------------------------------------------------------------------
285	// Mouselook
286	//--------------------------------------------------------------------
287public:
288	BOOL			getForceMouselook() const 			{ return mForceMouselook; }
289	void			setForceMouselook(BOOL mouselook) 	{ mForceMouselook = mouselook; }
290private:
291	BOOL			mForceMouselook;
292	
293	//--------------------------------------------------------------------
294	// HUD
295	//--------------------------------------------------------------------
296public:
297	F32				mHUDTargetZoom;	// Target zoom level for HUD objects (used when editing)
298	F32				mHUDCurZoom; 	// Current animated zoom level for HUD objects
299
300
301/********************************************************************************
302 **                                                                            **
303 **                    KEYS
304 **/
305
306public:
307	S32				getAtKey() const		{ return mAtKey; }
308	S32				getWalkKey() const		{ return mWalkKey; }
309	S32				getLeftKey() const		{ return mLeftKey; }
310	S32				getUpKey() const		{ return mUpKey; }
311	F32				getYawKey() const		{ return mYawKey; }
312	F32				getPitchKey() const		{ return mPitchKey; }
313
314	void			setAtKey(S32 mag)		{ mAtKey = mag; }
315	void			setWalkKey(S32 mag)		{ mWalkKey = mag; }
316	void			setLeftKey(S32 mag)		{ mLeftKey = mag; }
317	void			setUpKey(S32 mag)		{ mUpKey = mag; }
318	void			setYawKey(F32 mag)		{ mYawKey = mag; }
319	void			setPitchKey(F32 mag)	{ mPitchKey = mag; }
320
321	void			clearGeneralKeys();
322	static S32		directionToKey(S32 direction); // Changes direction to -1/0/1
323
324private:
325	S32 			mAtKey;				// Either 1, 0, or -1. Indicates that movement key is pressed
326	S32				mWalkKey; 			// Like AtKey, but causes less forward thrust
327	S32 			mLeftKey;
328	S32				mUpKey;
329	F32				mYawKey;
330	F32				mPitchKey;
331
332	//--------------------------------------------------------------------
333	// Orbit
334	//--------------------------------------------------------------------
335public:
336	F32				getOrbitLeftKey() const		{ return mOrbitLeftKey; }
337	F32				getOrbitRightKey() const	{ return mOrbitRightKey; }
338	F32				getOrbitUpKey() const		{ return mOrbitUpKey; }
339	F32				getOrbitDownKey() const		{ return mOrbitDownKey; }
340	F32				getOrbitInKey() const		{ return mOrbitInKey; }
341	F32				getOrbitOutKey() const		{ return mOrbitOutKey; }
342
343	void			setOrbitLeftKey(F32 mag)	{ mOrbitLeftKey = mag; }
344	void			setOrbitRightKey(F32 mag)	{ mOrbitRightKey = mag; }
345	void			setOrbitUpKey(F32 mag)		{ mOrbitUpKey = mag; }
346	void			setOrbitDownKey(F32 mag)	{ mOrbitDownKey = mag; }
347	void			setOrbitInKey(F32 mag)		{ mOrbitInKey = mag; }
348	void			setOrbitOutKey(F32 mag)		{ mOrbitOutKey = mag; }
349
350	void			clearOrbitKeys();
351private:
352	F32				mOrbitLeftKey;
353	F32				mOrbitRightKey;
354	F32				mOrbitUpKey;
355	F32				mOrbitDownKey;
356	F32				mOrbitInKey;
357	F32				mOrbitOutKey;
358
359	//--------------------------------------------------------------------
360	// Pan
361	//--------------------------------------------------------------------
362public:
363	F32				getPanLeftKey() const		{ return mPanLeftKey; }
364	F32				getPanRightKey() const	{ return mPanRightKey; }
365	F32				getPanUpKey() const		{ return mPanUpKey; }
366	F32				getPanDownKey() const		{ return mPanDownKey; }
367	F32				getPanInKey() const		{ return mPanInKey; }
368	F32				getPanOutKey() const		{ return mPanOutKey; }
369
370	void			setPanLeftKey(F32 mag)		{ mPanLeftKey = mag; }
371	void			setPanRightKey(F32 mag)		{ mPanRightKey = mag; }
372	void			setPanUpKey(F32 mag)		{ mPanUpKey = mag; }
373	void			setPanDownKey(F32 mag)		{ mPanDownKey = mag; }
374	void			setPanInKey(F32 mag)		{ mPanInKey = mag; }
375	void			setPanOutKey(F32 mag)		{ mPanOutKey = mag; }
376
377	void			clearPanKeys();
378private:
379	F32				mPanUpKey;						
380	F32				mPanDownKey;					
381	F32				mPanLeftKey;					
382	F32				mPanRightKey;					
383	F32				mPanInKey;
384	F32				mPanOutKey;
385
386/**                    Keys
387 **                                                                            **
388 *******************************************************************************/
389
390};
391
392extern LLAgentCamera gAgentCamera;
393
394#endif