27#if OOMATHS_OPENGL_INTEGRATION
33 {1.0f, 0.0f, 0.0f, 0.0f},
34 {0.0f, 1.0f, 0.0f, 0.0f},
35 {0.0f, 0.0f, 1.0f, 0.0f},
36 {0.0f, 0.0f, 0.0f, 1.0f}
39 {0.0f, 0.0f, 0.0f, 0.0f},
40 {0.0f, 0.0f, 0.0f, 0.0f},
41 {0.0f, 0.0f, 0.0f, 0.0f},
42 {0.0f, 0.0f, 0.0f, 0.0f},
48 axis = vector_normal(axis);
51 OOScalar s = sin(angle), c = cos(angle);
55 return OOMatrixConstruct
57 t *
x *
x + c, t *
x *
y + s * z, t *
x * z - s *
y, 0.0f,
58 t *
x *
y - s * z, t *
y *
y + c, t *
y * z + s *
x, 0.0f,
59 t *
x *
y + s *
y, t *
y * z - s *
x, t * z * z + c, 0.0f,
60 0.0f, 0.0f, 0.0f, 1.0f
72 Quaternion q = orientation;
73 quaternion_normalize(&q);
80 xx = 2.0f *
x; yy = 2.0f *
y; zz = 2.0f * z;
81 wx = w * xx; wy = w * yy; wz = w * zz;
82 xx =
x * xx; xy =
x * yy; xz =
x * zz;
83 yy =
y * yy; yz =
y * zz;
86 return OOMatrixConstruct
88 1.0f - yy - zz, xy - wz, xz + wy, 0.0f,
89 xy + wz, 1.0f - xx - zz, yz - wx, 0.0f,
90 xz - wy, yz + wx, 1.0f - xx - yy, 0.0f,
91 0.0f, 0.0f, 0.0f, 1.0f
102 for (i = 0; i < 16; i++)
104 if (*ma++ != *mb++)
return false;
117 for (i = 0; i != 4; ++i)
119 r.m[i][0] = a.m[i][0] * b.m[0][0] + a.m[i][1] * b.m[1][0] + a.m[i][2] * b.m[2][0] + a.m[i][3] * b.m[3][0];
120 r.m[i][1] = a.m[i][0] * b.m[0][1] + a.m[i][1] * b.m[1][1] + a.m[i][2] * b.m[2][1] + a.m[i][3] * b.m[3][1];
121 r.m[i][2] = a.m[i][0] * b.m[0][2] + a.m[i][1] * b.m[1][2] + a.m[i][2] * b.m[2][2] + a.m[i][3] * b.m[3][2];
122 r.m[i][3] = a.m[i][0] * b.m[0][3] + a.m[i][1] * b.m[1][3] + a.m[i][2] * b.m[2][3] + a.m[i][3] * b.m[3][3];
133 x = m.m[0][0] * v.x + m.m[1][0] * v.y + m.m[2][0] * v.z + m.m[3][0];
134 y = m.m[0][1] * v.x + m.m[1][1] * v.y + m.m[2][1] * v.z + m.m[3][1];
135 z = m.m[0][2] * v.x + m.m[1][2] * v.y + m.m[2][2] * v.z + m.m[3][2];
136 w = m.m[0][3] * v.x + m.m[1][3] * v.y + m.m[2][3] * v.z + m.m[3][3];
139 return make_vector(
x * w,
y * w, z * w);
149 x = m.m[0][0] * v.x + m.m[1][0] * v.y + m.m[2][0] * v.z + m.m[3][0];
150 y = m.m[0][1] * v.x + m.m[1][1] * v.y + m.m[2][1] * v.z + m.m[3][1];
151 z = m.m[0][2] * v.x + m.m[1][2] * v.y + m.m[2][2] * v.z + m.m[3][2];
152 w = m.m[0][3] * v.x + m.m[1][3] * v.y + m.m[2][3] * v.z + m.m[3][3];
155 return make_HPvector(
x * w,
y * w, z * w);
164 Vector j = { m.m[0][1], m.m[1][1], m.m[2][1] };
165 Vector k = { m.m[0][2], m.m[1][2], m.m[2][2] };
167 k = vector_normal(k);
168 i = vector_normal(cross_product(j, k));
169 j = cross_product(k, i);
171 m.m[0][0] = i.x; m.m[1][0] = i.y; m.m[2][0] = i.z;
172 m.m[0][1] = j.x; m.m[1][1] = j.y; m.m[2][1] = j.z;
173 m.m[0][2] = k.x; m.m[1][2] = k.y; m.m[2][2] = k.z;
180NSString *OOMatrixDescription(OOMatrix matrix)
182 return [NSString stringWithFormat:@"{{%g, %g, %g, %g}, {%g, %g, %g, %g}, {%g, %g, %g, %g}, {%g, %g, %g, %g}}",
183 matrix.m[0][0], matrix.m[0][1], matrix.m[0][2], matrix.m[0][3],
184 matrix.m[1][0], matrix.m[1][1], matrix.m[1][2], matrix.m[1][3],
185 matrix.m[2][0], matrix.m[2][1], matrix.m[2][2], matrix.m[2][3],
186 matrix.m[3][0], matrix.m[3][1], matrix.m[3][2], matrix.m[3][3]];
193 Vector v0, v1, v2, arbv;
195 v0 = HPVectorToVector(HPvector_subtract(bbPos, eyePos));
204 v1 = cross_product(v0, arbv);
205 v2 = cross_product(v0, v1);
207 return OOMatrixFromBasisVectors(v1, v2, v0);
213 if (row1<0 || row1 >= 4 || row2 < 0 || row2 >= 4 || row1 == row2 )
219 for (i = 0; i < 4; i++)
222 M->m[row1][i] = M->m[row2][i];
230 if (row < 0 || row >= 4)
235 for (i = 0; i < 4; i++)
237 M->m[row][i] *= factor;
244 if (row1 < 0 || row1 >= 4 || row2 < 0 || row2 >= 4)
249 for (i = 0; i < 4; i++)
251 M->m[row1][i] = factor1 * M->m[row1][i] + factor2 * M->m[row2][i];
258 if (column1<0 || column1 >= 4 || column2 < 0 || column2 >= 4 || column1 == column2 )
264 for (i = 0; i < 4; i++)
266 x = M->m[i][column1];
267 M->m[i][column1] = M->m[i][column2];
268 M->m[i][column2] =
x;
275 if (column < 0 || column >= 4)
280 for (i = 0; i < 4; i++)
282 M->m[i][column] *= factor;
289 if (column1 < 0 || column1 >= 4 || column2 < 0 || column2 >= 4)
294 for (i = 0; i < 4; i++)
296 M->m[i][column1] = factor1 * M->m[i][column1] + factor2 * M->m[i][column2];
305 for (i = 0; i < 4; i++)
307 if (A.m[i][i] == 0.0)
310 for (j = i+1; j < 4; j++)
312 if (A.m[j][i] != 0.0)
327 for (j = i+1; j < 4; j++)
333 for (i = 3; i > 0; i--)
335 for (j = 0; j < i; j++)
348 for (i = 0; i < 4; i++)
350 if (A.m[i][i] == 0.0)
353 for (j = i+1; j < 4; j++)
355 if (A.m[j][i] != 0.0)
370 for (j = i+1; j < 4; j++)
372 if (A.m[j][i] != 0.0)
379 for (i = 3; i > 0; i--)
381 for (j = 0; j < i; j++)
383 if (A.m[j][i] != 0.0)
406 for (i = 0; i < 4; i++)
408 max_value = fabsf(M.m[i][i]);
410 for (j = i+1; j < 4; j++)
412 if (fabs(M.m[j][i]) > max_value)
415 max_value = fabs(M.m[j][i]);
418 if (max_value == 0.0)
432 for (j = i+1; j < 4; j++)
434 if (M.m[j][i] != 0.0)
441 for (i = 3; i > 0; i--)
443 for (j = 0; j < i; j++)
445 if (M.m[j][i] != 0.0)
455#if OOMATHS_OPENGL_INTEGRATION
469 OOGL(glUniformMatrix3fvARB(location, 1, NO, m));
HPVector OOHPVectorMultiplyMatrix(HPVector v, OOMatrix m)
void OOMatrixColumnSwap(OOMatrix *M, int column1, int column2)
OOMatrix OOMatrixMultiply(OOMatrix a, OOMatrix b)
bool OOMatrixEqual(OOMatrix a, OOMatrix b)
OOMatrix OOMatrixForBillboard(HPVector bbPos, HPVector eyePos)
OOMatrix OOMatrixLeftTransform(OOMatrix A, OOMatrix B)
void GLUniformMatrix3(int location, OOMatrix M)
void OOMatrixColumnOperation(OOMatrix *M, int column1, OOScalar factor1, int column2, OOScalar factor2)
void OOMatrixColumnScale(OOMatrix *M, int column, OOScalar factor)
OOMatrix OOMatrixRightTransform(OOMatrix A, OOMatrix B)
OOMatrix OOMatrixForRotation(Vector axis, OOScalar angle)
OOMatrix OOMatrixOrthogonalize(OOMatrix m)
OOMatrix OOMatrixInverseWithDeterminant(OOMatrix M, OOScalar *d)
void OOMatrixRowSwap(OOMatrix *M, int row1, int row2)
const OOMatrix kIdentityMatrix
void OOMatrixRowScale(OOMatrix *M, int row, OOScalar factor)
Vector OOVectorMultiplyMatrix(Vector v, OOMatrix m)
const OOMatrix kZeroMatrix
OOMatrix OOMatrixInverse(OOMatrix M)
void OOMatrixRowOperation(OOMatrix *M, int row1, OOScalar factor1, int row2, OOScalar factor2)
OOMatrix OOMatrixForQuaternionRotation(Quaternion orientation)
const Vector kBasisZVector
const Vector kBasisXVector