diff options
Diffstat (limited to 'linden/indra/llmath/m3math.cpp')
-rw-r--r-- | linden/indra/llmath/m3math.cpp | 95 |
1 files changed, 45 insertions, 50 deletions
diff --git a/linden/indra/llmath/m3math.cpp b/linden/indra/llmath/m3math.cpp index c5d2c2d..4d93af6 100644 --- a/linden/indra/llmath/m3math.cpp +++ b/linden/indra/llmath/m3math.cpp | |||
@@ -52,14 +52,14 @@ | |||
52 | 52 | ||
53 | LLMatrix3::LLMatrix3(const LLQuaternion &q) | 53 | LLMatrix3::LLMatrix3(const LLQuaternion &q) |
54 | { | 54 | { |
55 | *this = q.getMatrix3(); | 55 | setRot(q); |
56 | } | 56 | } |
57 | 57 | ||
58 | 58 | ||
59 | LLMatrix3::LLMatrix3(const F32 angle, const LLVector3 &vec) | 59 | LLMatrix3::LLMatrix3(const F32 angle, const LLVector3 &vec) |
60 | { | 60 | { |
61 | LLQuaternion quat(angle, vec); | 61 | LLQuaternion quat(angle, vec); |
62 | *this = setRot(quat); | 62 | setRot(quat); |
63 | } | 63 | } |
64 | 64 | ||
65 | LLMatrix3::LLMatrix3(const F32 angle, const LLVector3d &vec) | 65 | LLMatrix3::LLMatrix3(const F32 angle, const LLVector3d &vec) |
@@ -67,60 +67,25 @@ LLMatrix3::LLMatrix3(const F32 angle, const LLVector3d &vec) | |||
67 | LLVector3 vec_f; | 67 | LLVector3 vec_f; |
68 | vec_f.setVec(vec); | 68 | vec_f.setVec(vec); |
69 | LLQuaternion quat(angle, vec_f); | 69 | LLQuaternion quat(angle, vec_f); |
70 | *this = setRot(quat); | 70 | setRot(quat); |
71 | } | 71 | } |
72 | 72 | ||
73 | LLMatrix3::LLMatrix3(const F32 angle, const LLVector4 &vec) | 73 | LLMatrix3::LLMatrix3(const F32 angle, const LLVector4 &vec) |
74 | { | 74 | { |
75 | LLQuaternion quat(angle, vec); | 75 | LLQuaternion quat(angle, vec); |
76 | *this = setRot(quat); | 76 | setRot(quat); |
77 | } | 77 | } |
78 | 78 | ||
79 | LLMatrix3::LLMatrix3(const F32 angle, const F32 x, const F32 y, const F32 z) | 79 | LLMatrix3::LLMatrix3(const F32 angle, const F32 x, const F32 y, const F32 z) |
80 | { | 80 | { |
81 | LLVector3 vec(x, y, z); | 81 | LLVector3 vec(x, y, z); |
82 | LLQuaternion quat(angle, vec); | 82 | LLQuaternion quat(angle, vec); |
83 | *this = setRot(quat); | 83 | setRot(quat); |
84 | } | 84 | } |
85 | 85 | ||
86 | LLMatrix3::LLMatrix3(const F32 roll, const F32 pitch, const F32 yaw) | 86 | LLMatrix3::LLMatrix3(const F32 roll, const F32 pitch, const F32 yaw) |
87 | { | 87 | { |
88 | // Rotates RH about x-axis by 'roll' then | 88 | setRot(roll,pitch,yaw); |
89 | // rotates RH about the old y-axis by 'pitch' then | ||
90 | // rotates RH about the original z-axis by 'yaw'. | ||
91 | // . | ||
92 | // /|\ yaw axis | ||
93 | // | __. | ||
94 | // ._ ___| /| pitch axis | ||
95 | // _||\ \\ |-. / | ||
96 | // \|| \_______\_|__\_/_______ | ||
97 | // | _ _ o o o_o_o_o o /_\_ ________\ roll axis | ||
98 | // // /_______/ /__________> / | ||
99 | // /_,-' // / | ||
100 | // /__,-' | ||
101 | |||
102 | F32 cx, sx, cy, sy, cz, sz; | ||
103 | F32 cxsy, sxsy; | ||
104 | |||
105 | cx = (F32)cos(roll); //A | ||
106 | sx = (F32)sin(roll); //B | ||
107 | cy = (F32)cos(pitch); //C | ||
108 | sy = (F32)sin(pitch); //D | ||
109 | cz = (F32)cos(yaw); //E | ||
110 | sz = (F32)sin(yaw); //F | ||
111 | |||
112 | cxsy = cx * sy; //AD | ||
113 | sxsy = sx * sy; //BD | ||
114 | |||
115 | mMatrix[0][0] = cy * cz; | ||
116 | mMatrix[1][0] = -cy * sz; | ||
117 | mMatrix[2][0] = sy; | ||
118 | mMatrix[0][1] = sxsy * cz + cx * sz; | ||
119 | mMatrix[1][1] = -sxsy * sz + cx * cz; | ||
120 | mMatrix[2][1] = -sx * cy; | ||
121 | mMatrix[0][2] = -cxsy * cz + sx * sz; | ||
122 | mMatrix[1][2] = cxsy * sz + sx * cz; | ||
123 | mMatrix[2][2] = cx * cy; | ||
124 | } | 89 | } |
125 | 90 | ||
126 | // From Matrix and Quaternion FAQ | 91 | // From Matrix and Quaternion FAQ |
@@ -307,34 +272,64 @@ LLQuaternion LLMatrix3::quaternion() const | |||
307 | // These functions take Rotation arguments | 272 | // These functions take Rotation arguments |
308 | const LLMatrix3& LLMatrix3::setRot(const F32 angle, const F32 x, const F32 y, const F32 z) | 273 | const LLMatrix3& LLMatrix3::setRot(const F32 angle, const F32 x, const F32 y, const F32 z) |
309 | { | 274 | { |
310 | LLMatrix3 mat(angle, x, y, z); | 275 | setRot(LLQuaternion(angle,x,y,z)); |
311 | *this = mat; | ||
312 | return *this; | 276 | return *this; |
313 | } | 277 | } |
314 | 278 | ||
315 | const LLMatrix3& LLMatrix3::setRot(const F32 angle, const LLVector3 &vec) | 279 | const LLMatrix3& LLMatrix3::setRot(const F32 angle, const LLVector3 &vec) |
316 | { | 280 | { |
317 | LLMatrix3 mat(angle, vec); | 281 | setRot(LLQuaternion(angle, vec)); |
318 | *this = mat; | ||
319 | return *this; | 282 | return *this; |
320 | } | 283 | } |
321 | 284 | ||
322 | const LLMatrix3& LLMatrix3::setRot(const F32 roll, const F32 pitch, const F32 yaw) | 285 | const LLMatrix3& LLMatrix3::setRot(const F32 roll, const F32 pitch, const F32 yaw) |
323 | { | 286 | { |
324 | LLMatrix3 mat(roll, pitch, yaw); | 287 | // Rotates RH about x-axis by 'roll' then |
325 | *this = mat; | 288 | // rotates RH about the old y-axis by 'pitch' then |
289 | // rotates RH about the original z-axis by 'yaw'. | ||
290 | // . | ||
291 | // /|\ yaw axis | ||
292 | // | __. | ||
293 | // ._ ___| /| pitch axis | ||
294 | // _||\ \\ |-. / | ||
295 | // \|| \_______\_|__\_/_______ | ||
296 | // | _ _ o o o_o_o_o o /_\_ ________\ roll axis | ||
297 | // // /_______/ /__________> / | ||
298 | // /_,-' // / | ||
299 | // /__,-' | ||
300 | |||
301 | F32 cx, sx, cy, sy, cz, sz; | ||
302 | F32 cxsy, sxsy; | ||
303 | |||
304 | cx = (F32)cos(roll); //A | ||
305 | sx = (F32)sin(roll); //B | ||
306 | cy = (F32)cos(pitch); //C | ||
307 | sy = (F32)sin(pitch); //D | ||
308 | cz = (F32)cos(yaw); //E | ||
309 | sz = (F32)sin(yaw); //F | ||
310 | |||
311 | cxsy = cx * sy; //AD | ||
312 | sxsy = sx * sy; //BD | ||
313 | |||
314 | mMatrix[0][0] = cy * cz; | ||
315 | mMatrix[1][0] = -cy * sz; | ||
316 | mMatrix[2][0] = sy; | ||
317 | mMatrix[0][1] = sxsy * cz + cx * sz; | ||
318 | mMatrix[1][1] = -sxsy * sz + cx * cz; | ||
319 | mMatrix[2][1] = -sx * cy; | ||
320 | mMatrix[0][2] = -cxsy * cz + sx * sz; | ||
321 | mMatrix[1][2] = cxsy * sz + sx * cz; | ||
322 | mMatrix[2][2] = cx * cy; | ||
326 | return *this; | 323 | return *this; |
327 | } | 324 | } |
328 | 325 | ||
329 | 326 | ||
330 | const LLMatrix3& LLMatrix3::setRot(const LLQuaternion &q) | 327 | const LLMatrix3& LLMatrix3::setRot(const LLQuaternion &q) |
331 | { | 328 | { |
332 | LLMatrix3 mat(q); | 329 | *this = q.getMatrix3(); |
333 | *this = mat; | ||
334 | return *this; | 330 | return *this; |
335 | } | 331 | } |
336 | 332 | ||
337 | |||
338 | const LLMatrix3& LLMatrix3::setRows(const LLVector3 &fwd, const LLVector3 &left, const LLVector3 &up) | 333 | const LLMatrix3& LLMatrix3::setRows(const LLVector3 &fwd, const LLVector3 &left, const LLVector3 &up) |
339 | { | 334 | { |
340 | mMatrix[0][0] = fwd.mV[0]; | 335 | mMatrix[0][0] = fwd.mV[0]; |