diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llmath/llcoordframe.h | |
parent | README.txt (diff) | |
download | meta-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/llcoordframe.h')
-rw-r--r-- | linden/indra/llmath/llcoordframe.h | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/linden/indra/llmath/llcoordframe.h b/linden/indra/llmath/llcoordframe.h new file mode 100644 index 0000000..d15f3e5 --- /dev/null +++ b/linden/indra/llmath/llcoordframe.h | |||
@@ -0,0 +1,175 @@ | |||
1 | /** | ||
2 | * @file llcoordframe.h | ||
3 | * @brief LLCoordFrame class header file. | ||
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_COORDFRAME_H | ||
29 | #define LL_COORDFRAME_H | ||
30 | |||
31 | #include "v3math.h" | ||
32 | #include "v4math.h" | ||
33 | #include "llerror.h" | ||
34 | |||
35 | // XXX : The constructors of the LLCoordFrame class assume that all vectors | ||
36 | // and quaternion being passed as arguments are normalized, and all matrix | ||
37 | // arguments are unitary. VERY BAD things will happen if these assumptions fail. | ||
38 | // Also, segfault hazzards exist in methods that accept F32* arguments. | ||
39 | |||
40 | |||
41 | class LLCoordFrame | ||
42 | { | ||
43 | public: | ||
44 | LLCoordFrame(); // Inits at zero with identity rotation | ||
45 | explicit LLCoordFrame(const LLVector3 &origin); // Sets origin, and inits rotation = Identity | ||
46 | LLCoordFrame(const LLVector3 &x_axis, | ||
47 | const LLVector3 &y_axis, | ||
48 | const LLVector3 &z_axis); // Sets coordinate axes and inits origin at zero | ||
49 | LLCoordFrame(const LLVector3 &origin, | ||
50 | const LLVector3 &x_axis, | ||
51 | const LLVector3 &y_axis, | ||
52 | const LLVector3 &z_axis); // Sets the origin and coordinate axes | ||
53 | LLCoordFrame(const LLVector3 &origin, | ||
54 | const LLMatrix3 &rotation); // Sets axes to 3x3 matrix | ||
55 | LLCoordFrame(const LLVector3 &origin, | ||
56 | const LLVector3 &direction); // Sets origin and calls lookDir(direction) | ||
57 | explicit LLCoordFrame(const LLQuaternion &q); // Sets axes using q and inits mOrigin to zero | ||
58 | LLCoordFrame(const LLVector3 &origin, | ||
59 | const LLQuaternion &q); // Uses quaternion to init axes | ||
60 | explicit LLCoordFrame(const LLMatrix4 &mat); // Extracts frame from a 4x4 matrix | ||
61 | // The folowing two constructors are dangerous due to implicit casting and have been disabled - SJB | ||
62 | //LLCoordFrame(const F32 *origin, const F32 *rotation); // Assumes "origin" is 1x3 and "rotation" is 1x9 array | ||
63 | //LLCoordFrame(const F32 *origin_and_rotation); // Assumes "origin_and_rotation" is 1x12 array | ||
64 | |||
65 | BOOL isFinite() { return mOrigin.isFinite() && mXAxis.isFinite() && mYAxis.isFinite() && mZAxis.isFinite(); } | ||
66 | |||
67 | void reset(); | ||
68 | void resetAxes(); | ||
69 | |||
70 | void setOrigin(F32 x, F32 y, F32 z); // Set mOrigin | ||
71 | void setOrigin(const LLVector3 &origin); | ||
72 | void setOrigin(const F32 *origin); | ||
73 | void setOrigin(const LLCoordFrame &frame); | ||
74 | |||
75 | inline void setOriginX(F32 x) { mOrigin.mV[VX] = x; } | ||
76 | inline void setOriginY(F32 y) { mOrigin.mV[VY] = y; } | ||
77 | inline void setOriginZ(F32 z) { mOrigin.mV[VZ] = z; } | ||
78 | |||
79 | void setAxes(const LLVector3 &x_axis, // Set axes | ||
80 | const LLVector3 &y_axis, | ||
81 | const LLVector3 &z_axis); | ||
82 | void setAxes(const LLMatrix3 &rotation_matrix); | ||
83 | void setAxes(const LLQuaternion &q); | ||
84 | void setAxes(const F32 *rotation_matrix); | ||
85 | void setAxes(const LLCoordFrame &frame); | ||
86 | |||
87 | void translate(F32 x, F32 y, F32 z); // Move mOrgin | ||
88 | void translate(const LLVector3 &v); | ||
89 | void translate(const F32 *origin); | ||
90 | |||
91 | void rotate(F32 angle, F32 x, F32 y, F32 z); // Move axes | ||
92 | void rotate(F32 angle, const LLVector3 &rotation_axis); | ||
93 | void rotate(const LLQuaternion &q); | ||
94 | void rotate(const LLMatrix3 &m); | ||
95 | |||
96 | void orthonormalize(); // Makes sure axes are unitary and orthogonal. | ||
97 | |||
98 | // These methods allow rotations in the LLCoordFrame's frame | ||
99 | void roll(F32 angle); // RH rotation about mXAxis, radians | ||
100 | void pitch(F32 angle); // RH rotation about mYAxis, radians | ||
101 | void yaw(F32 angle); // RH rotation about mZAxis, radians | ||
102 | |||
103 | inline const LLVector3 &getOrigin() const { return mOrigin; } | ||
104 | |||
105 | inline const LLVector3 &getXAxis() const { return mXAxis; } | ||
106 | inline const LLVector3 &getYAxis() const { return mYAxis; } | ||
107 | inline const LLVector3 &getZAxis() const { return mZAxis; } | ||
108 | |||
109 | inline const LLVector3 &getAtAxis() const { return mXAxis; } | ||
110 | inline const LLVector3 &getLeftAxis() const { return mYAxis; } | ||
111 | inline const LLVector3 &getUpAxis() const { return mZAxis; } | ||
112 | |||
113 | // These return representations of the rotation or orientation of the LLFrame | ||
114 | // it its absolute frame. That is, these rotations acting on the X-axis {1,0,0} | ||
115 | // will produce the mXAxis. | ||
116 | // LLMatrix3 getMatrix3() const; // Returns axes in 3x3 matrix | ||
117 | LLQuaternion getQuaternion() const; // Returns axes in quaternion form | ||
118 | |||
119 | // Same as above, except it also includes the translation of the LLFrame | ||
120 | // LLMatrix4 getMatrix4() const; // Returns position and axes in 4x4 matrix | ||
121 | |||
122 | // Returns matrix which expresses point in local frame in the parent frame | ||
123 | void getMatrixToParent(LLMatrix4 &mat) const; | ||
124 | // Returns matrix which expresses point in parent frame in the local frame | ||
125 | void getMatrixToLocal(LLMatrix4 &mat) const; // Returns matrix which expresses point in parent frame in the local frame | ||
126 | |||
127 | void getRotMatrixToParent(LLMatrix4 &mat) const; | ||
128 | |||
129 | // Copies mOrigin, then the three axes to buffer, returns number of bytes copied. | ||
130 | size_t writeOrientation(char *buffer) const; | ||
131 | |||
132 | // Copies mOrigin, then the three axes from buffer, returns the number of bytes copied. | ||
133 | // Assumes the data in buffer is correct. | ||
134 | size_t readOrientation(const char *buffer); | ||
135 | |||
136 | LLVector3 rotateToLocal(const LLVector3 &v) const; // Returns v' rotated to local | ||
137 | LLVector4 rotateToLocal(const LLVector4 &v) const; // Returns v' rotated to local | ||
138 | LLVector3 rotateToAbsolute(const LLVector3 &v) const; // Returns v' rotated to absolute | ||
139 | LLVector4 rotateToAbsolute(const LLVector4 &v) const; // Returns v' rotated to absolute | ||
140 | |||
141 | LLVector3 transformToLocal(const LLVector3 &v) const; // Returns v' in local coord | ||
142 | LLVector4 transformToLocal(const LLVector4 &v) const; // Returns v' in local coord | ||
143 | LLVector3 transformToAbsolute(const LLVector3 &v) const; // Returns v' in absolute coord | ||
144 | LLVector4 transformToAbsolute(const LLVector4 &v) const; // Returns v' in absolute coord | ||
145 | |||
146 | // Write coord frame orientation into provided array in OpenGL matrix format. | ||
147 | void getOpenGLTranslation(F32 *ogl_matrix) const; | ||
148 | void getOpenGLRotation(F32 *ogl_matrix) const; | ||
149 | void getOpenGLTransform(F32 *ogl_matrix) const; | ||
150 | |||
151 | // lookDir orients to (xuv, presumed normalized) and does not affect origin | ||
152 | void lookDir(const LLVector3 &xuv, const LLVector3 &up); | ||
153 | void lookDir(const LLVector3 &xuv); // up = 0,0,1 | ||
154 | // lookAt orients to (point_of_interest - origin) and sets origin | ||
155 | void lookAt(const LLVector3 &origin, const LLVector3 &point_of_interest, const LLVector3 &up); | ||
156 | void lookAt(const LLVector3 &origin, const LLVector3 &point_of_interest); // up = 0,0,1 | ||
157 | |||
158 | // deprecated | ||
159 | void setOriginAndLookAt(const LLVector3 &origin, const LLVector3 &up, const LLVector3 &point_of_interest) | ||
160 | { | ||
161 | lookAt(origin, point_of_interest, up); | ||
162 | } | ||
163 | |||
164 | friend std::ostream& operator<<(std::ostream &s, const LLCoordFrame &C); | ||
165 | |||
166 | // These vectors are in absolute frame | ||
167 | LLVector3 mOrigin; | ||
168 | LLVector3 mXAxis; | ||
169 | LLVector3 mYAxis; | ||
170 | LLVector3 mZAxis; | ||
171 | }; | ||
172 | |||
173 | |||
174 | #endif | ||
175 | |||