PageRenderTime 23ms CodeModel.GetById 9ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llviewercamera.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 142 lines | 86 code | 26 blank | 30 comment | 0 complexity | 0e05bcdf73c166ffb09476ea0771f411 MD5 | raw file
  1/** 
  2 * @file llviewercamera.h
  3 * @brief LLViewerCamera class header file
  4 *
  5 * $LicenseInfo:firstyear=2002&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_LLVIEWERCAMERA_H
 28#define LL_LLVIEWERCAMERA_H
 29
 30#include "llcamera.h"
 31#include "llsingleton.h"
 32#include "llstat.h"
 33#include "lltimer.h"
 34#include "m4math.h"
 35
 36class LLCoordGL;
 37class LLViewerObject;
 38
 39// This rotation matrix moves the default OpenGL reference frame 
 40// (-Z at, Y up) to Cory's favorite reference frame (X at, Z up)
 41const F32 OGL_TO_CFR_ROTATION[16] = {  0.f,  0.f, -1.f,  0.f, 	// -Z becomes X
 42									  -1.f,  0.f,  0.f,  0.f, 	// -X becomes Y
 43									   0.f,  1.f,  0.f,  0.f,	//  Y becomes Z
 44									   0.f,  0.f,  0.f,  1.f };
 45
 46const BOOL FOR_SELECTION = TRUE;
 47const BOOL NOT_FOR_SELECTION = FALSE;
 48
 49// Build time optimization, generate this once in .cpp file
 50#ifndef LLVIEWERCAMERA_CPP
 51extern template class LLViewerCamera* LLSingleton<class LLViewerCamera>::getInstance();
 52#endif
 53
 54class LLViewerCamera : public LLCamera, public LLSingleton<LLViewerCamera>
 55{
 56public:
 57
 58	typedef enum
 59	{
 60		CAMERA_WORLD = 0,
 61		CAMERA_SHADOW0,
 62		CAMERA_SHADOW1,
 63		CAMERA_SHADOW2,
 64		CAMERA_SHADOW3,
 65		CAMERA_SHADOW4,
 66		CAMERA_SHADOW5,
 67		CAMERA_WATER0,
 68		CAMERA_WATER1,
 69		CAMERA_GI_SOURCE,
 70		NUM_CAMERAS
 71	} eCameraID;
 72
 73	static U32 sCurCameraID;
 74
 75	LLViewerCamera();
 76
 77	void updateCameraLocation(const LLVector3 &center,
 78								const LLVector3 &up_direction,
 79								const LLVector3 &point_of_interest);
 80
 81	static void updateFrustumPlanes(LLCamera& camera, BOOL ortho = FALSE, BOOL zflip = FALSE, BOOL no_hacks = FALSE);
 82	static void updateCameraAngle(void* user_data, const LLSD& value);
 83	void setPerspective(BOOL for_selection, S32 x, S32 y_from_bot, S32 width, S32 height, BOOL limit_select_distance, F32 z_near = 0, F32 z_far = 0);
 84
 85	const LLMatrix4 &getProjection() const;
 86	const LLMatrix4 &getModelview() const;
 87
 88	// Warning!  These assume the current global matrices are correct
 89	void projectScreenToPosAgent(const S32 screen_x, const S32 screen_y, LLVector3* pos_agent ) const;
 90	BOOL projectPosAgentToScreen(const LLVector3 &pos_agent, LLCoordGL &out_point, const BOOL clamp = TRUE) const;
 91	BOOL projectPosAgentToScreenEdge(const LLVector3 &pos_agent, LLCoordGL &out_point) const;
 92
 93	const LLVector3* getVelocityDir() const {return &mVelocityDir;}
 94	LLStat *getVelocityStat() { return &mVelocityStat; }
 95	LLStat *getAngularVelocityStat() { return &mAngularVelocityStat; }
 96	F32     getCosHalfFov() {return mCosHalfCameraFOV;}
 97	F32     getAverageSpeed() {return mAverageSpeed ;}
 98	F32     getAverageAngularSpeed() {return mAverageAngularSpeed;}
 99
100	void getPixelVectors(const LLVector3 &pos_agent, LLVector3 &up, LLVector3 &right);
101	LLVector3 roundToPixel(const LLVector3 &pos_agent);
102
103	// Sets the current matrix
104	/* virtual */ void setView(F32 vertical_fov_rads);
105
106	void setDefaultFOV(F32 fov) ;
107	F32 getDefaultFOV() { return mCameraFOVDefault; }
108
109	BOOL cameraUnderWater() const;
110
111	const LLVector3 &getPointOfInterest() { return mLastPointOfInterest; }
112	BOOL areVertsVisible(LLViewerObject* volumep, BOOL all_verts);
113	F32 getPixelMeterRatio() const				{ return mPixelMeterRatio; }
114	S32 getScreenPixelArea() const				{ return mScreenPixelArea; }
115
116	void setZoomParameters(F32 factor, S16 subregion) { mZoomFactor = factor; mZoomSubregion = subregion; }
117	F32 getZoomFactor() { return mZoomFactor; }                             
118	S16 getZoomSubRegion() { return mZoomSubregion; } 
119
120protected:
121	void calcProjection(const F32 far_distance) const;
122
123	LLStat mVelocityStat;
124	LLStat mAngularVelocityStat;
125	LLVector3 mVelocityDir ;
126	F32       mAverageSpeed ;
127	F32       mAverageAngularSpeed ;
128
129	mutable LLMatrix4	mProjectionMatrix;	// Cache of perspective matrix
130	mutable LLMatrix4	mModelviewMatrix;
131	F32					mCameraFOVDefault;
132	F32					mCosHalfCameraFOV;
133	LLVector3			mLastPointOfInterest;
134	F32					mPixelMeterRatio; // Divide by distance from camera to get pixels per meter at that distance.
135	S32					mScreenPixelArea; // Pixel area of entire window
136	F32					mZoomFactor;
137	S16					mZoomSubregion;
138
139public:
140};
141
142#endif // LL_LLVIEWERCAMERA_H