6 void Matrix4x4_Copy (matrix4x4_t *out, matrix4x4_t *in)
11 void Matrix4x4_CopyRotateOnly (matrix4x4_t *out, matrix4x4_t *in)
13 out->m[0][0] = in->m[0][0];
14 out->m[0][1] = in->m[0][1];
15 out->m[0][2] = in->m[0][2];
17 out->m[1][0] = in->m[1][0];
18 out->m[1][1] = in->m[1][1];
19 out->m[1][2] = in->m[1][2];
21 out->m[2][0] = in->m[2][0];
22 out->m[2][1] = in->m[2][1];
23 out->m[2][2] = in->m[2][2];
31 void Matrix4x4_CopyTranslateOnly (matrix4x4_t *out, matrix4x4_t *in)
36 out->m[0][3] = in->m[0][3];
40 out->m[1][3] = in->m[0][3];
44 out->m[2][3] = in->m[0][3];
51 void Matrix4x4_FromMatrix3x4 (matrix4x4_t *out, matrix3x4_t *in)
53 out->m[0][0] = in->m[0][0];
54 out->m[0][1] = in->m[0][1];
55 out->m[0][2] = in->m[0][2];
56 out->m[0][3] = in->m[0][3];
57 out->m[1][0] = in->m[1][0];
58 out->m[1][1] = in->m[1][1];
59 out->m[1][2] = in->m[1][2];
60 out->m[1][3] = in->m[1][3];
61 out->m[2][0] = in->m[2][0];
62 out->m[2][1] = in->m[2][1];
63 out->m[2][2] = in->m[2][2];
64 out->m[2][3] = in->m[2][3];
71 void Matrix4x4_Concat (matrix4x4_t *out, const matrix4x4_t *in1, const matrix4x4_t *in2)
73 out->m[0][0] = in1->m[0][0] * in2->m[0][0] + in1->m[0][1] * in2->m[1][0] + in1->m[0][2] * in2->m[2][0] + in1->m[0][3] * in2->m[3][0];
74 out->m[0][1] = in1->m[0][0] * in2->m[0][1] + in1->m[0][1] * in2->m[1][1] + in1->m[0][2] * in2->m[2][1] + in1->m[0][3] * in2->m[3][1];
75 out->m[0][2] = in1->m[0][0] * in2->m[0][2] + in1->m[0][1] * in2->m[1][2] + in1->m[0][2] * in2->m[2][2] + in1->m[0][3] * in2->m[3][2];
76 out->m[0][3] = in1->m[0][0] * in2->m[0][3] + in1->m[0][1] * in2->m[1][3] + in1->m[0][2] * in2->m[2][3] + in1->m[0][3] * in2->m[3][3];
77 out->m[1][0] = in1->m[1][0] * in2->m[0][0] + in1->m[1][1] * in2->m[1][0] + in1->m[1][2] * in2->m[2][0] + in1->m[1][3] * in2->m[3][0];
78 out->m[1][1] = in1->m[1][0] * in2->m[0][1] + in1->m[1][1] * in2->m[1][1] + in1->m[1][2] * in2->m[2][1] + in1->m[1][3] * in2->m[3][1];
79 out->m[1][2] = in1->m[1][0] * in2->m[0][2] + in1->m[1][1] * in2->m[1][2] + in1->m[1][2] * in2->m[2][2] + in1->m[1][3] * in2->m[3][2];
80 out->m[1][3] = in1->m[1][0] * in2->m[0][3] + in1->m[1][1] * in2->m[1][3] + in1->m[1][2] * in2->m[2][3] + in1->m[1][3] * in2->m[3][3];
81 out->m[2][0] = in1->m[2][0] * in2->m[0][0] + in1->m[2][1] * in2->m[1][0] + in1->m[2][2] * in2->m[2][0] + in1->m[2][3] * in2->m[3][0];
82 out->m[2][1] = in1->m[2][0] * in2->m[0][1] + in1->m[2][1] * in2->m[1][1] + in1->m[2][2] * in2->m[2][1] + in1->m[2][3] * in2->m[3][1];
83 out->m[2][2] = in1->m[2][0] * in2->m[0][2] + in1->m[2][1] * in2->m[1][2] + in1->m[2][2] * in2->m[2][2] + in1->m[2][3] * in2->m[3][2];
84 out->m[2][3] = in1->m[2][0] * in2->m[0][3] + in1->m[2][1] * in2->m[1][3] + in1->m[2][2] * in2->m[2][3] + in1->m[2][3] * in2->m[3][3];
85 out->m[3][0] = in1->m[3][0] * in2->m[0][0] + in1->m[3][1] * in2->m[1][0] + in1->m[3][2] * in2->m[2][0] + in1->m[3][3] * in2->m[3][0];
86 out->m[3][1] = in1->m[3][0] * in2->m[0][1] + in1->m[3][1] * in2->m[1][1] + in1->m[3][2] * in2->m[2][1] + in1->m[3][3] * in2->m[3][1];
87 out->m[3][2] = in1->m[3][0] * in2->m[0][2] + in1->m[3][1] * in2->m[1][2] + in1->m[3][2] * in2->m[2][2] + in1->m[3][3] * in2->m[3][2];
88 out->m[3][3] = in1->m[3][0] * in2->m[0][3] + in1->m[3][1] * in2->m[1][3] + in1->m[3][2] * in2->m[2][3] + in1->m[3][3] * in2->m[3][3];
91 void Matrix4x4_Transpose (matrix4x4_t *out, const matrix4x4_t *in1)
94 scale = 3.0 / (in1->m[0][0] * in1->m[0][0]
95 + in1->m[0][1] * in1->m[0][1]
96 + in1->m[0][2] * in1->m[0][2]
97 + in1->m[1][0] * in1->m[1][0]
98 + in1->m[1][1] * in1->m[1][1]
99 + in1->m[1][2] * in1->m[1][2]
100 + in1->m[2][0] * in1->m[2][0]
101 + in1->m[2][1] * in1->m[2][1]
102 + in1->m[2][2] * in1->m[2][2]);
103 out->m[0][0] = in1->m[0][0] * scale;
104 out->m[0][1] = in1->m[1][0] * scale;
105 out->m[0][2] = in1->m[2][0] * scale;
106 out->m[0][3] = in1->m[3][0];
107 out->m[1][0] = in1->m[0][1] * scale;
108 out->m[1][1] = in1->m[1][1] * scale;
109 out->m[1][2] = in1->m[2][1] * scale;
110 out->m[1][3] = in1->m[3][1];
111 out->m[2][0] = in1->m[0][2] * scale;
112 out->m[2][1] = in1->m[1][2] * scale;
113 out->m[2][2] = in1->m[2][2] * scale;
114 out->m[2][3] = in1->m[3][2];
115 out->m[3][0] = in1->m[0][3];
116 out->m[3][1] = in1->m[1][3];
117 out->m[3][2] = in1->m[2][3];
118 out->m[3][3] = in1->m[3][3];
121 void Matrix4x4_CreateIdentity (matrix4x4_t *out)
141 void Matrix4x4_CreateTranslate (matrix4x4_t *out, float x, float y, float z)
161 void Matrix4x4_CreateRotate (matrix4x4_t *out, float angle, float x, float y, float z)
167 len = 1.0f / sqrt(len);
172 angle *= M_PI / 180.0;
176 out->m[0][0]=x * x + c * (1 - x * x);
177 out->m[0][1]=x * y * (1 - c) + z * s;
178 out->m[0][2]=z * x * (1 - c) - y * s;
180 out->m[1][0]=x * y * (1 - c) - z * s;
181 out->m[1][1]=y * y + c * (1 - y * y);
182 out->m[1][2]=y * z * (1 - c) + x * s;
184 out->m[2][0]=z * x * (1 - c) + y * s;
185 out->m[2][1]=y * z * (1 - c) - x * s;
186 out->m[2][2]=z * z + c * (1 - z * z);
194 void Matrix4x4_CreateScale (matrix4x4_t *out, float x)
214 void Matrix4x4_CreateScale3 (matrix4x4_t *out, float x, float y, float z)
234 void Matrix4x4_ToVectors(const matrix4x4_t *in, float vx[3], float vy[3], float vz[3], float t[3])
250 void Matrix4x4_FromVectors(matrix4x4_t *out, const float vx[3], const float vy[3], const float vz[3], const float t[3])
252 out->m[0][0] = vx[0];
253 out->m[0][1] = vy[0];
254 out->m[0][2] = vz[0];
256 out->m[1][0] = vx[1];
257 out->m[1][1] = vy[1];
258 out->m[1][2] = vz[1];
260 out->m[2][0] = vx[2];
261 out->m[2][1] = vy[2];
262 out->m[2][2] = vz[2];
270 void Matrix4x4_Transform (const matrix4x4_t *in, const float v[3], float out[3])
272 out[0] = v[0] * in->m[0][0] + v[1] * in->m[0][1] + v[2] * in->m[0][2] + in->m[0][3];
273 out[1] = v[0] * in->m[1][0] + v[1] * in->m[1][1] + v[2] * in->m[1][2] + in->m[1][3];
274 out[2] = v[0] * in->m[2][0] + v[1] * in->m[2][1] + v[2] * in->m[2][2] + in->m[2][3];
277 void Matrix4x4_Transform4 (const matrix4x4_t *in, const float v[4], float out[4])
279 out[0] = v[0] * in->m[0][0] + v[1] * in->m[0][1] + v[2] * in->m[0][2] + v[3] * in->m[0][3];
280 out[1] = v[0] * in->m[1][0] + v[1] * in->m[1][1] + v[2] * in->m[1][2] + v[3] * in->m[1][3];
281 out[2] = v[0] * in->m[2][0] + v[1] * in->m[2][1] + v[2] * in->m[2][2] + v[3] * in->m[2][3];
282 out[3] = v[0] * in->m[3][0] + v[1] * in->m[3][1] + v[2] * in->m[3][2] + v[3] * in->m[3][3];
285 void Matrix4x4_SimpleUntransform (const matrix4x4_t *in, const float v[3], float out[3])
288 t[0] = v[0] - in->m[0][3];
289 t[1] = v[1] - in->m[1][3];
290 t[2] = v[2] - in->m[2][3];
291 out[0] = t[0] * in->m[0][0] + t[1] * in->m[1][0] + t[2] * in->m[2][0];
292 out[1] = t[0] * in->m[0][1] + t[1] * in->m[1][1] + t[2] * in->m[2][1];
293 out[2] = t[0] * in->m[0][2] + t[1] * in->m[1][2] + t[2] * in->m[2][2];
297 void Matrix4x4_ConcatTranslate (matrix4x4_t *out, float x, float y, float z)
299 matrix4x4_t base, temp;
300 Matrix4x4_Copy(out, &base);
301 Matrix4x4_CreateTranslate(&temp, x, y, z);
302 Matrix4x4_Concat(out, &base, &temp);
306 void Matrix4x4_ConcatRotate (matrix4x4_t *out, float angle, float x, float y, float z)
308 matrix4x4_t base, temp;
309 Matrix4x4_Copy(out, &base);
310 Matrix4x4_CreateRotate(&temp, angle, x, y, z);
311 Matrix4x4_Concat(out, &base, &temp);
315 void Matrix4x4_ConcatScale (matrix4x4_t *out, float x)
317 matrix4x4_t base, temp;
318 Matrix4x4_Copy(out, &base);
319 Matrix4x4_CreateScale(&temp, x);
320 Matrix4x4_Concat(out, &base, &temp);
324 void Matrix4x4_ConcatScale3 (matrix4x4_t *out, float x, float y, float z)
326 matrix4x4_t base, temp;
327 Matrix4x4_Copy(out, &base);
328 Matrix4x4_CreateScale3(&temp, x, y, z);
329 Matrix4x4_Concat(out, &base, &temp);
339 void Matrix3x4_Copy (matrix3x4_t *out, matrix3x4_t *in)
344 void Matrix3x4_CopyRotateOnly (matrix3x4_t *out, matrix3x4_t *in)
346 out->m[0][0] = in->m[0][0];
347 out->m[0][1] = in->m[0][1];
348 out->m[0][2] = in->m[0][2];
350 out->m[1][0] = in->m[1][0];
351 out->m[1][1] = in->m[1][1];
352 out->m[1][2] = in->m[1][2];
354 out->m[2][0] = in->m[2][0];
355 out->m[2][1] = in->m[2][1];
356 out->m[2][2] = in->m[2][2];
360 void Matrix3x4_CopyTranslateOnly (matrix3x4_t *out, matrix3x4_t *in)
365 out->m[0][3] = in->m[0][3];
369 out->m[1][3] = in->m[0][3];
373 out->m[2][3] = in->m[0][3];
376 void Matrix3x4_FromMatrix4x4 (matrix3x4_t *out, matrix4x4_t *in)
378 out->m[0][0] = in->m[0][0];
379 out->m[0][1] = in->m[0][1];
380 out->m[0][2] = in->m[0][2];
381 out->m[0][3] = in->m[0][3];
382 out->m[1][0] = in->m[1][0];
383 out->m[1][1] = in->m[1][1];
384 out->m[1][2] = in->m[1][2];
385 out->m[1][3] = in->m[1][3];
386 out->m[2][0] = in->m[2][0];
387 out->m[2][1] = in->m[2][1];
388 out->m[2][2] = in->m[2][2];
389 out->m[2][3] = in->m[2][3];
392 void Matrix3x4_Concat (matrix3x4_t *out, const matrix3x4_t *in1, const matrix3x4_t *in2)
394 out->m[0][0] = in1->m[0][0] * in2->m[0][0] + in1->m[0][1] * in2->m[1][0] + in1->m[0][2] * in2->m[2][0];
395 out->m[0][1] = in1->m[0][0] * in2->m[0][1] + in1->m[0][1] * in2->m[1][1] + in1->m[0][2] * in2->m[2][1];
396 out->m[0][2] = in1->m[0][0] * in2->m[0][2] + in1->m[0][1] * in2->m[1][2] + in1->m[0][2] * in2->m[2][2];
397 out->m[0][3] = in1->m[0][0] * in2->m[0][3] + in1->m[0][1] * in2->m[1][3] + in1->m[0][2] * in2->m[2][3] + in1->m[0][3];
398 out->m[1][0] = in1->m[1][0] * in2->m[0][0] + in1->m[1][1] * in2->m[1][0] + in1->m[1][2] * in2->m[2][0];
399 out->m[1][1] = in1->m[1][0] * in2->m[0][1] + in1->m[1][1] * in2->m[1][1] + in1->m[1][2] * in2->m[2][1];
400 out->m[1][2] = in1->m[1][0] * in2->m[0][2] + in1->m[1][1] * in2->m[1][2] + in1->m[1][2] * in2->m[2][2];
401 out->m[1][3] = in1->m[1][0] * in2->m[0][3] + in1->m[1][1] * in2->m[1][3] + in1->m[1][2] * in2->m[2][3] + in1->m[1][3];
402 out->m[2][0] = in1->m[2][0] * in2->m[0][0] + in1->m[2][1] * in2->m[1][0] + in1->m[2][2] * in2->m[2][0];
403 out->m[2][1] = in1->m[2][0] * in2->m[0][1] + in1->m[2][1] * in2->m[1][1] + in1->m[2][2] * in2->m[2][1];
404 out->m[2][2] = in1->m[2][0] * in2->m[0][2] + in1->m[2][1] * in2->m[1][2] + in1->m[2][2] * in2->m[2][2];
405 out->m[2][3] = in1->m[2][0] * in2->m[0][3] + in1->m[2][1] * in2->m[1][3] + in1->m[2][2] * in2->m[2][3] + in1->m[2][3];
408 void Matrix3x4_Transpose3x3 (matrix3x4_t *out, const matrix3x4_t *in1)
411 scale = 3.0 / (in1->m[0][0] * in1->m[0][0]
412 + in1->m[0][1] * in1->m[0][1]
413 + in1->m[0][2] * in1->m[0][2]
414 + in1->m[1][0] * in1->m[1][0]
415 + in1->m[1][1] * in1->m[1][1]
416 + in1->m[1][2] * in1->m[1][2]
417 + in1->m[2][0] * in1->m[2][0]
418 + in1->m[2][1] * in1->m[2][1]
419 + in1->m[2][2] * in1->m[2][2]);
420 out->m[0][0] = in1->m[0][0] * scale;
421 out->m[0][1] = in1->m[1][0] * scale;
422 out->m[0][2] = in1->m[2][0] * scale;
424 out->m[1][0] = in1->m[0][1] * scale;
425 out->m[1][1] = in1->m[1][1] * scale;
426 out->m[1][2] = in1->m[2][1] * scale;
428 out->m[2][0] = in1->m[0][2] * scale;
429 out->m[2][1] = in1->m[1][2] * scale;
430 out->m[2][2] = in1->m[2][2] * scale;
434 void Matrix3x4_CreateIdentity (matrix3x4_t *out)
450 void Matrix3x4_CreateTranslate (matrix3x4_t *out, float x, float y, float z)
466 void Matrix3x4_CreateRotate (matrix3x4_t *out, float angle, float x, float y, float z)
472 len = 1.0f / sqrt(len);
477 angle *= M_PI / 180.0;
481 out->m[0][0]=x * x + c * (1 - x * x);
482 out->m[0][1]=x * y * (1 - c) + z * s;
483 out->m[0][2]=z * x * (1 - c) - y * s;
485 out->m[1][0]=x * y * (1 - c) - z * s;
486 out->m[1][1]=y * y + c * (1 - y * y);
487 out->m[1][2]=y * z * (1 - c) + x * s;
489 out->m[2][0]=z * x * (1 - c) + y * s;
490 out->m[2][1]=y * z * (1 - c) - x * s;
491 out->m[2][2]=z * z + c * (1 - z * z);
495 void Matrix3x4_CreateScale (matrix3x4_t *out, float x)
511 void Matrix3x4_CreateScale3 (matrix3x4_t *out, float x, float y, float z)
527 void Matrix3x4_ToVectors(const matrix3x4_t *in, float vx[3], float vy[3], float vz[3], float t[3])
543 void Matrix3x4_FromVectors(matrix3x4_t *out, const float vx[3], const float vy[3], const float vz[3], const float t[3])
545 out->m[0][0] = vx[0];
546 out->m[0][1] = vy[0];
547 out->m[0][2] = vz[0];
549 out->m[1][0] = vx[1];
550 out->m[1][1] = vy[1];
551 out->m[1][2] = vz[1];
553 out->m[2][0] = vx[2];
554 out->m[2][1] = vy[2];
555 out->m[2][2] = vz[2];
559 void Matrix3x4_Transform (const matrix3x4_t *in, const float v[3], float out[3])
561 out[0] = v[0] * in->m[0][0] + v[1] * in->m[0][1] + v[2] * in->m[0][2] + in->m[0][3];
562 out[1] = v[0] * in->m[1][0] + v[1] * in->m[1][1] + v[2] * in->m[1][2] + in->m[1][3];
563 out[2] = v[0] * in->m[2][0] + v[1] * in->m[2][1] + v[2] * in->m[2][2] + in->m[2][3];
566 void Matrix3x4_SimpleUntransform (const matrix3x4_t *in, const float v[3], float out[3])
569 t[0] = v[0] - in->m[0][3];
570 t[1] = v[1] - in->m[1][3];
571 t[2] = v[2] - in->m[2][3];
572 out[0] = t[0] * in->m[0][0] + t[1] * in->m[1][0] + t[2] * in->m[2][0];
573 out[1] = t[0] * in->m[0][1] + t[1] * in->m[1][1] + t[2] * in->m[2][1];
574 out[2] = t[0] * in->m[0][2] + t[1] * in->m[1][2] + t[2] * in->m[2][2];
578 void Matrix3x4_ConcatTranslate (matrix3x4_t *out, float x, float y, float z)
580 matrix3x4_t base, temp;
581 Matrix3x4_Copy(out, &base);
582 Matrix3x4_CreateTranslate(&temp, x, y, z);
583 Matrix3x4_Concat(out, &base, &temp);
587 void Matrix3x4_ConcatRotate (matrix3x4_t *out, float angle, float x, float y, float z)
589 matrix3x4_t base, temp;
590 Matrix3x4_Copy(out, &base);
591 Matrix3x4_CreateRotate(&temp, angle, x, y, z);
592 Matrix3x4_Concat(out, &base, &temp);
596 void Matrix3x4_ConcatScale (matrix3x4_t *out, float x)
598 matrix3x4_t base, temp;
599 Matrix3x4_Copy(out, &base);
600 Matrix3x4_CreateScale(&temp, x);
601 Matrix3x4_Concat(out, &base, &temp);
605 void Matrix3x4_ConcatScale3 (matrix3x4_t *out, float x, float y, float z)
607 matrix3x4_t base, temp;
608 Matrix3x4_Copy(out, &base);
609 Matrix3x4_CreateScale3(&temp, x, y, z);
610 Matrix3x4_Concat(out, &base, &temp);