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/xform.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/xform.h')
-rw-r--r-- | linden/indra/llmath/xform.h | 288 |
1 files changed, 288 insertions, 0 deletions
diff --git a/linden/indra/llmath/xform.h b/linden/indra/llmath/xform.h new file mode 100644 index 0000000..af28e43 --- /dev/null +++ b/linden/indra/llmath/xform.h | |||
@@ -0,0 +1,288 @@ | |||
1 | /** | ||
2 | * @file xform.h | ||
3 | * | ||
4 | * Copyright (c) 2001-2007, Linden Research, Inc. | ||
5 | * | ||
6 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
7 | * to you under the terms of the GNU General Public License, version 2.0 | ||
8 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
9 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
10 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
11 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
12 | * | ||
13 | * There are special exceptions to the terms and conditions of the GPL as | ||
14 | * it is applied to this Source Code. View the full text of the exception | ||
15 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
16 | * online at http://secondlife.com/developers/opensource/flossexception | ||
17 | * | ||
18 | * By copying, modifying or distributing this software, you acknowledge | ||
19 | * that you have read and understood your obligations described above, | ||
20 | * and agree to abide by those obligations. | ||
21 | * | ||
22 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
23 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
24 | * COMPLETENESS OR PERFORMANCE. | ||
25 | */ | ||
26 | |||
27 | #ifndef LL_XFORM_H | ||
28 | #define LL_XFORM_H | ||
29 | |||
30 | #include "v3math.h" | ||
31 | #include "m4math.h" | ||
32 | #include "llquaternion.h" | ||
33 | |||
34 | #define CHECK_FOR_FINITE | ||
35 | |||
36 | |||
37 | const F32 MAX_OBJECT_Z = 768.f; | ||
38 | const F32 MIN_OBJECT_Z = -256.f; | ||
39 | const F32 MIN_OBJECT_SCALE = 0.01f; | ||
40 | const F32 MAX_OBJECT_SCALE = 10.f; | ||
41 | |||
42 | class LLXform | ||
43 | { | ||
44 | protected: | ||
45 | LLVector3 mPosition; | ||
46 | LLQuaternion mRotation; | ||
47 | LLVector3 mScale; | ||
48 | |||
49 | //RN: TODO: move these world transform members to LLXformMatrix | ||
50 | // as they are *never* updated or accessed in the base class | ||
51 | LLVector3 mWorldPosition; | ||
52 | LLQuaternion mWorldRotation; | ||
53 | |||
54 | LLXform* mParent; | ||
55 | U32 mChanged; | ||
56 | |||
57 | BOOL mScaleChildOffset; | ||
58 | |||
59 | public: | ||
60 | typedef enum e_changed_flags | ||
61 | { | ||
62 | UNCHANGED = 0x00, | ||
63 | TRANSLATED = 0x01, | ||
64 | ROTATED = 0x02, | ||
65 | SCALED = 0x04, | ||
66 | SHIFTED = 0x08, | ||
67 | GEOMETRY = 0x10, | ||
68 | TEXTURE = 0x20, | ||
69 | MOVED = TRANSLATED|ROTATED|SCALED, | ||
70 | SILHOUETTE = 0x40, | ||
71 | ALL_CHANGED = 0x7f | ||
72 | }EChangedFlags; | ||
73 | |||
74 | void init() | ||
75 | { | ||
76 | mParent = NULL; | ||
77 | mChanged = UNCHANGED; | ||
78 | mPosition.setVec(0,0,0); | ||
79 | mRotation.loadIdentity(); | ||
80 | mScale. setVec(1,1,1); | ||
81 | mWorldPosition.clearVec(); | ||
82 | mWorldRotation.loadIdentity(); | ||
83 | mScaleChildOffset = FALSE; | ||
84 | } | ||
85 | |||
86 | LLXform(); | ||
87 | virtual ~LLXform(); | ||
88 | |||
89 | void getLocalMat4(LLMatrix4 &mat) const { mat.initAll(mScale, mRotation, mPosition); } | ||
90 | |||
91 | inline BOOL setParent(LLXform *parent); | ||
92 | |||
93 | inline void setPosition(const LLVector3& pos); | ||
94 | inline void setPosition(const F32 x, const F32 y, const F32 z); | ||
95 | inline void setPositionX(const F32 x); | ||
96 | inline void setPositionY(const F32 y); | ||
97 | inline void setPositionZ(const F32 z); | ||
98 | inline void addPosition(const LLVector3& pos); | ||
99 | |||
100 | |||
101 | inline void setScale(const LLVector3& scale); | ||
102 | inline void setScale(const F32 x, const F32 y, const F32 z); | ||
103 | inline void setRotation(const LLQuaternion& rot); | ||
104 | inline void setRotation(const F32 x, const F32 y, const F32 z); | ||
105 | inline void setRotation(const F32 x, const F32 y, const F32 z, const F32 s); | ||
106 | |||
107 | void setChanged(const U32 bits) { mChanged |= bits; } | ||
108 | BOOL isChanged() const { return mChanged; } | ||
109 | BOOL isChanged(const U32 bits) const { return mChanged & bits; } | ||
110 | void clearChanged() { mChanged = 0; } | ||
111 | void clearChanged(U32 bits) { mChanged &= ~bits; } | ||
112 | |||
113 | void setScaleChildOffset(BOOL scale) { mScaleChildOffset = scale; } | ||
114 | BOOL getScaleChildOffset() { return mScaleChildOffset; } | ||
115 | |||
116 | LLXform* getParent() const { return mParent; } | ||
117 | LLXform* getRoot() const; | ||
118 | virtual BOOL isRoot() const; | ||
119 | virtual BOOL isRootEdit() const; | ||
120 | |||
121 | const LLVector3& getPosition() const { return mPosition; } | ||
122 | const LLVector3& getScale() const { return mScale; } | ||
123 | const LLQuaternion& getRotation() const { return mRotation; } | ||
124 | const LLVector3& getPositionW() const { return mWorldPosition; } | ||
125 | const LLQuaternion& getWorldRotation() const { return mWorldRotation; } | ||
126 | const LLVector3& getWorldPosition() const { return mWorldPosition; } | ||
127 | }; | ||
128 | |||
129 | class LLXformMatrix : public LLXform | ||
130 | { | ||
131 | public: | ||
132 | LLXformMatrix() : LLXform() {}; | ||
133 | virtual ~LLXformMatrix(); | ||
134 | |||
135 | const LLMatrix4& getWorldMatrix() const { return mWorldMatrix; } | ||
136 | void setWorldMatrix (const LLMatrix4& mat) { mWorldMatrix = mat; } | ||
137 | |||
138 | void init() | ||
139 | { | ||
140 | mWorldMatrix.identity(); | ||
141 | mMin.clearVec(); | ||
142 | mMax.clearVec(); | ||
143 | |||
144 | LLXform::init(); | ||
145 | } | ||
146 | |||
147 | void update(); | ||
148 | void updateMatrix(BOOL update_bounds = TRUE); | ||
149 | void getMinMax(LLVector3& min,LLVector3& max) const; | ||
150 | |||
151 | protected: | ||
152 | LLMatrix4 mWorldMatrix; | ||
153 | LLVector3 mMin; | ||
154 | LLVector3 mMax; | ||
155 | |||
156 | }; | ||
157 | |||
158 | BOOL LLXform::setParent(LLXform* parent) | ||
159 | { | ||
160 | // Validate and make sure we're not creating a loop | ||
161 | if (parent == mParent) | ||
162 | { | ||
163 | return TRUE; | ||
164 | } | ||
165 | if (parent) | ||
166 | { | ||
167 | LLXform *cur_par = parent->mParent; | ||
168 | while (cur_par) | ||
169 | { | ||
170 | if (cur_par == this) | ||
171 | { | ||
172 | llwarns << "LLXform::setParent Creating loop when setting parent!" << llendl; | ||
173 | return FALSE; | ||
174 | } | ||
175 | cur_par = cur_par->mParent; | ||
176 | } | ||
177 | } | ||
178 | mParent = parent; | ||
179 | return TRUE; | ||
180 | } | ||
181 | |||
182 | #ifdef CHECK_FOR_FINITE | ||
183 | void LLXform::setPosition(const LLVector3& pos) | ||
184 | { | ||
185 | setChanged(TRANSLATED); | ||
186 | if (pos.isFinite()) | ||
187 | mPosition = pos; | ||
188 | else | ||
189 | llerror("Non Finite in LLXform::setPosition(LLVector3)", 0); | ||
190 | } | ||
191 | |||
192 | void LLXform::setPosition(const F32 x, const F32 y, const F32 z) | ||
193 | { | ||
194 | setChanged(TRANSLATED); | ||
195 | if (llfinite(x) && llfinite(y) && llfinite(z)) | ||
196 | mPosition.setVec(x,y,z); | ||
197 | else | ||
198 | llerror("Non Finite in LLXform::setPosition(F32,F32,F32)", 0); | ||
199 | } | ||
200 | |||
201 | void LLXform::setPositionX(const F32 x) | ||
202 | { | ||
203 | setChanged(TRANSLATED); | ||
204 | if (llfinite(x)) | ||
205 | mPosition.mV[VX] = x; | ||
206 | else | ||
207 | llerror("Non Finite in LLXform::setPositionX", 0); | ||
208 | } | ||
209 | |||
210 | void LLXform::setPositionY(const F32 y) | ||
211 | { | ||
212 | setChanged(TRANSLATED); | ||
213 | if (llfinite(y)) | ||
214 | mPosition.mV[VY] = y; | ||
215 | else | ||
216 | llerror("Non Finite in LLXform::setPositionY", 0); | ||
217 | } | ||
218 | |||
219 | void LLXform::setPositionZ(const F32 z) | ||
220 | { | ||
221 | setChanged(TRANSLATED); | ||
222 | if (llfinite(z)) | ||
223 | mPosition.mV[VZ] = z; | ||
224 | else | ||
225 | llerror("Non Finite in LLXform::setPositionZ", 0); | ||
226 | } | ||
227 | |||
228 | void LLXform::addPosition(const LLVector3& pos) | ||
229 | { | ||
230 | setChanged(TRANSLATED); | ||
231 | if (pos.isFinite()) | ||
232 | mPosition += pos; | ||
233 | else | ||
234 | llerror("Non Finite in LLXform::addPosition", 0); | ||
235 | } | ||
236 | |||
237 | void LLXform::setScale(const LLVector3& scale) | ||
238 | { | ||
239 | setChanged(SCALED); | ||
240 | if (scale.isFinite()) | ||
241 | mScale = scale; | ||
242 | else | ||
243 | llerror("Non Finite in LLXform::setScale", 0); | ||
244 | } | ||
245 | void LLXform::setScale(const F32 x, const F32 y, const F32 z) | ||
246 | { | ||
247 | setChanged(SCALED); | ||
248 | if (llfinite(x) && llfinite(y) && llfinite(z)) | ||
249 | mScale.setVec(x,y,z); | ||
250 | else | ||
251 | llerror("Non Finite in LLXform::setScale", 0); | ||
252 | } | ||
253 | void LLXform::setRotation(const LLQuaternion& rot) | ||
254 | { | ||
255 | setChanged(ROTATED); | ||
256 | if (rot.isFinite()) | ||
257 | mRotation = rot; | ||
258 | else | ||
259 | llerror("Non Finite in LLXform::setRotation", 0); | ||
260 | } | ||
261 | void LLXform::setRotation(const F32 x, const F32 y, const F32 z) | ||
262 | { | ||
263 | setChanged(ROTATED); | ||
264 | if (llfinite(x) && llfinite(y) && llfinite(z)) | ||
265 | { | ||
266 | mRotation.setQuat(x,y,z); | ||
267 | } | ||
268 | else | ||
269 | { | ||
270 | llerror("Non Finite in LLXform::setRotation", 0); | ||
271 | } | ||
272 | } | ||
273 | void LLXform::setRotation(const F32 x, const F32 y, const F32 z, const F32 s) | ||
274 | { | ||
275 | setChanged(ROTATED); | ||
276 | if (llfinite(x) && llfinite(y) && llfinite(z) && llfinite(s)) | ||
277 | { | ||
278 | mRotation.mQ[VX] = x; mRotation.mQ[VY] = y; mRotation.mQ[VZ] = z; mRotation.mQ[VS] = s; | ||
279 | } | ||
280 | else | ||
281 | { | ||
282 | llerror("Non Finite in LLXform::setRotation", 0); | ||
283 | } | ||
284 | } | ||
285 | |||
286 | #endif | ||
287 | |||
288 | #endif | ||