6 void Matrix4x4_Copy (matrix4x4_t *out, const matrix4x4_t *in)
11 void Matrix4x4_CopyRotateOnly (matrix4x4_t *out, const 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, const 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, const 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)
93 out->m[0][0] = in1->m[0][0];
94 out->m[0][1] = in1->m[1][0];
95 out->m[0][2] = in1->m[2][0];
96 out->m[0][3] = in1->m[3][0];
97 out->m[1][0] = in1->m[0][1];
98 out->m[1][1] = in1->m[1][1];
99 out->m[1][2] = in1->m[2][1];
100 out->m[1][3] = in1->m[3][1];
101 out->m[2][0] = in1->m[0][2];
102 out->m[2][1] = in1->m[1][2];
103 out->m[2][2] = in1->m[2][2];
104 out->m[2][3] = in1->m[3][2];
105 out->m[3][0] = in1->m[0][3];
106 out->m[3][1] = in1->m[1][3];
107 out->m[3][2] = in1->m[2][3];
108 out->m[3][3] = in1->m[3][3];
111 void Matrix4x4_Transpose3x3 (matrix4x4_t *out, const matrix4x4_t *in1)
113 out->m[0][0] = in1->m[0][0];
114 out->m[0][1] = in1->m[1][0];
115 out->m[0][2] = in1->m[2][0];
116 out->m[1][0] = in1->m[0][1];
117 out->m[1][1] = in1->m[1][1];
118 out->m[1][2] = in1->m[2][1];
119 out->m[2][0] = in1->m[0][2];
120 out->m[2][1] = in1->m[1][2];
121 out->m[2][2] = in1->m[2][2];
123 out->m[0][3] = in1->m[0][3];
124 out->m[1][3] = in1->m[1][3];
125 out->m[2][3] = in1->m[2][3];
126 out->m[3][0] = in1->m[0][3];
127 out->m[3][1] = in1->m[1][3];
128 out->m[3][2] = in1->m[2][3];
129 out->m[3][3] = in1->m[3][3];
132 void Matrix4x4_Invert_Simple (matrix4x4_t *out, const matrix4x4_t *in1)
134 // we only support uniform scaling, so assume the first row is enough
135 // (note the lack of sqrt here, because we're trying to undo the scaling,
136 // this means multiplying by the inverse scale twice - squaring it, which
137 // makes the sqrt a waste of time)
139 double scale = 1.0 / (in1->m[0][0] * in1->m[0][0] + in1->m[0][1] * in1->m[0][1] + in1->m[0][2] * in1->m[0][2]);
141 double scale = 3.0 / sqrt
142 (in1->m[0][0] * in1->m[0][0] + in1->m[0][1] * in1->m[0][1] + in1->m[0][2] * in1->m[0][2]
143 + in1->m[1][0] * in1->m[1][0] + in1->m[1][1] * in1->m[1][1] + in1->m[1][2] * in1->m[1][2]
144 + in1->m[2][0] * in1->m[2][0] + in1->m[2][1] * in1->m[2][1] + in1->m[2][2] * in1->m[2][2]);
148 // invert the rotation by transposing and multiplying by the squared
149 // recipricol of the input matrix scale as described above
150 out->m[0][0] = in1->m[0][0] * scale;
151 out->m[0][1] = in1->m[1][0] * scale;
152 out->m[0][2] = in1->m[2][0] * scale;
153 out->m[1][0] = in1->m[0][1] * scale;
154 out->m[1][1] = in1->m[1][1] * scale;
155 out->m[1][2] = in1->m[2][1] * scale;
156 out->m[2][0] = in1->m[0][2] * scale;
157 out->m[2][1] = in1->m[1][2] * scale;
158 out->m[2][2] = in1->m[2][2] * scale;
160 // invert the translate
161 out->m[0][3] = -(in1->m[0][3] * out->m[0][0] + in1->m[1][3] * out->m[0][1] + in1->m[2][3] * out->m[0][2]);
162 out->m[1][3] = -(in1->m[0][3] * out->m[1][0] + in1->m[1][3] * out->m[1][1] + in1->m[2][3] * out->m[1][2]);
163 out->m[2][3] = -(in1->m[0][3] * out->m[2][0] + in1->m[1][3] * out->m[2][1] + in1->m[2][3] * out->m[2][2]);
165 // don't know if there's anything worth doing here
172 void Matrix4x4_CreateIdentity (matrix4x4_t *out)
192 void Matrix4x4_CreateTranslate (matrix4x4_t *out, float x, float y, float z)
212 void Matrix4x4_CreateRotate (matrix4x4_t *out, float angle, float x, float y, float z)
218 len = 1.0f / sqrt(len);
223 angle *= -M_PI / 180.0;
227 out->m[0][0]=x * x + c * (1 - x * x);
228 out->m[0][1]=x * y * (1 - c) + z * s;
229 out->m[0][2]=z * x * (1 - c) - y * s;
231 out->m[1][0]=x * y * (1 - c) - z * s;
232 out->m[1][1]=y * y + c * (1 - y * y);
233 out->m[1][2]=y * z * (1 - c) + x * s;
235 out->m[2][0]=z * x * (1 - c) + y * s;
236 out->m[2][1]=y * z * (1 - c) - x * s;
237 out->m[2][2]=z * z + c * (1 - z * z);
245 void Matrix4x4_CreateScale (matrix4x4_t *out, float x)
265 void Matrix4x4_CreateScale3 (matrix4x4_t *out, float x, float y, float z)
285 void Matrix4x4_CreateFromQuakeEntity(matrix4x4_t *out, float x, float y, float z, float pitch, float yaw, float roll, float scale)
287 double angle, sr, sp, sy, cr, cp, cy;
289 angle = yaw * (M_PI*2 / 360);
292 angle = pitch * (M_PI*2 / 360);
295 angle = roll * (M_PI*2 / 360);
298 out->m[0][0] = (cp*cy) * scale;
299 out->m[0][1] = (sr*sp*cy+cr*-sy) * scale;
300 out->m[0][2] = (cr*sp*cy+-sr*-sy) * scale;
302 out->m[1][0] = (cp*sy) * scale;
303 out->m[1][1] = (sr*sp*sy+cr*cy) * scale;
304 out->m[1][2] = (cr*sp*sy+-sr*cy) * scale;
306 out->m[2][0] = (-sp) * scale;
307 out->m[2][1] = (sr*cp) * scale;
308 out->m[2][2] = (cr*cp) * scale;
316 void Matrix4x4_ToVectors(const matrix4x4_t *in, float vx[3], float vy[3], float vz[3], float t[3])
332 void Matrix4x4_FromVectors(matrix4x4_t *out, const float vx[3], const float vy[3], const float vz[3], const float t[3])
334 out->m[0][0] = vx[0];
335 out->m[0][1] = vy[0];
336 out->m[0][2] = vz[0];
338 out->m[1][0] = vx[1];
339 out->m[1][1] = vy[1];
340 out->m[1][2] = vz[1];
342 out->m[2][0] = vx[2];
343 out->m[2][1] = vy[2];
344 out->m[2][2] = vz[2];
352 void Matrix4x4_Transform (const matrix4x4_t *in, const float v[3], float out[3])
354 out[0] = v[0] * in->m[0][0] + v[1] * in->m[0][1] + v[2] * in->m[0][2] + in->m[0][3];
355 out[1] = v[0] * in->m[1][0] + v[1] * in->m[1][1] + v[2] * in->m[1][2] + in->m[1][3];
356 out[2] = v[0] * in->m[2][0] + v[1] * in->m[2][1] + v[2] * in->m[2][2] + in->m[2][3];
359 void Matrix4x4_Transform4 (const matrix4x4_t *in, const float v[4], float out[4])
361 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];
362 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];
363 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];
364 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];
367 void Matrix4x4_Transform3x3 (const matrix4x4_t *in, const float v[3], float out[3])
369 out[0] = v[0] * in->m[0][0] + v[1] * in->m[0][1] + v[2] * in->m[0][2];
370 out[1] = v[0] * in->m[1][0] + v[1] * in->m[1][1] + v[2] * in->m[1][2];
371 out[2] = v[0] * in->m[2][0] + v[1] * in->m[2][1] + v[2] * in->m[2][2];
375 void Matrix4x4_SimpleUntransform (const matrix4x4_t *in, const float v[3], float out[3])
378 t[0] = v[0] - in->m[0][3];
379 t[1] = v[1] - in->m[1][3];
380 t[2] = v[2] - in->m[2][3];
381 out[0] = t[0] * in->m[0][0] + t[1] * in->m[1][0] + t[2] * in->m[2][0];
382 out[1] = t[0] * in->m[0][1] + t[1] * in->m[1][1] + t[2] * in->m[2][1];
383 out[2] = t[0] * in->m[0][2] + t[1] * in->m[1][2] + t[2] * in->m[2][2];
388 void Matrix4x4_ConcatTranslate (matrix4x4_t *out, float x, float y, float z)
390 matrix4x4_t base, temp;
392 Matrix4x4_CreateTranslate(&temp, x, y, z);
393 Matrix4x4_Concat(out, &base, &temp);
397 void Matrix4x4_ConcatRotate (matrix4x4_t *out, float angle, float x, float y, float z)
399 matrix4x4_t base, temp;
401 Matrix4x4_CreateRotate(&temp, angle, x, y, z);
402 Matrix4x4_Concat(out, &base, &temp);
406 void Matrix4x4_ConcatScale (matrix4x4_t *out, float x)
408 matrix4x4_t base, temp;
410 Matrix4x4_CreateScale(&temp, x);
411 Matrix4x4_Concat(out, &base, &temp);
415 void Matrix4x4_ConcatScale3 (matrix4x4_t *out, float x, float y, float z)
417 matrix4x4_t base, temp;
419 Matrix4x4_CreateScale3(&temp, x, y, z);
420 Matrix4x4_Concat(out, &base, &temp);
423 void Matrix4x4_Print (const matrix4x4_t *in)
425 Con_Printf("%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n"
426 , in->m[0][0], in->m[0][1], in->m[0][2], in->m[0][3]
427 , in->m[1][0], in->m[1][1], in->m[1][2], in->m[1][3]
428 , in->m[2][0], in->m[2][1], in->m[2][2], in->m[2][3]
429 , in->m[3][0], in->m[3][1], in->m[3][2], in->m[3][3]);
438 void Matrix3x4_Copy (matrix3x4_t *out, const matrix3x4_t *in)
443 void Matrix3x4_CopyRotateOnly (matrix3x4_t *out, const matrix3x4_t *in)
445 out->m[0][0] = in->m[0][0];
446 out->m[0][1] = in->m[0][1];
447 out->m[0][2] = in->m[0][2];
449 out->m[1][0] = in->m[1][0];
450 out->m[1][1] = in->m[1][1];
451 out->m[1][2] = in->m[1][2];
453 out->m[2][0] = in->m[2][0];
454 out->m[2][1] = in->m[2][1];
455 out->m[2][2] = in->m[2][2];
459 void Matrix3x4_CopyTranslateOnly (matrix3x4_t *out, const matrix3x4_t *in)
464 out->m[0][3] = in->m[0][3];
468 out->m[1][3] = in->m[0][3];
472 out->m[2][3] = in->m[0][3];
475 void Matrix3x4_FromMatrix4x4 (matrix3x4_t *out, const matrix4x4_t *in)
477 out->m[0][0] = in->m[0][0];
478 out->m[0][1] = in->m[0][1];
479 out->m[0][2] = in->m[0][2];
480 out->m[0][3] = in->m[0][3];
481 out->m[1][0] = in->m[1][0];
482 out->m[1][1] = in->m[1][1];
483 out->m[1][2] = in->m[1][2];
484 out->m[1][3] = in->m[1][3];
485 out->m[2][0] = in->m[2][0];
486 out->m[2][1] = in->m[2][1];
487 out->m[2][2] = in->m[2][2];
488 out->m[2][3] = in->m[2][3];
491 void Matrix3x4_Concat (matrix3x4_t *out, const matrix3x4_t *in1, const matrix3x4_t *in2)
493 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];
494 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];
495 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];
496 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];
497 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];
498 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];
499 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];
500 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];
501 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];
502 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];
503 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];
504 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];
507 void Matrix3x4_Transpose3x3 (matrix3x4_t *out, const matrix3x4_t *in1)
509 out->m[0][0] = in1->m[0][0];
510 out->m[0][1] = in1->m[1][0];
511 out->m[0][2] = in1->m[2][0];
513 out->m[1][0] = in1->m[0][1];
514 out->m[1][1] = in1->m[1][1];
515 out->m[1][2] = in1->m[2][1];
517 out->m[2][0] = in1->m[0][2];
518 out->m[2][1] = in1->m[1][2];
519 out->m[2][2] = in1->m[2][2];
523 void Matrix3x4_Invert_Simple (matrix3x4_t *out, const matrix3x4_t *in1)
525 // we only support uniform scaling, so assume the first row is enough
526 // (note the lack of sqrt here, because we're trying to undo the scaling,
527 // this means multiplying by the inverse scale twice - squaring it, which
528 // makes the sqrt a waste of time)
530 double scale = 1.0 / (in1->m[0][0] * in1->m[0][0] + in1->m[0][1] * in1->m[0][1] + in1->m[0][2] * in1->m[0][2]);
532 double scale = 3.0 / sqrt
533 (in1->m[0][0] * in1->m[0][0] + in1->m[0][1] * in1->m[0][1] + in1->m[0][2] * in1->m[0][2]
534 + in1->m[1][0] * in1->m[1][0] + in1->m[1][1] * in1->m[1][1] + in1->m[1][2] * in1->m[1][2]
535 + in1->m[2][0] * in1->m[2][0] + in1->m[2][1] * in1->m[2][1] + in1->m[2][2] * in1->m[2][2]);
539 // invert the rotation by transposing and multiplying by the squared
540 // recipricol of the input matrix scale as described above
541 out->m[0][0] = in1->m[0][0] * scale;
542 out->m[0][1] = in1->m[1][0] * scale;
543 out->m[0][2] = in1->m[2][0] * scale;
544 out->m[1][0] = in1->m[0][1] * scale;
545 out->m[1][1] = in1->m[1][1] * scale;
546 out->m[1][2] = in1->m[2][1] * scale;
547 out->m[2][0] = in1->m[0][2] * scale;
548 out->m[2][1] = in1->m[1][2] * scale;
549 out->m[2][2] = in1->m[2][2] * scale;
551 // invert the translate
552 out->m[0][3] = -(in1->m[0][3] * out->m[0][0] + in1->m[1][3] * out->m[0][1] + in1->m[2][3] * out->m[0][2]);
553 out->m[1][3] = -(in1->m[0][3] * out->m[1][0] + in1->m[1][3] * out->m[1][1] + in1->m[2][3] * out->m[1][2]);
554 out->m[2][3] = -(in1->m[0][3] * out->m[2][0] + in1->m[1][3] * out->m[2][1] + in1->m[2][3] * out->m[2][2]);
558 void Matrix3x4_CreateIdentity (matrix3x4_t *out)
574 void Matrix3x4_CreateTranslate (matrix3x4_t *out, float x, float y, float z)
590 void Matrix3x4_CreateRotate (matrix3x4_t *out, float angle, float x, float y, float z)
596 len = 1.0f / sqrt(len);
601 angle *= M_PI / 180.0;
605 out->m[0][0]=x * x + c * (1 - x * x);
606 out->m[0][1]=x * y * (1 - c) + z * s;
607 out->m[0][2]=z * x * (1 - c) - y * s;
609 out->m[1][0]=x * y * (1 - c) - z * s;
610 out->m[1][1]=y * y + c * (1 - y * y);
611 out->m[1][2]=y * z * (1 - c) + x * s;
613 out->m[2][0]=z * x * (1 - c) + y * s;
614 out->m[2][1]=y * z * (1 - c) - x * s;
615 out->m[2][2]=z * z + c * (1 - z * z);
619 void Matrix3x4_CreateScale (matrix3x4_t *out, float x)
635 void Matrix3x4_CreateScale3 (matrix3x4_t *out, float x, float y, float z)
651 void Matrix3x4_CreateFromQuakeEntity(matrix3x4_t *out, float x, float y, float z, float pitch, float yaw, float roll, float scale)
653 double angle, sr, sp, sy, cr, cp, cy;
655 angle = yaw * (M_PI*2 / 360);
658 angle = pitch * (M_PI*2 / 360);
661 angle = roll * (M_PI*2 / 360);
664 out->m[0][0] = (cp*cy) * scale;
665 out->m[0][1] = (sr*sp*cy+cr*-sy) * scale;
666 out->m[0][2] = (cr*sp*cy+-sr*-sy) * scale;
668 out->m[1][0] = (cp*sy) * scale;
669 out->m[1][1] = (sr*sp*sy+cr*cy) * scale;
670 out->m[1][2] = (cr*sp*sy+-sr*cy) * scale;
672 out->m[2][0] = (-sp) * scale;
673 out->m[2][1] = (sr*cp) * scale;
674 out->m[2][2] = (cr*cp) * scale;
678 void Matrix3x4_ToVectors(const matrix3x4_t *in, float vx[3], float vy[3], float vz[3], float t[3])
694 void Matrix3x4_FromVectors(matrix3x4_t *out, const float vx[3], const float vy[3], const float vz[3], const float t[3])
696 out->m[0][0] = vx[0];
697 out->m[0][1] = vy[0];
698 out->m[0][2] = vz[0];
700 out->m[1][0] = vx[1];
701 out->m[1][1] = vy[1];
702 out->m[1][2] = vz[1];
704 out->m[2][0] = vx[2];
705 out->m[2][1] = vy[2];
706 out->m[2][2] = vz[2];
710 void Matrix3x4_Transform (const matrix3x4_t *in, const float v[3], float out[3])
712 out[0] = v[0] * in->m[0][0] + v[1] * in->m[0][1] + v[2] * in->m[0][2] + in->m[0][3];
713 out[1] = v[0] * in->m[1][0] + v[1] * in->m[1][1] + v[2] * in->m[1][2] + in->m[1][3];
714 out[2] = v[0] * in->m[2][0] + v[1] * in->m[2][1] + v[2] * in->m[2][2] + in->m[2][3];
718 void Matrix3x4_SimpleUntransform (const matrix3x4_t *in, const float v[3], float out[3])
721 t[0] = v[0] - in->m[0][3];
722 t[1] = v[1] - in->m[1][3];
723 t[2] = v[2] - in->m[2][3];
724 out[0] = t[0] * in->m[0][0] + t[1] * in->m[1][0] + t[2] * in->m[2][0];
725 out[1] = t[0] * in->m[0][1] + t[1] * in->m[1][1] + t[2] * in->m[2][1];
726 out[2] = t[0] * in->m[0][2] + t[1] * in->m[1][2] + t[2] * in->m[2][2];
730 void Matrix3x4_Transform3x3 (const matrix3x4_t *in, const float v[3], float out[3])
732 out[0] = v[0] * in->m[0][0] + v[1] * in->m[0][1] + v[2] * in->m[0][2] + in->m[0][3];
733 out[1] = v[0] * in->m[1][0] + v[1] * in->m[1][1] + v[2] * in->m[1][2] + in->m[1][3];
734 out[2] = v[0] * in->m[2][0] + v[1] * in->m[2][1] + v[2] * in->m[2][2] + in->m[2][3];
739 void Matrix3x4_ConcatTranslate (matrix3x4_t *out, float x, float y, float z)
741 matrix3x4_t base, temp;
743 Matrix3x4_CreateTranslate(&temp, x, y, z);
744 Matrix3x4_Concat(out, &base, &temp);
748 void Matrix3x4_ConcatRotate (matrix3x4_t *out, float angle, float x, float y, float z)
750 matrix3x4_t base, temp;
752 Matrix3x4_CreateRotate(&temp, angle, x, y, z);
753 Matrix3x4_Concat(out, &base, &temp);
757 void Matrix3x4_ConcatScale (matrix3x4_t *out, float x)
759 matrix3x4_t base, temp;
761 Matrix3x4_CreateScale(&temp, x);
762 Matrix3x4_Concat(out, &base, &temp);
766 void Matrix3x4_ConcatScale3 (matrix3x4_t *out, float x, float y, float z)
768 matrix3x4_t base, temp;
770 Matrix3x4_CreateScale3(&temp, x, y, z);
771 Matrix3x4_Concat(out, &base, &temp);
774 void Matrix3x4_Print (const matrix3x4_t *in)
776 Con_Printf("%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n"
777 , in->m[0][0], in->m[0][1], in->m[0][2], in->m[0][3]
778 , in->m[1][0], in->m[1][1], in->m[1][2], in->m[1][3]
779 , in->m[2][0], in->m[2][1], in->m[2][2], in->m[2][3]);