5 const matrix4x4_t identitymatrix =
15 void Matrix4x4_Copy (matrix4x4_t *out, const matrix4x4_t *in)
20 void Matrix4x4_CopyRotateOnly (matrix4x4_t *out, const matrix4x4_t *in)
22 out->m[0][0] = in->m[0][0];
23 out->m[0][1] = in->m[0][1];
24 out->m[0][2] = in->m[0][2];
26 out->m[1][0] = in->m[1][0];
27 out->m[1][1] = in->m[1][1];
28 out->m[1][2] = in->m[1][2];
30 out->m[2][0] = in->m[2][0];
31 out->m[2][1] = in->m[2][1];
32 out->m[2][2] = in->m[2][2];
40 void Matrix4x4_CopyTranslateOnly (matrix4x4_t *out, const matrix4x4_t *in)
42 #ifdef MATRIX4x4_OPENGLORIENTATION
46 out->m[3][0] = in->m[0][3];
50 out->m[3][1] = in->m[1][3];
54 out->m[3][2] = in->m[2][3];
63 out->m[0][3] = in->m[0][3];
67 out->m[1][3] = in->m[1][3];
71 out->m[2][3] = in->m[2][3];
79 void Matrix4x4_Concat (matrix4x4_t *out, const matrix4x4_t *in1, const matrix4x4_t *in2)
81 #ifdef MATRIX4x4_OPENGLORIENTATION
82 out->m[0][0] = in1->m[0][0] * in2->m[0][0] + in1->m[1][0] * in2->m[0][1] + in1->m[2][0] * in2->m[0][2] + in1->m[3][0] * in2->m[0][3];
83 out->m[1][0] = in1->m[0][0] * in2->m[1][0] + in1->m[1][0] * in2->m[1][1] + in1->m[2][0] * in2->m[1][2] + in1->m[3][0] * in2->m[1][3];
84 out->m[2][0] = in1->m[0][0] * in2->m[2][0] + in1->m[1][0] * in2->m[2][1] + in1->m[2][0] * in2->m[2][2] + in1->m[3][0] * in2->m[2][3];
85 out->m[3][0] = in1->m[0][0] * in2->m[3][0] + in1->m[1][0] * in2->m[3][1] + in1->m[2][0] * in2->m[3][2] + in1->m[3][0] * in2->m[3][3];
86 out->m[0][1] = in1->m[0][1] * in2->m[0][0] + in1->m[1][1] * in2->m[0][1] + in1->m[2][1] * in2->m[0][2] + in1->m[3][1] * in2->m[0][3];
87 out->m[1][1] = in1->m[0][1] * in2->m[1][0] + in1->m[1][1] * in2->m[1][1] + in1->m[2][1] * in2->m[1][2] + in1->m[3][1] * in2->m[1][3];
88 out->m[2][1] = in1->m[0][1] * in2->m[2][0] + in1->m[1][1] * in2->m[2][1] + in1->m[2][1] * in2->m[2][2] + in1->m[3][1] * in2->m[2][3];
89 out->m[3][1] = in1->m[0][1] * in2->m[3][0] + in1->m[1][1] * in2->m[3][1] + in1->m[2][1] * in2->m[3][2] + in1->m[3][1] * in2->m[3][3];
90 out->m[0][2] = in1->m[0][2] * in2->m[0][0] + in1->m[1][2] * in2->m[0][1] + in1->m[2][2] * in2->m[0][2] + in1->m[3][2] * in2->m[0][3];
91 out->m[1][2] = in1->m[0][2] * in2->m[1][0] + in1->m[1][2] * in2->m[1][1] + in1->m[2][2] * in2->m[1][2] + in1->m[3][2] * in2->m[1][3];
92 out->m[2][2] = in1->m[0][2] * in2->m[2][0] + in1->m[1][2] * in2->m[2][1] + in1->m[2][2] * in2->m[2][2] + in1->m[3][2] * in2->m[2][3];
93 out->m[3][2] = in1->m[0][2] * in2->m[3][0] + in1->m[1][2] * in2->m[3][1] + in1->m[2][2] * in2->m[3][2] + in1->m[3][2] * in2->m[3][3];
94 out->m[0][3] = in1->m[0][3] * in2->m[0][0] + in1->m[1][3] * in2->m[0][1] + in1->m[2][3] * in2->m[0][2] + in1->m[3][3] * in2->m[0][3];
95 out->m[1][3] = in1->m[0][3] * in2->m[1][0] + in1->m[1][3] * in2->m[1][1] + in1->m[2][3] * in2->m[1][2] + in1->m[3][3] * in2->m[1][3];
96 out->m[2][3] = in1->m[0][3] * in2->m[2][0] + in1->m[1][3] * in2->m[2][1] + in1->m[2][3] * in2->m[2][2] + in1->m[3][3] * in2->m[2][3];
97 out->m[3][3] = in1->m[0][3] * in2->m[3][0] + in1->m[1][3] * in2->m[3][1] + in1->m[2][3] * in2->m[3][2] + in1->m[3][3] * in2->m[3][3];
99 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];
100 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];
101 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];
102 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];
103 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];
104 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];
105 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];
106 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];
107 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];
108 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];
109 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];
110 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];
111 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];
112 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];
113 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];
114 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];
118 void Matrix4x4_Transpose (matrix4x4_t *out, const matrix4x4_t *in1)
120 out->m[0][0] = in1->m[0][0];
121 out->m[0][1] = in1->m[1][0];
122 out->m[0][2] = in1->m[2][0];
123 out->m[0][3] = in1->m[3][0];
124 out->m[1][0] = in1->m[0][1];
125 out->m[1][1] = in1->m[1][1];
126 out->m[1][2] = in1->m[2][1];
127 out->m[1][3] = in1->m[3][1];
128 out->m[2][0] = in1->m[0][2];
129 out->m[2][1] = in1->m[1][2];
130 out->m[2][2] = in1->m[2][2];
131 out->m[2][3] = in1->m[3][2];
132 out->m[3][0] = in1->m[0][3];
133 out->m[3][1] = in1->m[1][3];
134 out->m[3][2] = in1->m[2][3];
135 out->m[3][3] = in1->m[3][3];
138 int Matrix4x4_Invert_Full (matrix4x4_t *out, const matrix4x4_t *in1)
151 #ifdef MATRIX4x4_OPENGLORIENTATION
152 r[0][0] = in1->m[0][0]; r[0][1] = in1->m[1][0]; r[0][2] = in1->m[2][0]; r[0][3] = in1->m[3][0];
153 r[0][4] = 1.0; r[0][5] = r[0][6] = r[0][7] = 0.0;
155 r[1][0] = in1->m[0][1]; r[1][1] = in1->m[1][1]; r[1][2] = in1->m[2][1]; r[1][3] = in1->m[3][1];
156 r[1][5] = 1.0; r[1][4] = r[1][6] = r[1][7] = 0.0;
158 r[2][0] = in1->m[0][2]; r[2][1] = in1->m[1][2]; r[2][2] = in1->m[2][2]; r[2][3] = in1->m[3][2];
159 r[2][6] = 1.0; r[2][4] = r[2][5] = r[2][7] = 0.0;
161 r[3][0] = in1->m[0][3]; r[3][1] = in1->m[1][3]; r[3][2] = in1->m[2][3]; r[3][3] = in1->m[3][3];
162 r[3][7] = 1.0; r[3][4] = r[3][5] = r[3][6] = 0.0;
164 r[0][0] = in1->m[0][0]; r[0][1] = in1->m[0][1]; r[0][2] = in1->m[0][2]; r[0][3] = in1->m[0][3];
165 r[0][4] = 1.0; r[0][5] = r[0][6] = r[0][7] = 0.0;
167 r[1][0] = in1->m[1][0]; r[1][1] = in1->m[1][1]; r[1][2] = in1->m[1][2]; r[1][3] = in1->m[1][3];
168 r[1][5] = 1.0; r[1][4] = r[1][6] = r[1][7] = 0.0;
170 r[2][0] = in1->m[2][0]; r[2][1] = in1->m[2][1]; r[2][2] = in1->m[2][2]; r[2][3] = in1->m[2][3];
171 r[2][6] = 1.0; r[2][4] = r[2][5] = r[2][7] = 0.0;
173 r[3][0] = in1->m[3][0]; r[3][1] = in1->m[3][1]; r[3][2] = in1->m[3][2]; r[3][3] = in1->m[3][3];
174 r[3][7] = 1.0; r[3][4] = r[3][5] = r[3][6] = 0.0;
177 if (fabs (r[3][0]) > fabs (r[2][0])) { temp = r[3]; r[3] = r[2]; r[2] = temp; }
178 if (fabs (r[2][0]) > fabs (r[1][0])) { temp = r[2]; r[2] = r[1]; r[1] = temp; }
179 if (fabs (r[1][0]) > fabs (r[0][0])) { temp = r[1]; r[1] = r[0]; r[0] = temp; }
183 m[1] = r[1][0] / r[0][0];
184 m[2] = r[2][0] / r[0][0];
185 m[3] = r[3][0] / r[0][0];
187 s = r[0][1]; r[1][1] -= m[1] * s; r[2][1] -= m[2] * s; r[3][1] -= m[3] * s;
188 s = r[0][2]; r[1][2] -= m[1] * s; r[2][2] -= m[2] * s; r[3][2] -= m[3] * s;
189 s = r[0][3]; r[1][3] -= m[1] * s; r[2][3] -= m[2] * s; r[3][3] -= m[3] * s;
191 s = r[0][4]; if (s) { r[1][4] -= m[1] * s; r[2][4] -= m[2] * s; r[3][4] -= m[3] * s; }
192 s = r[0][5]; if (s) { r[1][5] -= m[1] * s; r[2][5] -= m[2] * s; r[3][5] -= m[3] * s; }
193 s = r[0][6]; if (s) { r[1][6] -= m[1] * s; r[2][6] -= m[2] * s; r[3][6] -= m[3] * s; }
194 s = r[0][7]; if (s) { r[1][7] -= m[1] * s; r[2][7] -= m[2] * s; r[3][7] -= m[3] * s; }
196 if (fabs (r[3][1]) > fabs (r[2][1])) { temp = r[3]; r[3] = r[2]; r[2] = temp; }
197 if (fabs (r[2][1]) > fabs (r[1][1])) { temp = r[2]; r[2] = r[1]; r[1] = temp; }
201 m[2] = r[2][1] / r[1][1];
202 m[3] = r[3][1] / r[1][1];
203 r[2][2] -= m[2] * r[1][2];
204 r[3][2] -= m[3] * r[1][2];
205 r[2][3] -= m[2] * r[1][3];
206 r[3][3] -= m[3] * r[1][3];
208 s = r[1][4]; if (s) { r[2][4] -= m[2] * s; r[3][4] -= m[3] * s; }
209 s = r[1][5]; if (s) { r[2][5] -= m[2] * s; r[3][5] -= m[3] * s; }
210 s = r[1][6]; if (s) { r[2][6] -= m[2] * s; r[3][6] -= m[3] * s; }
211 s = r[1][7]; if (s) { r[2][7] -= m[2] * s; r[3][7] -= m[3] * s; }
213 if (fabs (r[3][2]) > fabs (r[2][2])) { temp = r[3]; r[3] = r[2]; r[2] = temp; }
217 m[3] = r[3][2] / r[2][2];
218 r[3][3] -= m[3] * r[2][3];
219 r[3][4] -= m[3] * r[2][4];
220 r[3][5] -= m[3] * r[2][5];
221 r[3][6] -= m[3] * r[2][6];
222 r[3][7] -= m[3] * r[2][7];
234 r[2][4] = s * (r[2][4] - r[3][4] * m[2]);
235 r[2][5] = s * (r[2][5] - r[3][5] * m[2]);
236 r[2][6] = s * (r[2][6] - r[3][6] * m[2]);
237 r[2][7] = s * (r[2][7] - r[3][7] * m[2]);
240 r[1][4] -= r[3][4] * m[1], r[1][5] -= r[3][5] * m[1];
241 r[1][6] -= r[3][6] * m[1], r[1][7] -= r[3][7] * m[1];
244 r[0][4] -= r[3][4] * m[0], r[0][5] -= r[3][5] * m[0];
245 r[0][6] -= r[3][6] * m[0], r[0][7] -= r[3][7] * m[0];
249 r[1][4] = s * (r[1][4] - r[2][4] * m[1]), r[1][5] = s * (r[1][5] - r[2][5] * m[1]);
250 r[1][6] = s * (r[1][6] - r[2][6] * m[1]), r[1][7] = s * (r[1][7] - r[2][7] * m[1]);
253 r[0][4] -= r[2][4] * m[0], r[0][5] -= r[2][5] * m[0];
254 r[0][6] -= r[2][6] * m[0], r[0][7] -= r[2][7] * m[0];
258 r[0][4] = s * (r[0][4] - r[1][4] * m[0]), r[0][5] = s * (r[0][5] - r[1][5] * m[0]);
259 r[0][6] = s * (r[0][6] - r[1][6] * m[0]), r[0][7] = s * (r[0][7] - r[1][7] * m[0]);
261 #ifdef MATRIX4x4_OPENGLORIENTATION
262 out->m[0][0] = r[0][4];
263 out->m[0][1] = r[1][4];
264 out->m[0][2] = r[2][4];
265 out->m[0][3] = r[3][4];
266 out->m[1][0] = r[0][5];
267 out->m[1][1] = r[1][5];
268 out->m[1][2] = r[2][5];
269 out->m[1][3] = r[3][5];
270 out->m[2][0] = r[0][6];
271 out->m[2][1] = r[1][6];
272 out->m[2][2] = r[2][6];
273 out->m[2][3] = r[3][6];
274 out->m[3][0] = r[0][7];
275 out->m[3][1] = r[1][7];
276 out->m[3][2] = r[2][7];
277 out->m[3][3] = r[3][7];
279 out->m[0][0] = r[0][4];
280 out->m[0][1] = r[0][5];
281 out->m[0][2] = r[0][6];
282 out->m[0][3] = r[0][7];
283 out->m[1][0] = r[1][4];
284 out->m[1][1] = r[1][5];
285 out->m[1][2] = r[1][6];
286 out->m[1][3] = r[1][7];
287 out->m[2][0] = r[2][4];
288 out->m[2][1] = r[2][5];
289 out->m[2][2] = r[2][6];
290 out->m[2][3] = r[2][7];
291 out->m[3][0] = r[3][4];
292 out->m[3][1] = r[3][5];
293 out->m[3][2] = r[3][6];
294 out->m[3][3] = r[3][7];
306 void Matrix4x4_Invert_Simple (matrix4x4_t *out, const matrix4x4_t *in1)
308 // we only support uniform scaling, so assume the first row is enough
309 // (note the lack of sqrt here, because we're trying to undo the scaling,
310 // this means multiplying by the inverse scale twice - squaring it, which
311 // makes the sqrt a waste of time)
313 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]);
315 double scale = 3.0 / sqrt
316 (in1->m[0][0] * in1->m[0][0] + in1->m[0][1] * in1->m[0][1] + in1->m[0][2] * in1->m[0][2]
317 + in1->m[1][0] * in1->m[1][0] + in1->m[1][1] * in1->m[1][1] + in1->m[1][2] * in1->m[1][2]
318 + in1->m[2][0] * in1->m[2][0] + in1->m[2][1] * in1->m[2][1] + in1->m[2][2] * in1->m[2][2]);
322 // invert the rotation by transposing and multiplying by the squared
323 // recipricol of the input matrix scale as described above
324 out->m[0][0] = in1->m[0][0] * scale;
325 out->m[0][1] = in1->m[1][0] * scale;
326 out->m[0][2] = in1->m[2][0] * scale;
327 out->m[1][0] = in1->m[0][1] * scale;
328 out->m[1][1] = in1->m[1][1] * scale;
329 out->m[1][2] = in1->m[2][1] * scale;
330 out->m[2][0] = in1->m[0][2] * scale;
331 out->m[2][1] = in1->m[1][2] * scale;
332 out->m[2][2] = in1->m[2][2] * scale;
334 #ifdef MATRIX4x4_OPENGLORIENTATION
335 // invert the translate
336 out->m[3][0] = -(in1->m[3][0] * out->m[0][0] + in1->m[3][1] * out->m[1][0] + in1->m[3][2] * out->m[2][0]);
337 out->m[3][1] = -(in1->m[3][0] * out->m[0][1] + in1->m[3][1] * out->m[1][1] + in1->m[3][2] * out->m[2][1]);
338 out->m[3][2] = -(in1->m[3][0] * out->m[0][2] + in1->m[3][1] * out->m[1][2] + in1->m[3][2] * out->m[2][2]);
340 // don't know if there's anything worth doing here
346 // invert the translate
347 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]);
348 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]);
349 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]);
351 // don't know if there's anything worth doing here
359 void Matrix4x4_Normalize (matrix4x4_t *out, matrix4x4_t *in1)
361 // scale rotation matrix vectors to a length of 1
362 // note: this is only designed to undo uniform scaling
363 double scale = 1.0 / sqrt(in1->m[0][0] * in1->m[0][0] + in1->m[0][1] * in1->m[0][1] + in1->m[0][2] * in1->m[0][2]);
365 Matrix4x4_Scale(out, scale, 1);
368 void Matrix4x4_CreateIdentity (matrix4x4_t *out)
388 void Matrix4x4_CreateTranslate (matrix4x4_t *out, double x, double y, double z)
390 #ifdef MATRIX4x4_OPENGLORIENTATION
427 void Matrix4x4_CreateRotate (matrix4x4_t *out, double angle, double x, double y, double z)
433 len = 1.0f / sqrt(len);
438 angle *= (-M_PI / 180.0);
442 #ifdef MATRIX4x4_OPENGLORIENTATION
443 out->m[0][0]=x * x + c * (1 - x * x);
444 out->m[1][0]=x * y * (1 - c) + z * s;
445 out->m[2][0]=z * x * (1 - c) - y * s;
447 out->m[0][1]=x * y * (1 - c) - z * s;
448 out->m[1][1]=y * y + c * (1 - y * y);
449 out->m[2][1]=y * z * (1 - c) + x * s;
451 out->m[0][2]=z * x * (1 - c) + y * s;
452 out->m[1][2]=y * z * (1 - c) - x * s;
453 out->m[2][2]=z * z + c * (1 - z * z);
460 out->m[0][0]=x * x + c * (1 - x * x);
461 out->m[0][1]=x * y * (1 - c) + z * s;
462 out->m[0][2]=z * x * (1 - c) - y * s;
464 out->m[1][0]=x * y * (1 - c) - z * s;
465 out->m[1][1]=y * y + c * (1 - y * y);
466 out->m[1][2]=y * z * (1 - c) + x * s;
468 out->m[2][0]=z * x * (1 - c) + y * s;
469 out->m[2][1]=y * z * (1 - c) - x * s;
470 out->m[2][2]=z * z + c * (1 - z * z);
479 void Matrix4x4_CreateScale (matrix4x4_t *out, double x)
499 void Matrix4x4_CreateScale3 (matrix4x4_t *out, double x, double y, double z)
519 void Matrix4x4_CreateFromQuakeEntity(matrix4x4_t *out, double x, double y, double z, double pitch, double yaw, double roll, double scale)
521 double angle, sr, sp, sy, cr, cp, cy;
525 angle = yaw * (M_PI*2 / 360);
528 angle = pitch * (M_PI*2 / 360);
531 angle = roll * (M_PI*2 / 360);
534 #ifdef MATRIX4x4_OPENGLORIENTATION
535 out->m[0][0] = (cp*cy) * scale;
536 out->m[1][0] = (sr*sp*cy+cr*-sy) * scale;
537 out->m[2][0] = (cr*sp*cy+-sr*-sy) * scale;
539 out->m[0][1] = (cp*sy) * scale;
540 out->m[1][1] = (sr*sp*sy+cr*cy) * scale;
541 out->m[2][1] = (cr*sp*sy+-sr*cy) * scale;
543 out->m[0][2] = (-sp) * scale;
544 out->m[1][2] = (sr*cp) * scale;
545 out->m[2][2] = (cr*cp) * scale;
552 out->m[0][0] = (cp*cy) * scale;
553 out->m[0][1] = (sr*sp*cy+cr*-sy) * scale;
554 out->m[0][2] = (cr*sp*cy+-sr*-sy) * scale;
556 out->m[1][0] = (cp*sy) * scale;
557 out->m[1][1] = (sr*sp*sy+cr*cy) * scale;
558 out->m[1][2] = (cr*sp*sy+-sr*cy) * scale;
560 out->m[2][0] = (-sp) * scale;
561 out->m[2][1] = (sr*cp) * scale;
562 out->m[2][2] = (cr*cp) * scale;
572 angle = yaw * (M_PI*2 / 360);
575 angle = pitch * (M_PI*2 / 360);
578 #ifdef MATRIX4x4_OPENGLORIENTATION
579 out->m[0][0] = (cp*cy) * scale;
580 out->m[1][0] = (-sy) * scale;
581 out->m[2][0] = (sp*cy) * scale;
583 out->m[0][1] = (cp*sy) * scale;
584 out->m[1][1] = (cy) * scale;
585 out->m[2][1] = (sp*sy) * scale;
587 out->m[0][2] = (-sp) * scale;
589 out->m[2][2] = (cp) * scale;
596 out->m[0][0] = (cp*cy) * scale;
597 out->m[0][1] = (-sy) * scale;
598 out->m[0][2] = (sp*cy) * scale;
600 out->m[1][0] = (cp*sy) * scale;
601 out->m[1][1] = (cy) * scale;
602 out->m[1][2] = (sp*sy) * scale;
604 out->m[2][0] = (-sp) * scale;
606 out->m[2][2] = (cp) * scale;
616 angle = yaw * (M_PI*2 / 360);
619 #ifdef MATRIX4x4_OPENGLORIENTATION
620 out->m[0][0] = (cy) * scale;
621 out->m[1][0] = (-sy) * scale;
624 out->m[0][1] = (sy) * scale;
625 out->m[1][1] = (cy) * scale;
630 out->m[2][2] = scale;
637 out->m[0][0] = (cy) * scale;
638 out->m[0][1] = (-sy) * scale;
641 out->m[1][0] = (sy) * scale;
642 out->m[1][1] = (cy) * scale;
647 out->m[2][2] = scale;
657 #ifdef MATRIX4x4_OPENGLORIENTATION
658 out->m[0][0] = scale;
663 out->m[1][1] = scale;
668 out->m[2][2] = scale;
675 out->m[0][0] = scale;
680 out->m[1][1] = scale;
685 out->m[2][2] = scale;
695 void Matrix4x4_ToVectors(const matrix4x4_t *in, float vx[3], float vy[3], float vz[3], float t[3])
697 #ifdef MATRIX4x4_OPENGLORIENTATION
726 void Matrix4x4_FromVectors(matrix4x4_t *out, const float vx[3], const float vy[3], const float vz[3], const float t[3])
728 #ifdef MATRIX4x4_OPENGLORIENTATION
729 out->m[0][0] = vx[0];
730 out->m[1][0] = vy[0];
731 out->m[2][0] = vz[0];
733 out->m[0][1] = vx[1];
734 out->m[1][1] = vy[1];
735 out->m[2][1] = vz[1];
737 out->m[0][2] = vx[2];
738 out->m[1][2] = vy[2];
739 out->m[2][2] = vz[2];
746 out->m[0][0] = vx[0];
747 out->m[0][1] = vy[0];
748 out->m[0][2] = vz[0];
750 out->m[1][0] = vx[1];
751 out->m[1][1] = vy[1];
752 out->m[1][2] = vz[1];
754 out->m[2][0] = vx[2];
755 out->m[2][1] = vy[2];
756 out->m[2][2] = vz[2];
765 void Matrix4x4_ToArrayDoubleGL(const matrix4x4_t *in, double out[16])
767 #ifdef MATRIX4x4_OPENGLORIENTATION
768 out[ 0] = in->m[0][0];
769 out[ 1] = in->m[0][1];
770 out[ 2] = in->m[0][2];
771 out[ 3] = in->m[0][3];
772 out[ 4] = in->m[1][0];
773 out[ 5] = in->m[1][1];
774 out[ 6] = in->m[1][2];
775 out[ 7] = in->m[1][3];
776 out[ 8] = in->m[2][0];
777 out[ 9] = in->m[2][1];
778 out[10] = in->m[2][2];
779 out[11] = in->m[2][3];
780 out[12] = in->m[3][0];
781 out[13] = in->m[3][1];
782 out[14] = in->m[3][2];
783 out[15] = in->m[3][3];
785 out[ 0] = in->m[0][0];
786 out[ 1] = in->m[1][0];
787 out[ 2] = in->m[2][0];
788 out[ 3] = in->m[3][0];
789 out[ 4] = in->m[0][1];
790 out[ 5] = in->m[1][1];
791 out[ 6] = in->m[2][1];
792 out[ 7] = in->m[3][1];
793 out[ 8] = in->m[0][2];
794 out[ 9] = in->m[1][2];
795 out[10] = in->m[2][2];
796 out[11] = in->m[3][2];
797 out[12] = in->m[0][3];
798 out[13] = in->m[1][3];
799 out[14] = in->m[2][3];
800 out[15] = in->m[3][3];
804 void Matrix4x4_FromArrayDoubleGL (matrix4x4_t *out, const double in[16])
806 #ifdef MATRIX4x4_OPENGLORIENTATION
807 out->m[0][0] = in[0];
808 out->m[0][1] = in[1];
809 out->m[0][2] = in[2];
810 out->m[0][3] = in[3];
811 out->m[1][0] = in[4];
812 out->m[1][1] = in[5];
813 out->m[1][2] = in[6];
814 out->m[1][3] = in[7];
815 out->m[2][0] = in[8];
816 out->m[2][1] = in[9];
817 out->m[2][2] = in[10];
818 out->m[2][3] = in[11];
819 out->m[3][0] = in[12];
820 out->m[3][1] = in[13];
821 out->m[3][2] = in[14];
822 out->m[3][3] = in[15];
824 out->m[0][0] = in[0];
825 out->m[1][0] = in[1];
826 out->m[2][0] = in[2];
827 out->m[3][0] = in[3];
828 out->m[0][1] = in[4];
829 out->m[1][1] = in[5];
830 out->m[2][1] = in[6];
831 out->m[3][1] = in[7];
832 out->m[0][2] = in[8];
833 out->m[1][2] = in[9];
834 out->m[2][2] = in[10];
835 out->m[3][2] = in[11];
836 out->m[0][3] = in[12];
837 out->m[1][3] = in[13];
838 out->m[2][3] = in[14];
839 out->m[3][3] = in[15];
843 void Matrix4x4_ToArrayDoubleD3D(const matrix4x4_t *in, double out[16])
845 #ifdef MATRIX4x4_OPENGLORIENTATION
846 out[ 0] = in->m[0][0];
847 out[ 1] = in->m[1][0];
848 out[ 2] = in->m[2][0];
849 out[ 3] = in->m[3][0];
850 out[ 4] = in->m[0][1];
851 out[ 5] = in->m[1][1];
852 out[ 6] = in->m[2][1];
853 out[ 7] = in->m[3][1];
854 out[ 8] = in->m[0][2];
855 out[ 9] = in->m[1][2];
856 out[10] = in->m[2][2];
857 out[11] = in->m[3][2];
858 out[12] = in->m[0][3];
859 out[13] = in->m[1][3];
860 out[14] = in->m[2][3];
861 out[15] = in->m[3][3];
863 out[ 0] = in->m[0][0];
864 out[ 1] = in->m[0][1];
865 out[ 2] = in->m[0][2];
866 out[ 3] = in->m[0][3];
867 out[ 4] = in->m[1][0];
868 out[ 5] = in->m[1][1];
869 out[ 6] = in->m[1][2];
870 out[ 7] = in->m[1][3];
871 out[ 8] = in->m[2][0];
872 out[ 9] = in->m[2][1];
873 out[10] = in->m[2][2];
874 out[11] = in->m[2][3];
875 out[12] = in->m[3][0];
876 out[13] = in->m[3][1];
877 out[14] = in->m[3][2];
878 out[15] = in->m[3][3];
882 void Matrix4x4_FromArrayDoubleD3D (matrix4x4_t *out, const double in[16])
884 #ifdef MATRIX4x4_OPENGLORIENTATION
885 out->m[0][0] = in[0];
886 out->m[1][0] = in[1];
887 out->m[2][0] = in[2];
888 out->m[3][0] = in[3];
889 out->m[0][1] = in[4];
890 out->m[1][1] = in[5];
891 out->m[2][1] = in[6];
892 out->m[3][1] = in[7];
893 out->m[0][2] = in[8];
894 out->m[1][2] = in[9];
895 out->m[2][2] = in[10];
896 out->m[3][2] = in[11];
897 out->m[0][3] = in[12];
898 out->m[1][3] = in[13];
899 out->m[2][3] = in[14];
900 out->m[3][3] = in[15];
902 out->m[0][0] = in[0];
903 out->m[0][1] = in[1];
904 out->m[0][2] = in[2];
905 out->m[0][3] = in[3];
906 out->m[1][0] = in[4];
907 out->m[1][1] = in[5];
908 out->m[1][2] = in[6];
909 out->m[1][3] = in[7];
910 out->m[2][0] = in[8];
911 out->m[2][1] = in[9];
912 out->m[2][2] = in[10];
913 out->m[2][3] = in[11];
914 out->m[3][0] = in[12];
915 out->m[3][1] = in[13];
916 out->m[3][2] = in[14];
917 out->m[3][3] = in[15];
921 void Matrix4x4_ToArray12FloatGL(const matrix4x4_t *in, float out[12])
923 #ifdef MATRIX4x4_OPENGLORIENTATION
924 out[ 0] = in->m[0][0];
925 out[ 1] = in->m[0][1];
926 out[ 2] = in->m[0][2];
927 out[ 3] = in->m[1][0];
928 out[ 4] = in->m[1][1];
929 out[ 5] = in->m[1][2];
930 out[ 6] = in->m[2][0];
931 out[ 7] = in->m[2][1];
932 out[ 8] = in->m[2][2];
933 out[ 9] = in->m[3][0];
934 out[10] = in->m[3][1];
935 out[11] = in->m[3][2];
937 out[ 0] = in->m[0][0];
938 out[ 1] = in->m[1][0];
939 out[ 2] = in->m[2][0];
940 out[ 3] = in->m[0][1];
941 out[ 4] = in->m[1][1];
942 out[ 5] = in->m[2][1];
943 out[ 6] = in->m[0][2];
944 out[ 7] = in->m[1][2];
945 out[ 8] = in->m[2][2];
946 out[ 9] = in->m[0][3];
947 out[10] = in->m[1][3];
948 out[11] = in->m[2][3];
952 void Matrix4x4_FromArray12FloatGL(matrix4x4_t *out, const float in[12])
954 #ifdef MATRIX4x4_OPENGLORIENTATION
955 out->m[0][0] = in[0];
956 out->m[0][1] = in[1];
957 out->m[0][2] = in[2];
959 out->m[1][0] = in[3];
960 out->m[1][1] = in[4];
961 out->m[1][2] = in[5];
963 out->m[2][0] = in[6];
964 out->m[2][1] = in[7];
965 out->m[2][2] = in[8];
967 out->m[3][0] = in[9];
968 out->m[3][1] = in[10];
969 out->m[3][2] = in[11];
972 out->m[0][0] = in[0];
973 out->m[1][0] = in[1];
974 out->m[2][0] = in[2];
976 out->m[0][1] = in[3];
977 out->m[1][1] = in[4];
978 out->m[2][1] = in[5];
980 out->m[0][2] = in[6];
981 out->m[1][2] = in[7];
982 out->m[2][2] = in[8];
984 out->m[0][3] = in[9];
985 out->m[1][3] = in[10];
986 out->m[2][3] = in[11];
991 void Matrix4x4_ToArray12FloatD3D(const matrix4x4_t *in, float out[12])
993 #ifdef MATRIX4x4_OPENGLORIENTATION
994 out[ 0] = in->m[0][0];
995 out[ 1] = in->m[1][0];
996 out[ 2] = in->m[2][0];
997 out[ 3] = in->m[3][0];
998 out[ 4] = in->m[0][1];
999 out[ 5] = in->m[1][1];
1000 out[ 6] = in->m[2][1];
1001 out[ 7] = in->m[3][1];
1002 out[ 8] = in->m[0][2];
1003 out[ 9] = in->m[1][2];
1004 out[10] = in->m[2][2];
1005 out[11] = in->m[3][2];
1007 out[ 0] = in->m[0][0];
1008 out[ 1] = in->m[0][1];
1009 out[ 2] = in->m[0][2];
1010 out[ 3] = in->m[0][3];
1011 out[ 4] = in->m[1][0];
1012 out[ 5] = in->m[1][1];
1013 out[ 6] = in->m[1][2];
1014 out[ 7] = in->m[1][3];
1015 out[ 8] = in->m[2][0];
1016 out[ 9] = in->m[2][1];
1017 out[10] = in->m[2][2];
1018 out[11] = in->m[2][3];
1022 void Matrix4x4_FromArray12FloatD3D(matrix4x4_t *out, const float in[12])
1024 #ifdef MATRIX4x4_OPENGLORIENTATION
1025 out->m[0][0] = in[0];
1026 out->m[1][0] = in[1];
1027 out->m[2][0] = in[2];
1028 out->m[3][0] = in[3];
1029 out->m[0][1] = in[4];
1030 out->m[1][1] = in[5];
1031 out->m[2][1] = in[6];
1032 out->m[3][1] = in[7];
1033 out->m[0][2] = in[8];
1034 out->m[1][2] = in[9];
1035 out->m[2][2] = in[10];
1036 out->m[3][2] = in[11];
1042 out->m[0][0] = in[0];
1043 out->m[0][1] = in[1];
1044 out->m[0][2] = in[2];
1045 out->m[0][3] = in[3];
1046 out->m[1][0] = in[4];
1047 out->m[1][1] = in[5];
1048 out->m[1][2] = in[6];
1049 out->m[1][3] = in[7];
1050 out->m[2][0] = in[8];
1051 out->m[2][1] = in[9];
1052 out->m[2][2] = in[10];
1053 out->m[2][3] = in[11];
1061 void Matrix4x4_FromOriginQuat(matrix4x4_t *m, double ox, double oy, double oz, double x, double y, double z, double w)
1063 #ifdef MATRIX4x4_OPENGLORIENTATION
1064 m->m[0][0]=1-2*(y*y+z*z);m->m[1][0]= 2*(x*y-z*w);m->m[2][0]= 2*(x*z+y*w);m->m[3][0]=ox;
1065 m->m[0][1]= 2*(x*y+z*w);m->m[1][1]=1-2*(x*x+z*z);m->m[2][1]= 2*(y*z-x*w);m->m[3][1]=oy;
1066 m->m[0][2]= 2*(x*z-y*w);m->m[1][2]= 2*(y*z+x*w);m->m[2][2]=1-2*(x*x+y*y);m->m[3][2]=oz;
1067 m->m[0][3]= 0 ;m->m[1][3]= 0 ;m->m[2][3]= 0 ;m->m[3][3]=1;
1069 m->m[0][0]=1-2*(y*y+z*z);m->m[0][1]= 2*(x*y-z*w);m->m[0][2]= 2*(x*z+y*w);m->m[0][3]=ox;
1070 m->m[1][0]= 2*(x*y+z*w);m->m[1][1]=1-2*(x*x+z*z);m->m[1][2]= 2*(y*z-x*w);m->m[1][3]=oy;
1071 m->m[2][0]= 2*(x*z-y*w);m->m[2][1]= 2*(y*z+x*w);m->m[2][2]=1-2*(x*x+y*y);m->m[2][3]=oz;
1072 m->m[3][0]= 0 ;m->m[3][1]= 0 ;m->m[3][2]= 0 ;m->m[3][3]=1;
1076 // LordHavoc: I got this code from:
1077 //http://www.doom3world.org/phpbb2/viewtopic.php?t=2884
1078 void Matrix4x4_FromDoom3Joint(matrix4x4_t *m, double ox, double oy, double oz, double x, double y, double z)
1080 double w = 1.0 - (x*x+y*y+z*z);
1081 w = w > 0.0 ? -sqrt(w) : 0.0;
1082 #ifdef MATRIX4x4_OPENGLORIENTATION
1083 m->m[0][0]=1-2*(y*y+z*z);m->m[1][0]= 2*(x*y-z*w);m->m[2][0]= 2*(x*z+y*w);m->m[3][0]=ox;
1084 m->m[0][1]= 2*(x*y+z*w);m->m[1][1]=1-2*(x*x+z*z);m->m[2][1]= 2*(y*z-x*w);m->m[3][1]=oy;
1085 m->m[0][2]= 2*(x*z-y*w);m->m[1][2]= 2*(y*z+x*w);m->m[2][2]=1-2*(x*x+y*y);m->m[3][2]=oz;
1086 m->m[0][3]= 0 ;m->m[1][3]= 0 ;m->m[2][3]= 0 ;m->m[3][3]=1;
1088 m->m[0][0]=1-2*(y*y+z*z);m->m[0][1]= 2*(x*y-z*w);m->m[0][2]= 2*(x*z+y*w);m->m[0][3]=ox;
1089 m->m[1][0]= 2*(x*y+z*w);m->m[1][1]=1-2*(x*x+z*z);m->m[1][2]= 2*(y*z-x*w);m->m[1][3]=oy;
1090 m->m[2][0]= 2*(x*z-y*w);m->m[2][1]= 2*(y*z+x*w);m->m[2][2]=1-2*(x*x+y*y);m->m[2][3]=oz;
1091 m->m[3][0]= 0 ;m->m[3][1]= 0 ;m->m[3][2]= 0 ;m->m[3][3]=1;
1095 void Matrix4x4_Blend (matrix4x4_t *out, const matrix4x4_t *in1, const matrix4x4_t *in2, double blend)
1097 double iblend = 1 - blend;
1098 out->m[0][0] = in1->m[0][0] * iblend + in2->m[0][0] * blend;
1099 out->m[0][1] = in1->m[0][1] * iblend + in2->m[0][1] * blend;
1100 out->m[0][2] = in1->m[0][2] * iblend + in2->m[0][2] * blend;
1101 out->m[0][3] = in1->m[0][3] * iblend + in2->m[0][3] * blend;
1102 out->m[1][0] = in1->m[1][0] * iblend + in2->m[1][0] * blend;
1103 out->m[1][1] = in1->m[1][1] * iblend + in2->m[1][1] * blend;
1104 out->m[1][2] = in1->m[1][2] * iblend + in2->m[1][2] * blend;
1105 out->m[1][3] = in1->m[1][3] * iblend + in2->m[1][3] * blend;
1106 out->m[2][0] = in1->m[2][0] * iblend + in2->m[2][0] * blend;
1107 out->m[2][1] = in1->m[2][1] * iblend + in2->m[2][1] * blend;
1108 out->m[2][2] = in1->m[2][2] * iblend + in2->m[2][2] * blend;
1109 out->m[2][3] = in1->m[2][3] * iblend + in2->m[2][3] * blend;
1110 out->m[3][0] = in1->m[3][0] * iblend + in2->m[3][0] * blend;
1111 out->m[3][1] = in1->m[3][1] * iblend + in2->m[3][1] * blend;
1112 out->m[3][2] = in1->m[3][2] * iblend + in2->m[3][2] * blend;
1113 out->m[3][3] = in1->m[3][3] * iblend + in2->m[3][3] * blend;
1117 void Matrix4x4_Transform (const matrix4x4_t *in, const float v[3], float out[3])
1119 #ifdef MATRIX4x4_OPENGLORIENTATION
1120 out[0] = v[0] * in->m[0][0] + v[1] * in->m[1][0] + v[2] * in->m[2][0] + in->m[3][0];
1121 out[1] = v[0] * in->m[0][1] + v[1] * in->m[1][1] + v[2] * in->m[2][1] + in->m[3][1];
1122 out[2] = v[0] * in->m[0][2] + v[1] * in->m[1][2] + v[2] * in->m[2][2] + in->m[3][2];
1124 out[0] = v[0] * in->m[0][0] + v[1] * in->m[0][1] + v[2] * in->m[0][2] + in->m[0][3];
1125 out[1] = v[0] * in->m[1][0] + v[1] * in->m[1][1] + v[2] * in->m[1][2] + in->m[1][3];
1126 out[2] = v[0] * in->m[2][0] + v[1] * in->m[2][1] + v[2] * in->m[2][2] + in->m[2][3];
1130 void Matrix4x4_Transform4 (const matrix4x4_t *in, const float v[4], float out[4])
1132 #ifdef MATRIX4x4_OPENGLORIENTATION
1133 out[0] = v[0] * in->m[0][0] + v[1] * in->m[1][0] + v[2] * in->m[2][0] + v[3] * in->m[3][0];
1134 out[1] = v[0] * in->m[0][1] + v[1] * in->m[1][1] + v[2] * in->m[2][1] + v[3] * in->m[3][1];
1135 out[2] = v[0] * in->m[0][2] + v[1] * in->m[1][2] + v[2] * in->m[2][2] + v[3] * in->m[3][2];
1136 out[3] = v[0] * in->m[0][3] + v[1] * in->m[1][3] + v[2] * in->m[2][3] + v[3] * in->m[3][3];
1138 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];
1139 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];
1140 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];
1141 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];
1145 void Matrix4x4_Transform3x3 (const matrix4x4_t *in, const float v[3], float out[3])
1147 #ifdef MATRIX4x4_OPENGLORIENTATION
1148 out[0] = v[0] * in->m[0][0] + v[1] * in->m[1][0] + v[2] * in->m[2][0];
1149 out[1] = v[0] * in->m[0][1] + v[1] * in->m[1][1] + v[2] * in->m[2][1];
1150 out[2] = v[0] * in->m[0][2] + v[1] * in->m[1][2] + v[2] * in->m[2][2];
1152 out[0] = v[0] * in->m[0][0] + v[1] * in->m[0][1] + v[2] * in->m[0][2];
1153 out[1] = v[0] * in->m[1][0] + v[1] * in->m[1][1] + v[2] * in->m[1][2];
1154 out[2] = v[0] * in->m[2][0] + v[1] * in->m[2][1] + v[2] * in->m[2][2];
1159 void Matrix4x4_SimpleUntransform (const matrix4x4_t *in, const float v[3], float out[3])
1162 #ifdef MATRIX4x4_OPENGLORIENTATION
1163 t[0] = v[0] - in->m[3][0];
1164 t[1] = v[1] - in->m[3][1];
1165 t[2] = v[2] - in->m[3][2];
1166 out[0] = t[0] * in->m[0][0] + t[1] * in->m[0][1] + t[2] * in->m[0][2];
1167 out[1] = t[0] * in->m[1][0] + t[1] * in->m[1][1] + t[2] * in->m[1][2];
1168 out[2] = t[0] * in->m[2][0] + t[1] * in->m[2][1] + t[2] * in->m[2][2];
1170 t[0] = v[0] - in->m[0][3];
1171 t[1] = v[1] - in->m[1][3];
1172 t[2] = v[2] - in->m[2][3];
1173 out[0] = t[0] * in->m[0][0] + t[1] * in->m[1][0] + t[2] * in->m[2][0];
1174 out[1] = t[0] * in->m[0][1] + t[1] * in->m[1][1] + t[2] * in->m[2][1];
1175 out[2] = t[0] * in->m[0][2] + t[1] * in->m[1][2] + t[2] * in->m[2][2];
1181 void Matrix4x4_ConcatTranslate (matrix4x4_t *out, double x, double y, double z)
1183 matrix4x4_t base, temp;
1185 Matrix4x4_CreateTranslate(&temp, x, y, z);
1186 Matrix4x4_Concat(out, &base, &temp);
1190 void Matrix4x4_ConcatRotate (matrix4x4_t *out, double angle, double x, double y, double z)
1192 matrix4x4_t base, temp;
1194 Matrix4x4_CreateRotate(&temp, angle, x, y, z);
1195 Matrix4x4_Concat(out, &base, &temp);
1199 void Matrix4x4_ConcatScale (matrix4x4_t *out, double x)
1201 matrix4x4_t base, temp;
1203 Matrix4x4_CreateScale(&temp, x);
1204 Matrix4x4_Concat(out, &base, &temp);
1208 void Matrix4x4_ConcatScale3 (matrix4x4_t *out, double x, double y, double z)
1210 matrix4x4_t base, temp;
1212 Matrix4x4_CreateScale3(&temp, x, y, z);
1213 Matrix4x4_Concat(out, &base, &temp);
1216 void Matrix4x4_OriginFromMatrix (const matrix4x4_t *in, float *out)
1218 #ifdef MATRIX4x4_OPENGLORIENTATION
1219 out[0] = in->m[3][0];
1220 out[1] = in->m[3][1];
1221 out[2] = in->m[3][2];
1223 out[0] = in->m[0][3];
1224 out[1] = in->m[1][3];
1225 out[2] = in->m[2][3];
1229 double Matrix4x4_ScaleFromMatrix (const matrix4x4_t *in)
1231 // we only support uniform scaling, so assume the first row is enough
1232 return sqrt(in->m[0][0] * in->m[0][0] + in->m[0][1] * in->m[0][1] + in->m[0][2] * in->m[0][2]);
1235 void Matrix4x4_SetOrigin (matrix4x4_t *out, double x, double y, double z)
1237 #ifdef MATRIX4x4_OPENGLORIENTATION
1248 void Matrix4x4_AdjustOrigin (matrix4x4_t *out, double x, double y, double z)
1250 #ifdef MATRIX4x4_OPENGLORIENTATION
1261 void Matrix4x4_Scale (matrix4x4_t *out, double rotatescale, double originscale)
1263 out->m[0][0] *= rotatescale;
1264 out->m[0][1] *= rotatescale;
1265 out->m[0][2] *= rotatescale;
1266 out->m[1][0] *= rotatescale;
1267 out->m[1][1] *= rotatescale;
1268 out->m[1][2] *= rotatescale;
1269 out->m[2][0] *= rotatescale;
1270 out->m[2][1] *= rotatescale;
1271 out->m[2][2] *= rotatescale;
1272 #ifdef MATRIX4x4_OPENGLORIENTATION
1273 out->m[3][0] *= originscale;
1274 out->m[3][1] *= originscale;
1275 out->m[3][2] *= originscale;
1277 out->m[0][3] *= originscale;
1278 out->m[1][3] *= originscale;
1279 out->m[2][3] *= originscale;