Tiberian Technologies Scripts Reference Revision: 9000
Loading...
Searching...
No Matches
Matrix3D.h
1/* Renegade Scripts.dll
2 Copyright 2013 Tiberian Technologies
3
4 This file is part of the Renegade scripts.dll
5 The Renegade scripts.dll is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
8 version. See the file COPYING for more details.
9 In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module that does not contain code covered by this licence.
10 Only the source code to the module(s) containing the licenced code has to be released.
11*/
12#ifndef TT_INCLUDE__MATRIX3D_H
13#define TT_INCLUDE__MATRIX3D_H
14#include "vector2.h"
15#include "Vector3.h"
16#include "Vector4.h"
17class Matrix3;
18class Matrix4;
19class Quaternion;
20class PlaneClass;
21class SCRIPTS_API Matrix3D
22{
23protected:
24 Vector4 Row[3];
25public:
26 static Matrix3D Identity;
27 TT_INLINE Vector4 & operator [] (int i) { return Row[i]; }
28 TT_INLINE const Vector4 & operator [] (int i) const { return Row[i]; }
29
30 TT_INLINE explicit Matrix3D(bool init) { if (init) Make_Identity(); }
31 TT_INLINE explicit Matrix3D(float m[12])
32 {
33 Row[0].Set(m[0],m[1],m[2],m[3]);
34 Row[1].Set(m[4],m[5],m[6],m[7]);
35 Row[2].Set(m[8],m[9],m[10],m[11]);
36 }
37 TT_INLINE explicit Matrix3D(const Vector3 &x,const Vector3 &y,const Vector3 &z,const Vector3 &pos)
38 {
39 Set(x,y,z,pos);
40 }
41 TT_INLINE explicit Matrix3D(const Vector3 &axis,float angle)
42 {
43 Set(axis,angle);
44 }
45 TT_INLINE explicit Matrix3D(const Vector3 &axis,float sine,float cosine)
46 {
47 Set(axis,sine,cosine);
48 }
49 TT_INLINE explicit Matrix3D(const Matrix3 & rotation,const Vector3 & position)
50 {
51 Set(rotation,position);
52 }
53 TT_INLINE explicit Matrix3D(const Quaternion & rotation,const Vector3 & position)
54 {
55 Set(rotation,position);
56 }
57 TT_INLINE explicit Matrix3D(const Vector3 & position)
58 {
59 Set(position);
60 }
61 TT_INLINE Matrix3D(const Matrix3D & m)
62 {
63 Row[0] = m.Row[0];
64 Row[1] = m.Row[1];
65 Row[2] = m.Row[2];
66 }
67 TT_INLINE Matrix3D & operator = (const Matrix3D & m)
68 {
69 Row[0] = m.Row[0];
70 Row[1] = m.Row[1];
71 Row[2] = m.Row[2];
72 return *this;
73 }
74 Matrix3D ();
75 Matrix3D (float _11, float _12, float _13, float _14,
76 float _21, float _22, float _23, float _24,
77 float _31, float _32, float _33, float _34);
78
79 void Get_Orthogonal_Inverse (Matrix3D& target) const;
80 float Get_X_Rotation () const;
81 float Get_Y_Rotation () const;
82 float Get_Z_Rotation () const;
83 void Look_At (const Vector3&, const Vector3&, float);
84 void Obj_Look_At (const Vector3&, const Vector3&, float unknown = 0);
85 Vector3 Rotate_Vector (const Vector3& vector) const;
86 Vector3 Inverse_Rotate_Vector (const Vector3& vector) const;
87 TT_INLINE void Set(float m[12])
88 {
89 Row[0].Set(m[0],m[1],m[2],m[3]);
90 Row[1].Set(m[4],m[5],m[6],m[7]);
91 Row[2].Set(m[8],m[9],m[10],m[11]);
92 }
93 TT_INLINE void Set(float m11,float m12,float m13,float m14,float m21,float m22,float m23,float m24,float m31,float m32,float m33,float m34)
94 {
95 Row[0].Set(m11,m12,m13,m14);
96 Row[1].Set(m21,m22,m23,m24);
97 Row[2].Set(m31,m32,m33,m34);
98 }
99 TT_INLINE void Set(const Vector3 &x,const Vector3 &y,const Vector3 &z,const Vector3 &pos)
100 {
101 Row[0].Set(x[0],y[0],z[0],pos[0]);
102 Row[1].Set(x[1],y[1],z[1],pos[1]);
103 Row[2].Set(x[2],y[2],z[2],pos[2]);
104 }
105 TT_INLINE void Set(const Vector3 & axis,float angle)
106 {
107 float c = cosf(angle);
108 float s = sinf(angle);
109 Set(axis,s,c);
110 }
111 TT_INLINE void Set(const Vector3 & axis,float s,float c)
112 {
113 Row[0].Set(
114 (float)(axis[0]*axis[0] + c*(1.0f - axis[0]*axis[0])),
115 (float)(axis[0]*axis[1]*(1.0f - c) - axis[2]*s),
116 (float)(axis[2]*axis[0]*(1.0f - c) + axis[1]*s),
117 0.0f
118 );
119 Row[1].Set(
120 (float)(axis[0]*axis[1]*(1.0f - c) + axis[2]*s),
121 (float)(axis[1]*axis[1] + c*(1.0f - axis[1]*axis[1])),
122 (float)(axis[1]*axis[2]*(1.0f - c) - axis[0]*s),
123 0.0f
124 );
125 Row[2].Set(
126 (float)(axis[2]*axis[0]*(1.0f - c) - axis[1]*s),
127 (float)(axis[1]*axis[2]*(1.0f - c) + axis[0]*s),
128 (float)(axis[2]*axis[2] + c*(1 - axis[2]*axis[2])),
129 0.0f
130 );
131 }
132 TT_INLINE void Set(const Vector3 & position)
133 {
134 Row[0].Set(1.0f,0.0f,0.0f,position[0]);
135 Row[1].Set(0.0f,1.0f,0.0f,position[1]);
136 Row[2].Set(0.0f,0.0f,1.0f,position[2]);
137 }
138 void Set (const Matrix3& rotation, const Vector3& position);
139 void Set (const Quaternion& rotation, const Vector3& position);
140 void Set_Rotation (const Quaternion& rotation);
141 TT_INLINE Vector3 Get_Translation(void) const { return Vector3(Row[0][3],Row[1][3],Row[2][3]); }
142 TT_INLINE void Get_Translation(Vector3 * set) const { set->X = Row[0][3]; set->Y = Row[1][3]; set->Z = Row[2][3]; }
143 TT_INLINE void Set_Translation(const Vector3 & t) { Row[0][3] = t[0]; Row[1][3] = t[1];Row[2][3] = t[2]; }
144 void Set_Rotation(const Matrix3 & m);
145 TT_INLINE float Get_X_Translation(void) const { return Row[0][3]; };
146 TT_INLINE float Get_Y_Translation(void) const { return Row[1][3]; };
147 TT_INLINE float Get_Z_Translation(void) const { return Row[2][3]; };
148 TT_INLINE void Set_X_Translation(float x) { Row[0][3] = x; };
149 TT_INLINE void Set_Y_Translation(float y) { Row[1][3] = y; };
150 TT_INLINE void Set_Z_Translation(float z) { Row[2][3] = z; };
151 TT_INLINE void Adjust_Translation(const Vector3 & t) { Row[0][3] += t[0]; Row[1][3] += t[1]; Row[2][3] += t[2]; };
152 TT_INLINE void Adjust_X_Translation(float x) { Row[0][3] += x; };
153 TT_INLINE void Adjust_Y_Translation(float y) { Row[1][3] += y; };
154 TT_INLINE void Adjust_Z_Translation(float z) { Row[2][3] += z; };
155 TT_INLINE void Make_Identity(void)
156 {
157 Row[0].Set(1.0f,0.0f,0.0f,0.0f);
158 Row[1].Set(0.0f,1.0f,0.0f,0.0f);
159 Row[2].Set(0.0f,0.0f,1.0f,0.0f);
160 }
161 TT_INLINE void Translate(float x,float y,float z)
162 {
163 Row[0][3] += (float)(Row[0][0]*x + Row[0][1]*y + Row[0][2]*z);
164 Row[1][3] += (float)(Row[1][0]*x + Row[1][1]*y + Row[1][2]*z);
165 Row[2][3] += (float)(Row[2][0]*x + Row[2][1]*y + Row[2][2]*z);
166 }
167 TT_INLINE void Translate(const Vector3 &t)
168 {
169 Row[0][3] += Row[0][0]*t[0] + Row[0][1]*t[1] + Row[0][2]*t[2];
170 Row[1][3] += Row[1][0]*t[0] + Row[1][1]*t[1] + Row[1][2]*t[2];
171 Row[2][3] += Row[2][0]*t[0] + Row[2][1]*t[1] + Row[2][2]*t[2];
172 }
173 TT_INLINE void Translate_X(float x)
174 {
175 Row[0][3] += (float)(Row[0][0]*x);
176 Row[1][3] += (float)(Row[1][0]*x);
177 Row[2][3] += (float)(Row[2][0]*x);
178 }
179 TT_INLINE void Translate_Y(float y)
180 {
181 Row[0][3] += (float)(Row[0][1]*y);
182 Row[1][3] += (float)(Row[1][1]*y);
183 Row[2][3] += (float)(Row[2][1]*y);
184 }
185 TT_INLINE void Translate_Z(float z)
186 {
187 Row[0][3] += (float)(Row[0][2]*z);
188 Row[1][3] += (float)(Row[1][2]*z);
189 Row[2][3] += (float)(Row[2][2]*z);
190 }
191 TT_INLINE void Rotate_X(float theta)
192 {
193 float tmp1,tmp2;
194 float s,c;
195 s = sinf(theta);
196 c = cosf(theta);
197 tmp1 = Row[0][1]; tmp2 = Row[0][2];
198 Row[0][1] = (float)( c*tmp1 + s*tmp2);
199 Row[0][2] = (float)(-s*tmp1 + c*tmp2);
200 tmp1 = Row[1][1]; tmp2 = Row[1][2];
201 Row[1][1] = (float)( c*tmp1 + s*tmp2);
202 Row[1][2] = (float)(-s*tmp1 + c*tmp2);
203 tmp1 = Row[2][1]; tmp2 = Row[2][2];
204 Row[2][1] = (float)( c*tmp1 + s*tmp2);
205 Row[2][2] = (float)(-s*tmp1 + c*tmp2);
206 }
207 TT_INLINE void Rotate_Y(float theta)
208 {
209 float tmp1,tmp2;
210 float s,c;
211 s = sinf(theta);
212 c = cosf(theta);
213 tmp1 = Row[0][0]; tmp2 = Row[0][2];
214 Row[0][0] = (float)(c*tmp1 - s*tmp2);
215 Row[0][2] = (float)(s*tmp1 + c*tmp2);
216 tmp1 = Row[1][0]; tmp2 = Row[1][2];
217 Row[1][0] = (float)(c*tmp1 - s*tmp2);
218 Row[1][2] = (float)(s*tmp1 + c*tmp2);
219 tmp1 = Row[2][0]; tmp2 = Row[2][2];
220 Row[2][0] = (float)(c*tmp1 - s*tmp2);
221 Row[2][2] = (float)(s*tmp1 + c*tmp2);
222 }
223 TT_INLINE void Rotate_Z(float theta)
224 {
225 float tmp1,tmp2;
226 float c,s;
227 c = cosf(theta);
228 s = sinf(theta);
229 tmp1 = Row[0][0]; tmp2 = Row[0][1];
230 Row[0][0] = (float)( c*tmp1 + s*tmp2);
231 Row[0][1] = (float)(-s*tmp1 + c*tmp2);
232 tmp1 = Row[1][0]; tmp2 = Row[1][1];
233 Row[1][0] = (float)( c*tmp1 + s*tmp2);
234 Row[1][1] = (float)(-s*tmp1 + c*tmp2);
235 tmp1 = Row[2][0]; tmp2 = Row[2][1];
236 Row[2][0] = (float)( c*tmp1 + s*tmp2);
237 Row[2][1] = (float)(-s*tmp1 + c*tmp2);
238 }
239 TT_INLINE void Rotate_X(float s,float c)
240 {
241 float tmp1,tmp2;
242 tmp1 = Row[0][1]; tmp2 = Row[0][2];
243 Row[0][1] = (float)( c*tmp1 + s*tmp2);
244 Row[0][2] = (float)(-s*tmp1 + c*tmp2);
245 tmp1 = Row[1][1]; tmp2 = Row[1][2];
246 Row[1][1] = (float)( c*tmp1 + s*tmp2);
247 Row[1][2] = (float)(-s*tmp1 + c*tmp2);
248 tmp1 = Row[2][1]; tmp2 = Row[2][2];
249 Row[2][1] = (float)( c*tmp1 + s*tmp2);
250 Row[2][2] = (float)(-s*tmp1 + c*tmp2);
251 }
252 TT_INLINE void Rotate_Y(float s,float c)
253 {
254 float tmp1,tmp2;
255 tmp1 = Row[0][0]; tmp2 = Row[0][2];
256 Row[0][0] = (float)(c*tmp1 - s*tmp2);
257 Row[0][2] = (float)(s*tmp1 + c*tmp2);
258 tmp1 = Row[1][0]; tmp2 = Row[1][2];
259 Row[1][0] = (float)(c*tmp1 - s*tmp2);
260 Row[1][2] = (float)(s*tmp1 + c*tmp2);
261 tmp1 = Row[2][0]; tmp2 = Row[2][2];
262 Row[2][0] = (float)(c*tmp1 - s*tmp2);
263 Row[2][2] = (float)(s*tmp1 + c*tmp2);
264 }
265 TT_INLINE void Rotate_Z(float s,float c)
266 {
267 float tmp1,tmp2;
268 tmp1 = Row[0][0]; tmp2 = Row[0][1];
269 Row[0][0] = (float)( c*tmp1 + s*tmp2);
270 Row[0][1] = (float)(-s*tmp1 + c*tmp2);
271 tmp1 = Row[1][0]; tmp2 = Row[1][1];
272 Row[1][0] = (float)( c*tmp1 + s*tmp2);
273 Row[1][1] = (float)(-s*tmp1 + c*tmp2);
274 tmp1 = Row[2][0]; tmp2 = Row[2][1];
275 Row[2][0] = (float)( c*tmp1 + s*tmp2);
276 Row[2][1] = (float)(-s*tmp1 + c*tmp2);
277 }
278 TT_INLINE void Scale(float scale)
279 {
280 Row[0][0] *= scale;
281 Row[1][0] *= scale;
282 Row[2][0] *= scale;
283 Row[0][1] *= scale;
284 Row[1][1] *= scale;
285 Row[2][1] *= scale;
286 Row[0][2] *= scale;
287 Row[1][2] *= scale;
288 Row[2][2] *= scale;
289 }
290 TT_INLINE void Scale(float x, float y, float z)
291 {
292 Row[0][0] *= x;
293 Row[1][0] *= x;
294 Row[2][0] *= x;
295 Row[0][1] *= y;
296 Row[1][1] *= y;
297 Row[2][1] *= y;
298 Row[0][2] *= z;
299 Row[1][2] *= z;
300 Row[2][2] *= z;
301 }
302 TT_INLINE void Scale(Vector3 &scale)
303 {
304 Scale(scale.X, scale.Y, scale.Z);
305 }
306 TT_INLINE void Pre_Rotate_X(float theta)
307 {
308 float tmp1,tmp2;
309 float c,s;
310 c = cosf(theta);
311 s = sinf(theta);
312 tmp1 = Row[1][0]; tmp2 = Row[2][0];
313 Row[1][0] = (float)(c*tmp1 - s*tmp2);
314 Row[2][0] = (float)(s*tmp1 + c*tmp2);
315 tmp1 = Row[1][1]; tmp2 = Row[2][1];
316 Row[1][1] = (float)(c*tmp1 - s*tmp2);
317 Row[2][1] = (float)(s*tmp1 + c*tmp2);
318 tmp1 = Row[1][2]; tmp2 = Row[2][2];
319 Row[1][2] = (float)(c*tmp1 - s*tmp2);
320 Row[2][2] = (float)(s*tmp1 + c*tmp2);
321 tmp1 = Row[1][3]; tmp2 = Row[2][3];
322 Row[1][3] = (float)(c*tmp1 - s*tmp2);
323 Row[2][3] = (float)(s*tmp1 + c*tmp2);
324 }
325 TT_INLINE void Pre_Rotate_Y(float theta)
326 {
327 float tmp1,tmp2;
328 float c,s;
329 c = cosf(theta);
330 s = sinf(theta);
331 tmp1 = Row[0][0]; tmp2 = Row[2][0];
332 Row[0][0] = (float)( c*tmp1 + s*tmp2);
333 Row[2][0] = (float)(-s*tmp1 + c*tmp2);
334 tmp1 = Row[0][1]; tmp2 = Row[2][1];
335 Row[0][1] = (float)( c*tmp1 + s*tmp2);
336 Row[2][1] = (float)(-s*tmp1 + c*tmp2);
337 tmp1 = Row[0][2]; tmp2 = Row[2][2];
338 Row[0][2] = (float)( c*tmp1 + s*tmp2);
339 Row[2][2] = (float)(-s*tmp1 + c*tmp2);
340 tmp1 = Row[0][3]; tmp2 = Row[2][3];
341 Row[0][3] = (float)( c*tmp1 + s*tmp2);
342 Row[2][3] = (float)(-s*tmp1 + c*tmp2);
343 }
344 TT_INLINE void Pre_Rotate_Z(float theta)
345 {
346 float tmp1,tmp2;
347 float c,s;
348 c = cosf(theta);
349 s = sinf(theta);
350 tmp1 = Row[0][0]; tmp2 = Row[1][0];
351 Row[0][0] = (float)(c*tmp1 - s*tmp2);
352 Row[1][0] = (float)(s*tmp1 + c*tmp2);
353 tmp1 = Row[0][1]; tmp2 = Row[1][1];
354 Row[0][1] = (float)(c*tmp1 - s*tmp2);
355 Row[1][1] = (float)(s*tmp1 + c*tmp2);
356 tmp1 = Row[0][2]; tmp2 = Row[1][2];
357 Row[0][2] = (float)(c*tmp1 - s*tmp2);
358 Row[1][2] = (float)(s*tmp1 + c*tmp2);
359 tmp1 = Row[0][3]; tmp2 = Row[1][3];
360 Row[0][3] = (float)(c*tmp1 - s*tmp2);
361 Row[1][3] = (float)(s*tmp1 + c*tmp2);
362 }
363 TT_INLINE void Pre_Rotate_X(float s,float c)
364 {
365 float tmp1,tmp2;
366 tmp1 = Row[1][0]; tmp2 = Row[2][0];
367 Row[1][0] = (float)(c*tmp1 - s*tmp2);
368 Row[2][0] = (float)(s*tmp1 + c*tmp2);
369 tmp1 = Row[1][1]; tmp2 = Row[2][1];
370 Row[1][1] = (float)(c*tmp1 - s*tmp2);
371 Row[2][1] = (float)(s*tmp1 + c*tmp2);
372 tmp1 = Row[1][2]; tmp2 = Row[2][2];
373 Row[1][2] = (float)(c*tmp1 - s*tmp2);
374 Row[2][2] = (float)(s*tmp1 + c*tmp2);
375 tmp1 = Row[1][3]; tmp2 = Row[2][3];
376 Row[1][3] = (float)(c*tmp1 - s*tmp2);
377 Row[2][3] = (float)(s*tmp1 + c*tmp2);
378 }
379 TT_INLINE void Pre_Rotate_Y(float s,float c)
380 {
381 float tmp1,tmp2;
382 tmp1 = Row[0][0]; tmp2 = Row[2][0];
383 Row[0][0] = (float)( c*tmp1 + s*tmp2);
384 Row[2][0] = (float)(-s*tmp1 + c*tmp2);
385 tmp1 = Row[0][1]; tmp2 = Row[2][1];
386 Row[0][1] = (float)( c*tmp1 + s*tmp2);
387 Row[2][1] = (float)(-s*tmp1 + c*tmp2);
388 tmp1 = Row[0][2]; tmp2 = Row[2][2];
389 Row[0][2] = (float)( c*tmp1 + s*tmp2);
390 Row[2][2] = (float)(-s*tmp1 + c*tmp2);
391 tmp1 = Row[0][3]; tmp2 = Row[2][3];
392 Row[0][3] = (float)( c*tmp1 + s*tmp2);
393 Row[2][3] = (float)(-s*tmp1 + c*tmp2);
394 }
395 TT_INLINE void Pre_Rotate_Z(float s,float c)
396 {
397 float tmp1,tmp2;
398 tmp1 = Row[0][0]; tmp2 = Row[1][0];
399 Row[0][0] = (float)(c*tmp1 - s*tmp2);
400 Row[1][0] = (float)(s*tmp1 + c*tmp2);
401 tmp1 = Row[0][1]; tmp2 = Row[1][1];
402 Row[0][1] = (float)(c*tmp1 - s*tmp2);
403 Row[1][1] = (float)(s*tmp1 + c*tmp2);
404 tmp1 = Row[0][2]; tmp2 = Row[1][2];
405 Row[0][2] = (float)(c*tmp1 - s*tmp2);
406 Row[1][2] = (float)(s*tmp1 + c*tmp2);
407 tmp1 = Row[0][3]; tmp2 = Row[1][3];
408 Row[0][3] = (float)(c*tmp1 - s*tmp2);
409 Row[1][3] = (float)(s*tmp1 + c*tmp2);
410 }
411 TT_INLINE void In_Place_Pre_Rotate_X(float theta)
412 {
413 float tmp1,tmp2;
414 float c,s;
415 c = cosf(theta);
416 s = sinf(theta);
417 tmp1 = Row[1][0]; tmp2 = Row[2][0];
418 Row[1][0] = (float)(c*tmp1 - s*tmp2);
419 Row[2][0] = (float)(s*tmp1 + c*tmp2);
420 tmp1 = Row[1][1]; tmp2 = Row[2][1];
421 Row[1][1] = (float)(c*tmp1 - s*tmp2);
422 Row[2][1] = (float)(s*tmp1 + c*tmp2);
423 tmp1 = Row[1][2]; tmp2 = Row[2][2];
424 Row[1][2] = (float)(c*tmp1 - s*tmp2);
425 Row[2][2] = (float)(s*tmp1 + c*tmp2);
426 }
427 TT_INLINE void In_Place_Pre_Rotate_Y(float theta)
428 {
429 float tmp1,tmp2;
430 float c,s;
431 c = cosf(theta);
432 s = sinf(theta);
433 tmp1 = Row[0][0]; tmp2 = Row[2][0];
434 Row[0][0] = (float)( c*tmp1 + s*tmp2);
435 Row[2][0] = (float)(-s*tmp1 + c*tmp2);
436 tmp1 = Row[0][1]; tmp2 = Row[2][1];
437 Row[0][1] = (float)( c*tmp1 + s*tmp2);
438 Row[2][1] = (float)(-s*tmp1 + c*tmp2);
439 tmp1 = Row[0][2]; tmp2 = Row[2][2];
440 Row[0][2] = (float)( c*tmp1 + s*tmp2);
441 Row[2][2] = (float)(-s*tmp1 + c*tmp2);
442 }
443 TT_INLINE void In_Place_Pre_Rotate_Z(float theta)
444 {
445 float tmp1,tmp2;
446 float c,s;
447 c = cosf(theta);
448 s = sinf(theta);
449 tmp1 = Row[0][0]; tmp2 = Row[1][0];
450 Row[0][0] = (float)(c*tmp1 - s*tmp2);
451 Row[1][0] = (float)(s*tmp1 + c*tmp2);
452 tmp1 = Row[0][1]; tmp2 = Row[1][1];
453 Row[0][1] = (float)(c*tmp1 - s*tmp2);
454 Row[1][1] = (float)(s*tmp1 + c*tmp2);
455 tmp1 = Row[0][2]; tmp2 = Row[1][2];
456 Row[0][2] = (float)(c*tmp1 - s*tmp2);
457 Row[1][2] = (float)(s*tmp1 + c*tmp2);
458 }
459 TT_INLINE void In_Place_Pre_Rotate_X(float s,float c)
460 {
461 float tmp1,tmp2;
462 tmp1 = Row[1][0]; tmp2 = Row[2][0];
463 Row[1][0] = (float)(c*tmp1 - s*tmp2);
464 Row[2][0] = (float)(s*tmp1 + c*tmp2);
465 tmp1 = Row[1][1]; tmp2 = Row[2][1];
466 Row[1][1] = (float)(c*tmp1 - s*tmp2);
467 Row[2][1] = (float)(s*tmp1 + c*tmp2);
468 tmp1 = Row[1][2]; tmp2 = Row[2][2];
469 Row[1][2] = (float)(c*tmp1 - s*tmp2);
470 Row[2][2] = (float)(s*tmp1 + c*tmp2);
471 }
472 TT_INLINE void In_Place_Pre_Rotate_Y(float s,float c)
473 {
474 float tmp1,tmp2;
475 tmp1 = Row[0][0]; tmp2 = Row[2][0];
476 Row[0][0] = (float)( c*tmp1 + s*tmp2);
477 Row[2][0] = (float)(-s*tmp1 + c*tmp2);
478 tmp1 = Row[0][1]; tmp2 = Row[2][1];
479 Row[0][1] = (float)( c*tmp1 + s*tmp2);
480 Row[2][1] = (float)(-s*tmp1 + c*tmp2);
481 tmp1 = Row[0][2]; tmp2 = Row[2][2];
482 Row[0][2] = (float)( c*tmp1 + s*tmp2);
483 Row[2][2] = (float)(-s*tmp1 + c*tmp2);
484 }
485 TT_INLINE void In_Place_Pre_Rotate_Z(float s,float c)
486 {
487 float tmp1,tmp2;
488 tmp1 = Row[0][0]; tmp2 = Row[1][0];
489 Row[0][0] = (float)(c*tmp1 - s*tmp2);
490 Row[1][0] = (float)(s*tmp1 + c*tmp2);
491 tmp1 = Row[0][1]; tmp2 = Row[1][1];
492 Row[0][1] = (float)(c*tmp1 - s*tmp2);
493 Row[1][1] = (float)(s*tmp1 + c*tmp2);
494 tmp1 = Row[0][2]; tmp2 = Row[1][2];
495 Row[0][2] = (float)(c*tmp1 - s*tmp2);
496 Row[1][2] = (float)(s*tmp1 + c*tmp2);
497 }
498
499 int Is_Orthogonal(void) const;
500 Matrix3D& operator *= (const Matrix3D& matrix);
501 Vector3 operator * (const Vector3& vector) const;
502 static void Transform_Vector(const Matrix3D & A,const Vector3 & in,Vector3 * out)
503 {
504 Vector3 tmp;
505 Vector3 * v;
506 if (out == &in)
507 {
508 tmp = in;
509 v = &tmp;
510 }
511 else
512 {
513 v = (Vector3 *)∈
514 }
515 out->X = (A.Row[0][0] * v->X + A.Row[0][1] * v->Y + A.Row[0][2] * v->Z + A.Row[0][3]);
516 out->Y = (A.Row[1][0] * v->X + A.Row[1][1] * v->Y + A.Row[1][2] * v->Z + A.Row[1][3]);
517 out->Z = (A.Row[2][0] * v->X + A.Row[2][1] * v->Y + A.Row[2][2] * v->Z + A.Row[2][3]);
518 }
519 TT_INLINE Vector3 Get_X_Vector() const { return Vector3(Row[0][0], Row[1][0], Row[2][0]); }
520 TT_INLINE Vector3 Get_Y_Vector() const { return Vector3(Row[0][1], Row[1][1], Row[2][1]); }
521 TT_INLINE Vector3 Get_Z_Vector() const { return Vector3(Row[0][2], Row[1][2], Row[2][2]); }
522 TT_INLINE void Get_X_Vector(Vector3 * set_x) const { set_x->Set(Row[0][0], Row[1][0], Row[2][0]); }
523 TT_INLINE void Get_Y_Vector(Vector3 * set_y) const { set_y->Set(Row[0][1], Row[1][1], Row[2][1]); }
524 TT_INLINE void Get_Z_Vector(Vector3 * set_z) const { set_z->Set(Row[0][2], Row[1][2], Row[2][2]); }
525 void Get_Inverse(Matrix3D & set_inverse) const;
526 void Copy_3x3_Matrix(float matrix[3][3]);
527 void Transform_Min_Max_AABox(const Vector3 & min,const Vector3 & max,Vector3 * set_min,Vector3 * set_max) const;
528 void Transform_Center_Extent_AABox(const Vector3 & center,const Vector3 & extent,Vector3 * set_center,Vector3 * set_extent) const;
529 static void Multiply(const Matrix3D &A,const Matrix3D &B,Matrix3D * set_result);
530 static TT_INLINE void Rotate_Vector(const Matrix3D & A,const Vector3 & in,Vector3 * out)
531 {
532 Vector3 tmp;
533 Vector3 * v;
534 if (out == &in)
535 {
536 tmp = in;
537 v = &tmp;
538 }
539 else
540 {
541 v = (Vector3 *)∈
542 }
543 out->X = (A[0][0] * v->X + A[0][1] * v->Y + A[0][2] * v->Z);
544 out->Y = (A[1][0] * v->X + A[1][1] * v->Y + A[1][2] * v->Z);
545 out->Z = (A[2][0] * v->X + A[2][1] * v->Y + A[2][2] * v->Z);
546 }
547 static TT_INLINE void Inverse_Transform_Vector(const Matrix3D & A,const Vector3 & in,Vector3 * out)
548 {
549 Vector3 tmp;
550 Vector3 * v;
551 if (out == &in)
552 {
553 tmp = in;
554 v = &tmp;
555 }
556 else
557 {
558 v = (Vector3 *)∈
559 }
560 Vector3 diff(v->X - A[0][3], v->Y - A[1][3], v->Z - A[2][3]);
561 Matrix3D::Inverse_Rotate_Vector(A, diff, out);
562 }
563 static TT_INLINE void Inverse_Rotate_Vector(const Matrix3D & A,const Vector3 & in,Vector3 * out)
564 {
565 Vector3 tmp;
566 Vector3 * v;
567 if (out == &in)
568 {
569 tmp = in;
570 v = &tmp;
571 }
572 else
573 {
574 v = (Vector3 *)∈
575 }
576 out->X = (A[0][0] * v->X + A[1][0] * v->Y + A[2][0] * v->Z);
577 out->Y = (A[0][1] * v->X + A[1][1] * v->Y + A[2][1] * v->Z);
578 out->Z = (A[0][2] * v->X + A[1][2] * v->Y + A[2][2] * v->Z);
579 }
580 static Matrix3D Reflect_Plane(const PlaneClass& _plane);
581 PlaneClass Transform_Plane(const PlaneClass& _plane) const;
582 static bool Solve_Linear_System(Matrix3D & system);
583 void Re_Orthogonalize(void);
584}; // 48
585
586TT_INLINE Matrix3D operator * (const Matrix3D &A,const Matrix3D &B)
587{
588 Matrix3D C;
589 float tmp1,tmp2,tmp3;
590 tmp1 = B[0][0];
591 tmp2 = B[1][0];
592 tmp3 = B[2][0];
593 C[0][0] = (float)(A[0][0]*tmp1 + A[0][1]*tmp2 + A[0][2]*tmp3);
594 C[1][0] = (float)(A[1][0]*tmp1 + A[1][1]*tmp2 + A[1][2]*tmp3);
595 C[2][0] = (float)(A[2][0]*tmp1 + A[2][1]*tmp2 + A[2][2]*tmp3);
596 tmp1 = B[0][1];
597 tmp2 = B[1][1];
598 tmp3 = B[2][1];
599 C[0][1] = (float)(A[0][0]*tmp1 + A[0][1]*tmp2 + A[0][2]*tmp3);
600 C[1][1] = (float)(A[1][0]*tmp1 + A[1][1]*tmp2 + A[1][2]*tmp3);
601 C[2][1] = (float)(A[2][0]*tmp1 + A[2][1]*tmp2 + A[2][2]*tmp3);
602 tmp1 = B[0][2];
603 tmp2 = B[1][2];
604 tmp3 = B[2][2];
605 C[0][2] = (float)(A[0][0]*tmp1 + A[0][1]*tmp2 + A[0][2]*tmp3);
606 C[1][2] = (float)(A[1][0]*tmp1 + A[1][1]*tmp2 + A[1][2]*tmp3);
607 C[2][2] = (float)(A[2][0]*tmp1 + A[2][1]*tmp2 + A[2][2]*tmp3);
608 tmp1 = B[0][3];
609 tmp2 = B[1][3];
610 tmp3 = B[2][3];
611 C[0][3] = (float)(A[0][0]*tmp1 + A[0][1]*tmp2 + A[0][2]*tmp3 + A[0][3]);
612 C[1][3] = (float)(A[1][0]*tmp1 + A[1][1]*tmp2 + A[1][2]*tmp3 + A[1][3]);
613 C[2][3] = (float)(A[2][0]*tmp1 + A[2][1]*tmp2 + A[2][2]*tmp3 + A[2][3]);
614 return C;
615}
616TT_INLINE bool operator == (const Matrix3D &A, const Matrix3D &B)
617{
618 return (A[0].X == B[0].X && A[0].Y == B[0].Y && A[0].Z == B[0].Z && A[0].W == B[0].W
619 && A[1].X == B[1].X && A[1].Y == B[1].Y && A[1].Z == B[1].Z && A[1].W == B[1].W
620 && A[2].X == B[2].X && A[2].Y == B[2].Y && A[2].Z == B[2].Z && A[2].W == B[2].W);
621}
622
623TT_INLINE bool operator != (const Matrix3D &A, const Matrix3D &B)
624{
625 return !(A == B);
626}
627#endif