aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmath/llcamera.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llmath/llcamera.h
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/llmath/llcamera.h')
-rw-r--r--linden/indra/llmath/llcamera.h188
1 files changed, 188 insertions, 0 deletions
diff --git a/linden/indra/llmath/llcamera.h b/linden/indra/llmath/llcamera.h
new file mode 100644
index 0000000..82b6130
--- /dev/null
+++ b/linden/indra/llmath/llcamera.h
@@ -0,0 +1,188 @@
1/**
2 * @file llcamera.h
3 * @brief Header file for the LLCamera class.
4 *
5 * Copyright (c) 2000-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#ifndef LL_CAMERA_H
29#define LL_CAMERA_H
30
31
32#include "llmath.h"
33#include "llcoordframe.h"
34#include "llplane.h"
35
36const F32 DEFAULT_FIELD_OF_VIEW = 60.f * DEG_TO_RAD;
37const F32 DEFAULT_ASPECT_RATIO = 640.f / 480.f;
38const F32 DEFAULT_NEAR_PLANE = 0.25f;
39const F32 DEFAULT_FAR_PLANE = 64.f; // far reaches across two horizontal, not diagonal, regions
40
41const F32 MAX_FIELD_OF_VIEW = F_PI;
42const F32 MAX_ASPECT_RATIO = 50.0f;
43const F32 MAX_NEAR_PLANE = 10.f;
44const F32 MAX_FAR_PLANE = 100000.0f; //1000000.0f; // Max allowed. Not good Z precision though.
45const F32 MAX_FAR_CLIP = 1024.0f;
46
47const F32 MIN_FIELD_OF_VIEW = 0.1f;
48const F32 MIN_ASPECT_RATIO = 0.02f;
49const F32 MIN_NEAR_PLANE = 0.1f;
50const F32 MIN_FAR_PLANE = 0.2f;
51
52static const LLVector3 X_AXIS(1.f,0.f,0.f);
53static const LLVector3 Y_AXIS(0.f,1.f,0.f);
54static const LLVector3 Z_AXIS(0.f,0.f,1.f);
55
56static const LLVector3 NEG_X_AXIS(-1.f,0.f,0.f);
57static const LLVector3 NEG_Y_AXIS(0.f,-1.f,0.f);
58static const LLVector3 NEG_Z_AXIS(0.f,0.f,-1.f);
59
60
61// An LLCamera is an LLCoorFrame with a view frustum.
62// This means that it has several methods for moving it around
63// that are inherited from the LLCoordFrame() class :
64//
65// setOrigin(), setAxes()
66// translate(), rotate()
67// roll(), pitch(), yaw()
68// etc...
69
70
71class LLCamera
72: public LLCoordFrame
73{
74public:
75 enum {
76 PLANE_LEFT = 0,
77 PLANE_RIGHT = 1,
78 PLANE_BOTTOM = 2,
79 PLANE_TOP = 3,
80 PLANE_NUM = 4
81 };
82 enum {
83 PLANE_LEFT_MASK = (1<<PLANE_LEFT),
84 PLANE_RIGHT_MASK = (1<<PLANE_RIGHT),
85 PLANE_BOTTOM_MASK = (1<<PLANE_BOTTOM),
86 PLANE_TOP_MASK = (1<<PLANE_TOP),
87 PLANE_ALL_MASK = 0xf
88 };
89 enum {
90 HORIZ_PLANE_LEFT = 0,
91 HORIZ_PLANE_RIGHT = 1,
92 HORIZ_PLANE_NUM = 2
93 };
94 enum {
95 HORIZ_PLANE_LEFT_MASK = (1<<HORIZ_PLANE_LEFT),
96 HORIZ_PLANE_RIGHT_MASK = (1<<HORIZ_PLANE_RIGHT),
97 HORIZ_PLANE_ALL_MASK = 0x3
98 };
99
100protected:
101 F32 mView; // angle between top and bottom frustum planes in radians.
102 F32 mAspect; // width/height
103 S32 mViewHeightInPixels; // for ViewHeightInPixels() only
104 F32 mNearPlane;
105 F32 mFarPlane;
106 LLPlane mLocalPlanes[4];
107 F32 mFixedDistance; // Always return this distance, unless < 0
108 LLVector3 mFrustCenter; // center of frustum and radius squared for ultra-quick exclusion test
109 F32 mFrustRadiusSquared;
110
111 LLPlane mWorldPlanes[PLANE_NUM];
112 LLPlane mHorizPlanes[HORIZ_PLANE_NUM];
113 LLPlane mAgentPlanes[6]; //frustum in agent space a la gluUnproject (I'm a bastard, I know) - DaveP
114 U8 mAgentPlaneMask[6];
115 LLVector3 mWorldPlanePos; // Position of World Planes (may be offset from camera)
116public:
117 LLVector3 mAgentFrustum[8];
118
119public:
120 LLCamera();
121 LLCamera(F32 z_field_of_view, F32 aspect_ratio, S32 view_height_in_pixels, F32 near_plane, F32 far_plane);
122
123 void setView(F32 new_view);
124 void setViewHeightInPixels(S32 height);
125 void setAspect(F32 new_aspect);
126 void setNear(F32 new_near);
127 void setFar(F32 new_far);
128
129 F32 getView() const { return mView; } // vertical FOV in radians
130 S32 getViewHeightInPixels() const { return mViewHeightInPixels; }
131 F32 getAspect() const { return mAspect; } // width / height
132 F32 getNear() const { return mNearPlane; } // meters
133 F32 getFar() const { return mFarPlane; } // meters
134
135 F32 getYaw() const
136 {
137 return atan2f(mXAxis[VY], mXAxis[VX]);
138 }
139 F32 getPitch() const
140 {
141 F32 xylen = sqrtf(mXAxis[VX]*mXAxis[VX] + mXAxis[VY]*mXAxis[VY]);
142 return atan2f(mXAxis[VZ], xylen);
143 }
144
145 const LLPlane& getWorldPlane(S32 index) const { return mWorldPlanes[index]; }
146 const LLVector3& getWorldPlanePos() const { return mWorldPlanePos; }
147
148 // Copy mView, mAspect, mNearPlane, and mFarPlane to buffer.
149 // Return number of bytes copied.
150 size_t writeFrustumToBuffer(char *buffer) const;
151
152 // Copy mView, mAspect, mNearPlane, and mFarPlane from buffer.
153 // Return number of bytes copied.
154 size_t readFrustumFromBuffer(const char *buffer);
155 void calcAgentFrustumPlanes(LLVector3* frust);
156 // Returns 1 if partly in, 2 if fully in.
157 // NOTE: 'center' is in absolute frame.
158 S32 sphereInFrustumOld(const LLVector3 &center, const F32 radius) const;
159 S32 sphereInFrustum(const LLVector3 &center, const F32 radius) const;
160 S32 pointInFrustum(const LLVector3 &point) const { return sphereInFrustum(point, 0.0f); }
161 S32 sphereInFrustumFull(const LLVector3 &center, const F32 radius) const { return sphereInFrustum(center, radius); }
162 S32 AABBInFrustum(const LLVector3 &center, const LLVector3& radius);
163 //does a quick 'n dirty sphere-sphere check
164 S32 sphereInFrustumQuick(const LLVector3 &sphere_center, const F32 radius);
165
166 // Returns height of object in pixels (must be height because field of view
167 // is based on window height).
168 F32 heightInPixels(const LLVector3 &center, F32 radius ) const;
169
170 // return the distance from pos to camera if visible (-distance if not visible)
171 F32 visibleDistance(const LLVector3 &pos, F32 rad, F32 fudgescale = 1.0f, U32 planemask = PLANE_ALL_MASK) const;
172 F32 visibleHorizDistance(const LLVector3 &pos, F32 rad, F32 fudgescale = 1.0f, U32 planemask = HORIZ_PLANE_ALL_MASK) const;
173 void setFixedDistance(F32 distance) { mFixedDistance = distance; }
174
175 friend std::ostream& operator<<(std::ostream &s, const LLCamera &C);
176
177protected:
178 void calculateFrustumPlanes();
179 void calculateFrustumPlanes(F32 left, F32 right, F32 top, F32 bottom);
180 void calculateFrustumPlanesFromWindow(F32 x1, F32 y1, F32 x2, F32 y2);
181 void calculateWorldFrustumPlanes();
182};
183
184
185#endif
186
187
188