Oolite
Loading...
Searching...
No Matches
OOMatrix.h File Reference
#include "OOQuaternion.h"
#include "OOVector.h"
Include dependency graph for OOMatrix.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  OOMatrix

Macros

#define OOMatrixValuesForOpenGL(M)
#define GLMultOOMatrix(M)
#define GLLoadOOMatrix(M)
#define GLMultTransposeOOMatrix(M)
#define GLLoadTransposeOOMatrix(M)
#define GLUniformMatrix(location, M)

Typedefs

typedef struct OOMatrix OOMatrix

Functions

OOINLINE OOMatrix OOMatrixConstruct (OOScalar aa, OOScalar ab, OOScalar ac, OOScalar ad, OOScalar ba, OOScalar bb, OOScalar bc, OOScalar bd, OOScalar ca, OOScalar cb, OOScalar cc, OOScalar cd, OOScalar da, OOScalar db, OOScalar dc, OOScalar dd) INLINE_CONST_FUNC
OOINLINE OOMatrix OOMatrixFromOrientationAndPosition (Quaternion orientation, Vector position) INLINE_CONST_FUNC
OOINLINE OOMatrix OOMatrixFromBasisVectorsAndPosition (Vector i, Vector j, Vector k, Vector position) INLINE_CONST_FUNC
OOINLINE OOMatrix OOMatrixFromBasisVectors (Vector i, Vector j, Vector k) INLINE_CONST_FUNC
OOINLINE OOMatrix OOMatrixForScale (OOScalar sx, OOScalar sy, OOScalar sz) INLINE_CONST_FUNC
OOINLINE OOMatrix OOMatrixForScaleUniform (OOScalar s) INLINE_CONST_FUNC
OOINLINE OOMatrix OOMatrixForRotationX (OOScalar angle) INLINE_CONST_FUNC
OOINLINE OOMatrix OOMatrixForRotationY (OOScalar angle) INLINE_CONST_FUNC
OOINLINE OOMatrix OOMatrixForRotationZ (OOScalar angle) INLINE_CONST_FUNC
OOMatrix OOMatrixForRotation (Vector axis, OOScalar angle) CONST_FUNC
OOMatrix OOMatrixForQuaternionRotation (Quaternion orientation)
OOINLINE OOMatrix OOMatrixForTranslation (Vector v) INLINE_CONST_FUNC
OOINLINE OOMatrix OOMatrixForTranslationComponents (OOScalar dx, OOScalar dy, OOScalar dz) INLINE_CONST_FUNC
OOMatrix OOMatrixForBillboard (HPVector bbPos, HPVector eyePos) CONST_FUNC
OOINLINE OOMatrix OOMatrixTranslate (OOMatrix m, Vector offset) INLINE_CONST_FUNC
OOINLINE OOMatrix OOMatrixHPTranslate (OOMatrix m, HPVector offset) INLINE_CONST_FUNC
OOINLINE OOMatrix OOMatrixTranslateComponents (OOMatrix m, OOScalar dx, OOScalar dy, OOScalar dz) INLINE_CONST_FUNC
OOINLINE OOMatrix OOMatrixScale (OOMatrix m, OOScalar sx, OOScalar sy, OOScalar sz) INLINE_CONST_FUNC
OOINLINE OOMatrix OOMatrixScaleUniform (OOMatrix m, OOScalar s) INLINE_CONST_FUNC
OOINLINE OOMatrix OOMatrixRotateX (OOMatrix m, OOScalar angle) INLINE_CONST_FUNC
OOINLINE OOMatrix OOMatrixRotateY (OOMatrix m, OOScalar angle) INLINE_CONST_FUNC
OOINLINE OOMatrix OOMatrixRotateZ (OOMatrix m, OOScalar angle) INLINE_CONST_FUNC
OOINLINE OOMatrix OOMatrixRotate (OOMatrix m, Vector axis, OOScalar angle) INLINE_CONST_FUNC
OOINLINE OOMatrix OOMatrixRotateQuaternion (OOMatrix m, Quaternion quat) INLINE_CONST_FUNC
OOINLINE OOMatrix OOMatrixTranspose (OOMatrix m) INLINE_CONST_FUNC
bool OOMatrixEqual (OOMatrix a, OOMatrix b) CONST_FUNC
OOINLINE bool OOMatrixIsIdentity (OOMatrix m) INLINE_CONST_FUNC
OOMatrix OOMatrixMultiply (OOMatrix a, OOMatrix b) CONST_FUNC
Vector OOVectorMultiplyMatrix (Vector v, OOMatrix m) CONST_FUNC
HPVector OOHPVectorMultiplyMatrix (HPVector v, OOMatrix m) CONST_FUNC
OOINLINE void OOMatrixGetBasisVectors (OOMatrix m, Vector *outRight, Vector *outUp, Vector *outForward) NONNULL_FUNC ALWAYS_INLINE_FUNC
OOMatrix OOMatrixOrthogonalize (OOMatrix m) CONST_FUNC
void GLUniformMatrix3 (GLint location, OOMatrix M)
OOINLINE OOMatrix OOMatrixLoadGLMatrix (GLenum matrixID) ALWAYS_INLINE_FUNC
void OOMatrixRowSwap (OOMatrix *M, int row1, int row2)
void OOMatrixRowScale (OOMatrix *m, int row, OOScalar factor)
void OOMatrixRowOperation (OOMatrix *M, int row1, OOScalar factor1, int row2, OOScalar factor2)
void OOMatrixColumnSwap (OOMatrix *M, int column1, int column2)
void OOMatrixColumnScale (OOMatrix *M, int column, OOScalar factor)
void OOMatrixColumnOperation (OOMatrix *M, int column1, OOScalar factor1, int column2, OOScalar factor2)
OOMatrix OOMatrixLeftTransform (OOMatrix A, OOMatrix B)
OOMatrix OOMatrixRightTransform (OOMatrix A, OOMatrix B)
OOMatrix OOMatrixInverse (OOMatrix M)
OOMatrix OOMatrixInverseWithDeterminant (OOMatrix M, OOScalar *determinant)

Variables

const OOMatrix kIdentityMatrix
const OOMatrix kZeroMatrix

Macro Definition Documentation

◆ GLLoadOOMatrix

#define GLLoadOOMatrix ( M)
Value:
do { \
OOMatrix m_ = M; \
OOGL(glLoadMatrixf(OOMatrixValuesForOpenGL(m_))); \
} while (0)
#define OOMatrixValuesForOpenGL(M)
Definition OOMatrix.h:92

Definition at line 98 of file OOMatrix.h.

98#define GLLoadOOMatrix(M) \
99 do { \
100 OOMatrix m_ = M; \
101 OOGL(glLoadMatrixf(OOMatrixValuesForOpenGL(m_))); \
102 } while (0)

Referenced by OOOpenGLMatrixManager::syncModelView, and OOOpenGLMatrixManager::syncProjection.

◆ GLLoadTransposeOOMatrix

#define GLLoadTransposeOOMatrix ( M)
Value:
do { \
OOMatrix m_ = M; \
OOGL(glLoadTransposeMatrixf(OOMatrixValuesForOpenGL(m_))); \
} while (0)

Definition at line 108 of file OOMatrix.h.

108#define GLLoadTransposeOOMatrix(M) \
109 do { \
110 OOMatrix m_ = M; \
111 OOGL(glLoadTransposeMatrixf(OOMatrixValuesForOpenGL(m_))); \
112 } while (0)

◆ GLMultOOMatrix

#define GLMultOOMatrix ( M)
Value:
do { \
OOMatrix m_ = M; \
OOGL(glMultMatrixf(OOMatrixValuesForOpenGL(m_))); \
} while (0)

Definition at line 93 of file OOMatrix.h.

93#define GLMultOOMatrix(M) \
94 do { \
95 OOMatrix m_ = M; \
96 OOGL(glMultMatrixf(OOMatrixValuesForOpenGL(m_))); \
97 } while (0)

◆ GLMultTransposeOOMatrix

#define GLMultTransposeOOMatrix ( M)
Value:
do { \
OOMatrix m_ = M; \
OOGL(glMultTransposeMatrixf(OOMatrixValuesForOpenGL(m_))); \
} while (0)

Definition at line 103 of file OOMatrix.h.

103#define GLMultTransposeOOMatrix(M) \
104 do { \
105 OOMatrix m_ = M; \
106 OOGL(glMultTransposeMatrixf(OOMatrixValuesForOpenGL(m_))); \
107 } while (0)

◆ GLUniformMatrix

#define GLUniformMatrix ( location,
M )
Value:
do { \
OOGL(glUniformMatrix4fvARB(location, 1, NO, OOMatrixValuesForOpenGL(M))); \
} while (0)

Definition at line 113 of file OOMatrix.h.

113#define GLUniformMatrix(location, M) \
114 do { \
115 OOGL(glUniformMatrix4fvARB(location, 1, NO, OOMatrixValuesForOpenGL(M))); \
116 } while (0)

◆ OOMatrixValuesForOpenGL

#define OOMatrixValuesForOpenGL ( M)
Value:
(&(M).m[0][0])

Definition at line 92 of file OOMatrix.h.

Referenced by OOMatrixLoadGLMatrix().

Typedef Documentation

◆ OOMatrix

typedef struct OOMatrix OOMatrix

Function Documentation

◆ GLUniformMatrix3()

void GLUniformMatrix3 ( GLint location,
OOMatrix M )

References ALWAYS_INLINE_FUNC, and OOINLINE.

◆ OOHPVectorMultiplyMatrix()

HPVector OOHPVectorMultiplyMatrix ( HPVector v,
OOMatrix m )

Definition at line 137 of file OOMatrix.m.

138{
139 OOScalar x, y, z, w;
140
141 x = m.m[0][0] * v.x + m.m[1][0] * v.y + m.m[2][0] * v.z + m.m[3][0];
142 y = m.m[0][1] * v.x + m.m[1][1] * v.y + m.m[2][1] * v.z + m.m[3][1];
143 z = m.m[0][2] * v.x + m.m[1][2] * v.y + m.m[2][2] * v.z + m.m[3][2];
144 w = m.m[0][3] * v.x + m.m[1][3] * v.y + m.m[2][3] * v.z + m.m[3][3];
145
146 w = 1.0f / w;
147 return make_HPvector(x * w, y * w, z * w);
148}
OOINLINE HPVector make_HPvector(OOHPScalar vx, OOHPScalar vy, OOHPScalar vz) INLINE_CONST_FUNC
Definition OOHPVector.h:149
GLfloat OOScalar
Definition OOMaths.h:49
float y
float x
OOHPScalar x
Definition OOHPVector.h:36
OOHPScalar y
Definition OOHPVector.h:37
OOHPScalar z
Definition OOHPVector.h:38
OOScalar m[4][4]
Definition OOMatrix.h:31

References OOMatrix::m, make_HPvector(), HPVector::x, x, HPVector::y, y, and HPVector::z.

Referenced by Entity::absolutePositionForSubentityOffset:, OOLightParticleEntity::drawSubEntityImmediate:translucent:, ShipEntity::fireTurretCannon:, OOExhaustPlumeEntity::resetPlume, and OOExhaustPlumeEntity(Private)::saveToLastFrame.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOMatrixColumnOperation()

void OOMatrixColumnOperation ( OOMatrix * M,
int column1,
OOScalar factor1,
int column2,
OOScalar factor2 )

Definition at line 273 of file OOMatrix.m.

274{
275 if (column1 < 0 || column1 >= 4 || column2 < 0 || column2 >= 4) {
276 return;
277 }
278 int i;
279 for (i = 0; i < 4; i++) {
280 M->m[i][column1] = factor1 * M->m[i][column1] + factor2 * M->m[i][column2];
281 }
282 return;
283}

References OOMatrix::m.

Referenced by OOMatrixLeftTransform().

Here is the caller graph for this function:

◆ OOMatrixColumnScale()

void OOMatrixColumnScale ( OOMatrix * M,
int column,
OOScalar factor )

Definition at line 261 of file OOMatrix.m.

262{
263 if (column < 0 || column >= 4) {
264 return;
265 }
266 int i;
267 for (i = 0; i < 4; i++) {
268 M->m[i][column] *= factor;
269 }
270 return;
271}

References OOMatrix::m.

Referenced by OOMatrixLeftTransform().

Here is the caller graph for this function:

◆ OOMatrixColumnSwap()

void OOMatrixColumnSwap ( OOMatrix * M,
int column1,
int column2 )

Definition at line 246 of file OOMatrix.m.

247{
248 if (column1 < 0 || column1 >= 4 || column2 < 0 || column2 >= 4 || column1 == column2) {
249 return;
250 }
251 float x;
252 int i;
253 for (i = 0; i < 4; i++) {
254 x = M->m[i][column1];
255 M->m[i][column1] = M->m[i][column2];
256 M->m[i][column2] = x;
257 }
258 return;
259}

References OOMatrix::m, and x.

Referenced by OOMatrixLeftTransform().

Here is the caller graph for this function:

◆ OOMatrixConstruct()

OOINLINE OOMatrix OOMatrixConstruct ( OOScalar aa,
OOScalar ab,
OOScalar ac,
OOScalar ad,
OOScalar ba,
OOScalar bb,
OOScalar bc,
OOScalar bd,
OOScalar ca,
OOScalar cb,
OOScalar cc,
OOScalar cd,
OOScalar da,
OOScalar db,
OOScalar dc,
OOScalar dd )

Definition at line 158 of file OOMatrix.h.

162{
163 OOMatrix r = { { { aa, ab, ac, ad },
164 { ba, bb, bc, bd },
165 { ca, cb, cc, cd },
166 { da, db, dc, dd } } };
167 return r;
168}

References OOINLINE.

Referenced by OOOpenGLMatrixManager::lookAtWithEye:center:up:, OOMatrixForQuaternionRotation(), OOMatrixForRotation(), OOMatrixForRotationX(), OOMatrixForRotationY(), OOMatrixForRotationZ(), OOMatrixForScale(), OOMatrixForTranslationComponents(), OOMatrixFromBasisVectorsAndPosition(), and OOMatrixTranspose().

Here is the caller graph for this function:

◆ OOMatrixEqual()

bool OOMatrixEqual ( OOMatrix a,
OOMatrix b )

Definition at line 91 of file OOMatrix.m.

92{
93 OOScalar* ma = &a.m[0][0];
94 OOScalar* mb = &b.m[0][0];
95
96 unsigned i;
97 for (i = 0; i < 16; i++) {
98 if (*ma++ != *mb++)
99 return false;
100 }
101
102 return true;
103}

References OOMatrix::m.

Referenced by OOMesh::findSubentityBoundingBoxWithPosition:rotMatrix:, and OOMatrixIsIdentity().

Here is the caller graph for this function:

◆ OOMatrixForBillboard()

OOMatrix OOMatrixForBillboard ( HPVector bbPos,
HPVector eyePos )

Definition at line 186 of file OOMatrix.m.

187{
188 Vector v0, v1, v2, arbv;
189
190 v0 = HPVectorToVector(HPvector_subtract(bbPos, eyePos));
191 // once the subtraction is done safe to lose precision since
192 // we're now dealing with relatively small vectors
194
195 // arbitrary axis - not aligned with v0
196 if (EXPECT_NOT(v0.x == 0.0 && v0.y == 0.0))
197 arbv = kBasisXVector;
198 else
199 arbv = kBasisZVector;
200
201 v1 = cross_product(v0, arbv); // 90 degrees to (v0 x arb1)
202 v2 = cross_product(v0, v1); // 90 degrees to (v0 x v1)
203
204 return OOMatrixFromBasisVectors(v1, v2, v0);
205}
#define EXPECT_NOT(x)
OOINLINE HPVector HPvector_subtract(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:236
OOINLINE Vector HPVectorToVector(HPVector v) INLINE_CONST_FUNC
Definition OOHPVector.h:175
OOINLINE OOMatrix OOMatrixFromBasisVectors(Vector i, Vector j, Vector k) INLINE_CONST_FUNC
Definition OOMatrix.h:185
OOINLINE Vector vector_normal_or_fallback(Vector vec, Vector fallback) INLINE_CONST_FUNC
Definition OOVector.h:247
OOINLINE Vector cross_product(Vector first, Vector second) INLINE_CONST_FUNC
Definition OOVector.h:294
const Vector kBasisZVector
Definition OOVector.h:47
const Vector kBasisXVector
Definition OOVector.h:45
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33

References cross_product(), EXPECT_NOT, HPvector_subtract(), HPVectorToVector(), kBasisXVector, kBasisZVector, OOMatrixFromBasisVectors(), vector_normal_or_fallback(), Vector::x, and Vector::y.

Referenced by OOParticleSystem::drawImmediate:translucent:, OOQuiriumCascadeEntity::update:, OOSunEntity::update:, and WormholeEntity::update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOMatrixForQuaternionRotation()

OOMatrix OOMatrixForQuaternionRotation ( Quaternion orientation)

Definition at line 56 of file OOMatrix.m.

57{
58 OOScalar w, wz, wy, wx;
59 OOScalar x, xz, xy, xx;
60 OOScalar y, yz, yy;
61 OOScalar z, zz;
62
63 Quaternion q = orientation;
65
66 w = q.w;
67 z = q.z;
68 y = q.y;
69 x = q.x;
70
71 xx = 2.0f * x;
72 yy = 2.0f * y;
73 zz = 2.0f * z;
74 wx = w * xx;
75 wy = w * yy;
76 wz = w * zz;
77 xx = x * xx;
78 xy = x * yy;
79 xz = x * zz;
80 yy = y * yy;
81 yz = y * zz;
82 zz = z * zz;
83
84 return OOMatrixConstruct(
85 1.0f - yy - zz, xy - wz, xz + wy, 0.0f,
86 xy + wz, 1.0f - xx - zz, yz - wx, 0.0f,
87 xz - wy, yz + wx, 1.0f - xx - yy, 0.0f,
88 0.0f, 0.0f, 0.0f, 1.0f);
89}
OOINLINE OOMatrix OOMatrixConstruct(OOScalar aa, OOScalar ab, OOScalar ac, OOScalar ad, OOScalar ba, OOScalar bb, OOScalar bc, OOScalar bd, OOScalar ca, OOScalar cb, OOScalar cc, OOScalar cd, OOScalar da, OOScalar db, OOScalar dc, OOScalar dd) INLINE_CONST_FUNC
Definition OOMatrix.h:158
OOINLINE void quaternion_normalize(Quaternion *quat) NONNULL_FUNC ALWAYS_INLINE_FUNC
OOScalar w
OOScalar x
OOScalar y
OOScalar z

References OOMatrixConstruct(), quaternion_normalize(), Quaternion::w, Quaternion::x, x, Quaternion::y, y, and Quaternion::z.

Referenced by HeadUpDisplay::hudRotateViewpointForVirtualDepth, OOMatrixFromOrientationAndPosition(), OOMatrixRotateQuaternion(), Entity::orientationChanged, PlayerEntity::orientationChanged, and PlayerEntity::setCustomViewData.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOMatrixForRotation()

OOMatrix OOMatrixForRotation ( Vector axis,
OOScalar angle )

Definition at line 40 of file OOMatrix.m.

41{
42 axis = vector_normal(axis);
43
44 OOScalar x = axis.x, y = axis.y, z = axis.z;
45 OOScalar s = sin(angle), c = cos(angle);
46 OOScalar t = 1.0f - c;
47
48 // Lots of opportunity for common subexpression elimintation here, but I'll leave it to the compiler for now.
49 return OOMatrixConstruct(
50 t * x * x + c, t * x * y + s * z, t * x * z - s * y, 0.0f,
51 t * x * y - s * z, t * y * y + c, t * y * z + s * x, 0.0f,
52 t * x * y + s * y, t * y * z - s * x, t * z * z + c, 0.0f,
53 0.0f, 0.0f, 0.0f, 1.0f);
54}
OOINLINE Vector vector_normal(Vector vec) INLINE_CONST_FUNC
Definition OOVector.h:270
OOScalar z
Definition OOVector.h:34

References OOMatrixConstruct(), vector_normal(), Vector::x, x, Vector::y, y, and Vector::z.

Referenced by OOMatrixRotate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOMatrixForRotationX()

OOMatrix OOMatrixForRotationX ( OOScalar angle)

Definition at line 191 of file OOMatrix.h.

192{
193 OOScalar s, c;
194
195 s = sin(angle);
196 c = cos(angle);
197
198 return OOMatrixConstruct(
199 1, 0, 0, 0,
200 0, c, s, 0,
201 0, -s, c, 0,
202 0, 0, 0, 1);
203}

References OOMatrixConstruct().

Referenced by OOMatrixRotateX().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOMatrixForRotationY()

OOMatrix OOMatrixForRotationY ( OOScalar angle)

Definition at line 205 of file OOMatrix.h.

206{
207 OOScalar s, c;
208
209 s = sin(angle);
210 c = cos(angle);
211
212 return OOMatrixConstruct(
213 c, 0, -s, 0,
214 0, 1, 0, 0,
215 s, 0, c, 0,
216 0, 0, 0, 1);
217}

References OOMatrixConstruct().

Referenced by OOMatrixRotateY().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOMatrixForRotationZ()

OOMatrix OOMatrixForRotationZ ( OOScalar angle)

Definition at line 219 of file OOMatrix.h.

220{
221 OOScalar s, c;
222
223 s = sin(angle);
224 c = cos(angle);
225
226 return OOMatrixConstruct(
227 c, s, 0, 0,
228 -s, c, 0, 0,
229 0, 0, 1, 0,
230 0, 0, 0, 1);
231}

References OOMatrixConstruct().

Referenced by OOTrumble::drawTrumble:, and OOMatrixRotateZ().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOMatrixForScale()

OOINLINE OOMatrix OOMatrixForScale ( OOScalar sx,
OOScalar sy,
OOScalar sz )

Definition at line 264 of file OOMatrix.h.

265{
266 return OOMatrixConstruct(
267 sx, 0, 0, 0,
268 0, sy, 0, 0,
269 0, 0, sz, 0,
270 0, 0, 0, 1);
271}

References OOINLINE, and OOMatrixConstruct().

Referenced by Universe::drawUniverse, OOMatrixForScaleUniform(), and OOMatrixScale().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOMatrixForScaleUniform()

OOINLINE OOMatrix OOMatrixForScaleUniform ( OOScalar s)

Definition at line 273 of file OOMatrix.h.

274{
275 return OOMatrixForScale(s, s, s);
276}
OOINLINE OOMatrix OOMatrixForScale(OOScalar sx, OOScalar sy, OOScalar sz) INLINE_CONST_FUNC
Definition OOMatrix.h:264

References OOINLINE, and OOMatrixForScale().

Here is the call graph for this function:

◆ OOMatrixForTranslation()

OOINLINE OOMatrix OOMatrixForTranslation ( Vector v)

Definition at line 241 of file OOMatrix.h.

242{
243 return OOMatrixForTranslationComponents(v.x, v.y, v.z);
244}
OOINLINE OOMatrix OOMatrixForTranslationComponents(OOScalar dx, OOScalar dy, OOScalar dz) INLINE_CONST_FUNC
Definition OOMatrix.h:232

References OOINLINE, OOMatrixForTranslationComponents(), Vector::x, Vector::y, and Vector::z.

Here is the call graph for this function:

◆ OOMatrixForTranslationComponents()

OOINLINE OOMatrix OOMatrixForTranslationComponents ( OOScalar dx,
OOScalar dy,
OOScalar dz )

Definition at line 232 of file OOMatrix.h.

233{
234 return OOMatrixConstruct(
235 1, 0, 0, 0,
236 0, 1, 0, 0,
237 0, 0, 1, 0,
238 dx, dy, dz, 1);
239}

References OOINLINE, and OOMatrixConstruct().

Referenced by OOMatrixForTranslation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOMatrixFromBasisVectors()

OOINLINE OOMatrix OOMatrixFromBasisVectors ( Vector i,
Vector j,
Vector k )

Definition at line 185 of file OOMatrix.h.

186{
188}
OOINLINE OOMatrix OOMatrixFromBasisVectorsAndPosition(Vector i, Vector j, Vector k, Vector position) INLINE_CONST_FUNC
Definition OOMatrix.h:176
const Vector kZeroVector
Definition OOVector.m:27

References kZeroVector, OOINLINE, and OOMatrixFromBasisVectorsAndPosition().

Referenced by Universe::firstEntityTargetedByPlayer, Universe::firstShipHitByLaserFromShip:inDirection:offset:gettingRangeFound:, and OOMatrixForBillboard().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOMatrixFromBasisVectorsAndPosition()

OOINLINE OOMatrix OOMatrixFromBasisVectorsAndPosition ( Vector i,
Vector j,
Vector k,
Vector position )

Definition at line 176 of file OOMatrix.h.

177{
178 return OOMatrixConstruct(
179 i.x, i.y, i.z, 0.0f,
180 j.x, j.y, j.z, 0.0f,
181 k.x, k.y, k.z, 0.0f,
182 p.x, p.y, p.z, 1.0f);
183}

References OOINLINE, OOMatrixConstruct(), Vector::x, Vector::y, and Vector::z.

Referenced by OOMatrixFromBasisVectors().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOMatrixFromOrientationAndPosition()

OOINLINE OOMatrix OOMatrixFromOrientationAndPosition ( Quaternion orientation,
Vector position )

Definition at line 170 of file OOMatrix.h.

171{
173 return OOMatrixTranslate(m, position);
174}
OOINLINE OOMatrix OOMatrixTranslate(OOMatrix m, Vector offset) INLINE_CONST_FUNC
Definition OOMatrix.h:254
OOMatrix OOMatrixForQuaternionRotation(Quaternion orientation)
Definition OOMatrix.m:56

References OOINLINE, OOMatrixForQuaternionRotation(), and OOMatrixTranslate().

Here is the call graph for this function:

◆ OOMatrixGetBasisVectors()

OOINLINE void OOMatrixGetBasisVectors ( OOMatrix m,
Vector * outRight,
Vector * outUp,
Vector * outForward )

Definition at line 318 of file OOMatrix.h.

319{
320 assert(outRight != NULL && outUp != NULL && outForward != NULL);
321
322 *outRight = make_vector(m.m[0][0], m.m[1][0], m.m[2][0]);
323 *outUp = make_vector(m.m[0][1], m.m[1][1], m.m[2][1]);
324 *outForward = make_vector(m.m[0][2], m.m[1][2], m.m[2][2]);
325}
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
Definition OOVector.h:149

References OOMatrix::m, make_vector(), and OOINLINE.

Referenced by PlayerEntity::orientationChanged.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOMatrixHPTranslate()

OOINLINE OOMatrix OOMatrixHPTranslate ( OOMatrix m,
HPVector offset )

Definition at line 259 of file OOMatrix.h.

260{
262}
OOINLINE OOMatrix OOMatrixTranslateComponents(OOMatrix m, OOScalar dx, OOScalar dy, OOScalar dz) INLINE_CONST_FUNC
Definition OOMatrix.h:246
voidpf uLong offset
Definition ioapi.h:132

References OOINLINE, and OOMatrixTranslateComponents().

Referenced by Entity::drawTransformationMatrix, and Entity::transformationMatrix.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOMatrixInverse()

OOMatrix OOMatrixInverse ( OOMatrix M)

Definition at line 359 of file OOMatrix.m.

360{
362}
const OOMatrix kIdentityMatrix
Definition OOMatrix.m:28
OOMatrix OOMatrixLeftTransform(OOMatrix A, OOMatrix B)
Definition OOMatrix.m:285

References kIdentityMatrix, and OOMatrixLeftTransform().

Referenced by OOOpenGLMatrixManager::getMatrix:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOMatrixInverseWithDeterminant()

OOMatrix OOMatrixInverseWithDeterminant ( OOMatrix M,
OOScalar * determinant )

Definition at line 364 of file OOMatrix.m.

365{
366 int i, j;
368 int best_row;
369 float max_value;
370
371 *d = 1.0;
372 for (i = 0; i < 4; i++) {
373 max_value = fabsf(M.m[i][i]);
374 best_row = i;
375 for (j = i + 1; j < 4; j++) {
376 if (fabs(M.m[j][i]) > max_value) {
377 best_row = j;
378 max_value = fabs(M.m[j][i]);
379 }
380 }
381 if (max_value == 0.0) {
382 *d = 0.0;
383 return kZeroMatrix;
384 }
385 if (best_row != i) {
386 OOMatrixRowSwap(&M, i, best_row);
387 OOMatrixRowSwap(&B, i, best_row);
388 *d *= -1;
389 }
390 *d /= M.m[i][i];
391 OOMatrixRowScale(&B, i, 1 / M.m[i][i]);
392 OOMatrixRowScale(&M, i, 1 / M.m[i][i]);
393 for (j = i + 1; j < 4; j++) {
394 if (M.m[j][i] != 0.0) {
395 OOMatrixRowOperation(&B, j, 1, i, -M.m[j][i]);
396 OOMatrixRowOperation(&M, j, 1, i, -M.m[j][i]);
397 }
398 }
399 }
400 for (i = 3; i > 0; i--) {
401 for (j = 0; j < i; j++) {
402 if (M.m[j][i] != 0.0) {
403 OOMatrixRowOperation(&B, j, 1, i, -M.m[j][i]);
404 OOMatrixRowOperation(&M, j, 1, i, -M.m[j][i]);
405 }
406 }
407 }
408 return B;
409}
const OOMatrix kZeroMatrix
Definition OOMatrix.m:33
void OOMatrixRowSwap(OOMatrix *M, int row1, int row2)
Definition OOMatrix.m:207
void OOMatrixRowScale(OOMatrix *M, int row, OOScalar factor)
Definition OOMatrix.m:222
void OOMatrixRowOperation(OOMatrix *M, int row1, OOScalar factor1, int row2, OOScalar factor2)
Definition OOMatrix.m:234

References kIdentityMatrix, kZeroMatrix, OOMatrix::m, OOMatrixRowOperation(), OOMatrixRowScale(), and OOMatrixRowSwap().

Referenced by OOOpenGLMatrixManager::getMatrix:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOMatrixIsIdentity()

OOINLINE bool OOMatrixIsIdentity ( OOMatrix m)

Definition at line 313 of file OOMatrix.h.

314{
316}
bool OOMatrixEqual(OOMatrix a, OOMatrix b) CONST_FUNC
Definition OOMatrix.m:91

References kIdentityMatrix, OOINLINE, and OOMatrixEqual().

Here is the call graph for this function:

◆ OOMatrixLeftTransform()

OOMatrix OOMatrixLeftTransform ( OOMatrix A,
OOMatrix B )

Definition at line 285 of file OOMatrix.m.

286{
287 int i, j;
288 bool found;
289 for (i = 0; i < 4; i++) {
290 if (A.m[i][i] == 0.0) {
291 found = false;
292 for (j = i + 1; j < 4; j++) {
293 if (A.m[j][i] != 0.0) {
294 found = true;
295 OOMatrixColumnSwap(&A, i, j);
296 OOMatrixColumnSwap(&B, i, j);
297 break;
298 }
299 }
300 if (!found) {
301 return kZeroMatrix;
302 }
303 }
304 OOMatrixColumnScale(&B, i, 1 / A.m[i][i]);
305 OOMatrixColumnScale(&A, i, 1 / A.m[i][i]);
306 for (j = i + 1; j < 4; j++) {
307 OOMatrixColumnOperation(&B, j, 1, i, -A.m[i][j]);
308 OOMatrixColumnOperation(&A, j, 1, i, -A.m[i][j]);
309 }
310 }
311 for (i = 3; i > 0; i--) {
312 for (j = 0; j < i; j++) {
313 OOMatrixColumnOperation(&B, j, 1, i, -A.m[i][j]);
314 OOMatrixColumnOperation(&A, j, 1, i, -A.m[i][j]);
315 }
316 }
317 return B;
318}
void OOMatrixColumnSwap(OOMatrix *M, int column1, int column2)
Definition OOMatrix.m:246
void OOMatrixColumnOperation(OOMatrix *M, int column1, OOScalar factor1, int column2, OOScalar factor2)
Definition OOMatrix.m:273
void OOMatrixColumnScale(OOMatrix *M, int column, OOScalar factor)
Definition OOMatrix.m:261

References kZeroMatrix, OOMatrix::m, OOMatrixColumnOperation(), OOMatrixColumnScale(), and OOMatrixColumnSwap().

Referenced by OOMatrixInverse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOMatrixLoadGLMatrix()

OOINLINE OOMatrix OOMatrixLoadGLMatrix ( GLenum matrixID)

Definition at line 336 of file OOMatrix.h.

337{
338 OOMatrix m;
339 glGetFloatv(matrixID, OOMatrixValuesForOpenGL(m));
340 return m;
341}

References OOINLINE, and OOMatrixValuesForOpenGL.

◆ OOMatrixMultiply()

OOMatrix OOMatrixMultiply ( OOMatrix a,
OOMatrix b )

Definition at line 105 of file OOMatrix.m.

106{
107 unsigned i = 0;
108 OOMatrix r;
109
110 // This is amenable to significant optimization with Altivec, and presumably also SSE.
111 for (i = 0; i != 4; ++i) {
112 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];
113 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];
114 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];
115 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];
116 }
117
118 return r;
119}

References OOMatrix::m.

Referenced by Universe::drawUniverse, OOOpenGLMatrixManager::getMatrix:, OOOpenGLMatrixManager::multModelView:, OOOpenGLMatrixManager::multProjection:, OOMatrixRotate(), OOMatrixRotateQuaternion(), OOMatrixRotateX(), OOMatrixRotateY(), OOMatrixRotateZ(), and OOMatrixScale().

Here is the caller graph for this function:

◆ OOMatrixOrthogonalize()

OOMatrix OOMatrixOrthogonalize ( OOMatrix m)

Definition at line 150 of file OOMatrix.m.

151{
152 // Simple orthogonalization: make everything orthogonal to everything else.
153
154 Vector i; // = { m.m[0][0], m.m[1][0], m.m[2][0] }; // Overwritten without being used
155 Vector j = { m.m[0][1], m.m[1][1], m.m[2][1] };
156 Vector k = { m.m[0][2], m.m[1][2], m.m[2][2] };
157
158 k = vector_normal(k);
159 i = vector_normal(cross_product(j, k));
160 j = cross_product(k, i);
161
162 m.m[0][0] = i.x;
163 m.m[1][0] = i.y;
164 m.m[2][0] = i.z;
165 m.m[0][1] = j.x;
166 m.m[1][1] = j.y;
167 m.m[2][1] = j.z;
168 m.m[0][2] = k.x;
169 m.m[1][2] = k.y;
170 m.m[2][2] = k.z;
171
172 return m;
173}

References cross_product(), OOMatrix::m, vector_normal(), Vector::x, Vector::y, and Vector::z.

Here is the call graph for this function:

◆ OOMatrixRightTransform()

OOMatrix OOMatrixRightTransform ( OOMatrix A,
OOMatrix B )

Definition at line 320 of file OOMatrix.m.

321{
322 int i, j;
323 bool found;
324 for (i = 0; i < 4; i++) {
325 if (A.m[i][i] == 0.0) {
326 found = false;
327 for (j = i + 1; j < 4; j++) {
328 if (A.m[j][i] != 0.0) {
329 found = true;
330 OOMatrixRowSwap(&A, i, j);
331 OOMatrixRowSwap(&B, i, j);
332 break;
333 }
334 }
335 if (!found) {
336 return kZeroMatrix;
337 }
338 }
339 OOMatrixRowScale(&B, i, 1 / A.m[i][i]);
340 OOMatrixRowScale(&A, i, 1 / A.m[i][i]);
341 for (j = i + 1; j < 4; j++) {
342 if (A.m[j][i] != 0.0) {
343 OOMatrixRowOperation(&B, j, 1, i, -A.m[j][i]);
344 OOMatrixRowOperation(&A, j, 1, i, -A.m[j][i]);
345 }
346 }
347 }
348 for (i = 3; i > 0; i--) {
349 for (j = 0; j < i; j++) {
350 if (A.m[j][i] != 0.0) {
351 OOMatrixRowOperation(&B, j, 1, i, -A.m[j][i]);
352 OOMatrixRowOperation(&A, j, 1, i, -A.m[j][i]);
353 }
354 }
355 }
356 return B;
357}

References kZeroMatrix, OOMatrix::m, OOMatrixRowOperation(), OOMatrixRowScale(), and OOMatrixRowSwap().

Here is the call graph for this function:

◆ OOMatrixRotate()

OOINLINE OOMatrix OOMatrixRotate ( OOMatrix m,
Vector axis,
OOScalar angle )

Definition at line 303 of file OOMatrix.h.

304{
305 return OOMatrixMultiply(m, OOMatrixForRotation(axis, angle));
306}
OOMatrix OOMatrixForRotation(Vector axis, OOScalar angle) CONST_FUNC
Definition OOMatrix.m:40
OOMatrix OOMatrixMultiply(OOMatrix a, OOMatrix b) CONST_FUNC
Definition OOMatrix.m:105

References OOINLINE, OOMatrixForRotation(), and OOMatrixMultiply().

Here is the call graph for this function:

◆ OOMatrixRotateQuaternion()

OOINLINE OOMatrix OOMatrixRotateQuaternion ( OOMatrix m,
Quaternion quat )

Definition at line 308 of file OOMatrix.h.

309{
311}

References OOINLINE, OOMatrixForQuaternionRotation(), and OOMatrixMultiply().

Here is the call graph for this function:

◆ OOMatrixRotateX()

OOINLINE OOMatrix OOMatrixRotateX ( OOMatrix m,
OOScalar angle )

Definition at line 288 of file OOMatrix.h.

289{
290 return OOMatrixMultiply(m, OOMatrixForRotationX(angle));
291}
OOINLINE OOMatrix OOMatrixForRotationX(OOScalar angle) INLINE_CONST_FUNC
Definition OOMatrix.h:191

References OOINLINE, OOMatrixForRotationX(), and OOMatrixMultiply().

Here is the call graph for this function:

◆ OOMatrixRotateY()

OOINLINE OOMatrix OOMatrixRotateY ( OOMatrix m,
OOScalar angle )

Definition at line 293 of file OOMatrix.h.

294{
295 return OOMatrixMultiply(m, OOMatrixForRotationY(angle));
296}
OOINLINE OOMatrix OOMatrixForRotationY(OOScalar angle) INLINE_CONST_FUNC
Definition OOMatrix.h:205

References OOINLINE, OOMatrixForRotationY(), and OOMatrixMultiply().

Here is the call graph for this function:

◆ OOMatrixRotateZ()

OOINLINE OOMatrix OOMatrixRotateZ ( OOMatrix m,
OOScalar angle )

Definition at line 298 of file OOMatrix.h.

299{
300 return OOMatrixMultiply(m, OOMatrixForRotationZ(angle));
301}
OOINLINE OOMatrix OOMatrixForRotationZ(OOScalar angle) INLINE_CONST_FUNC
Definition OOMatrix.h:219

References OOINLINE, OOMatrixForRotationZ(), and OOMatrixMultiply().

Here is the call graph for this function:

◆ OOMatrixRowOperation()

void OOMatrixRowOperation ( OOMatrix * M,
int row1,
OOScalar factor1,
int row2,
OOScalar factor2 )

Definition at line 234 of file OOMatrix.m.

235{
236 if (row1 < 0 || row1 >= 4 || row2 < 0 || row2 >= 4) {
237 return;
238 }
239 int i;
240 for (i = 0; i < 4; i++) {
241 M->m[row1][i] = factor1 * M->m[row1][i] + factor2 * M->m[row2][i];
242 }
243 return;
244}

References OOMatrix::m.

Referenced by OOMatrixInverseWithDeterminant(), and OOMatrixRightTransform().

Here is the caller graph for this function:

◆ OOMatrixRowScale()

void OOMatrixRowScale ( OOMatrix * m,
int row,
OOScalar factor )

Definition at line 222 of file OOMatrix.m.

223{
224 if (row < 0 || row >= 4) {
225 return;
226 }
227 int i;
228 for (i = 0; i < 4; i++) {
229 M->m[row][i] *= factor;
230 }
231 return;
232}

References OOMatrix::m.

Referenced by OOMatrixInverseWithDeterminant(), and OOMatrixRightTransform().

Here is the caller graph for this function:

◆ OOMatrixRowSwap()

void OOMatrixRowSwap ( OOMatrix * M,
int row1,
int row2 )

Definition at line 207 of file OOMatrix.m.

208{
209 if (row1 < 0 || row1 >= 4 || row2 < 0 || row2 >= 4 || row1 == row2) {
210 return;
211 }
212 float x;
213 int i;
214 for (i = 0; i < 4; i++) {
215 x = M->m[row1][i];
216 M->m[row1][i] = M->m[row2][i];
217 M->m[row2][i] = x;
218 }
219 return;
220}

References OOMatrix::m, and x.

Referenced by OOMatrixInverseWithDeterminant(), and OOMatrixRightTransform().

Here is the caller graph for this function:

◆ OOMatrixScale()

OOINLINE OOMatrix OOMatrixScale ( OOMatrix m,
OOScalar sx,
OOScalar sy,
OOScalar sz )

Definition at line 278 of file OOMatrix.h.

279{
280 return OOMatrixMultiply(m, OOMatrixForScale(sx, sy, sz));
281}

References OOINLINE, OOMatrixForScale(), and OOMatrixMultiply().

Referenced by OOMatrixScaleUniform().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOMatrixScaleUniform()

OOINLINE OOMatrix OOMatrixScaleUniform ( OOMatrix m,
OOScalar s )

Definition at line 283 of file OOMatrix.h.

284{
285 return OOMatrixScale(m, s, s, s);
286}
OOINLINE OOMatrix OOMatrixScale(OOMatrix m, OOScalar sx, OOScalar sy, OOScalar sz) INLINE_CONST_FUNC
Definition OOMatrix.h:278

References OOINLINE, and OOMatrixScale().

Here is the call graph for this function:

◆ OOMatrixTranslate()

OOINLINE OOMatrix OOMatrixTranslate ( OOMatrix m,
Vector offset )

Definition at line 254 of file OOMatrix.h.

255{
257}

References OOINLINE, and OOMatrixTranslateComponents().

Referenced by PlayerEntity::drawTransformationMatrix, and OOMatrixFromOrientationAndPosition().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOMatrixTranslateComponents()

OOINLINE OOMatrix OOMatrixTranslateComponents ( OOMatrix m,
OOScalar dx,
OOScalar dy,
OOScalar dz )

Definition at line 246 of file OOMatrix.h.

247{
248 m.m[3][0] += dx;
249 m.m[3][1] += dy;
250 m.m[3][2] += dz;
251 return m;
252}

References OOMatrix::m, and OOINLINE.

Referenced by OOMatrixHPTranslate(), and OOMatrixTranslate().

Here is the caller graph for this function:

◆ OOMatrixTranspose()

OOINLINE OOMatrix OOMatrixTranspose ( OOMatrix m)

Definition at line 327 of file OOMatrix.h.

328{
329 return OOMatrixConstruct(
330 m.m[0][0], m.m[1][0], m.m[2][0], m.m[3][0],
331 m.m[0][1], m.m[1][1], m.m[2][1], m.m[3][1],
332 m.m[0][2], m.m[1][2], m.m[2][2], m.m[3][2],
333 m.m[0][3], m.m[1][3], m.m[2][3], m.m[3][3]);
334}

References OOMatrix::m, OOINLINE, and OOMatrixConstruct().

Referenced by OOOpenGLMatrixManager::getMatrix:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOVectorMultiplyMatrix()

Vector OOVectorMultiplyMatrix ( Vector v,
OOMatrix m )

Definition at line 121 of file OOMatrix.m.

122{
123 OOScalar x, y, z, w;
124
125 x = m.m[0][0] * v.x + m.m[1][0] * v.y + m.m[2][0] * v.z + m.m[3][0];
126 y = m.m[0][1] * v.x + m.m[1][1] * v.y + m.m[2][1] * v.z + m.m[3][1];
127 z = m.m[0][2] * v.x + m.m[1][2] * v.y + m.m[2][2] * v.z + m.m[3][2];
128 w = m.m[0][3] * v.x + m.m[1][3] * v.y + m.m[2][3] * v.z + m.m[3][3];
129
130 w = 1.0f / w;
131 return make_vector(x * w, y * w, z * w);
132}

References OOMatrix::m, make_vector(), Vector::x, x, Vector::y, y, and Vector::z.

Referenced by ShipEntity::absoluteIJKForSubentity, HeadUpDisplay(Private)::drawCompass:, HeadUpDisplay(Private)::drawDirectionCue:, HeadUpDisplay(Private)::drawScanner:, OOMesh::findSubentityBoundingBoxWithPosition:rotMatrix:, ShipEntity::fireTurretCannon:, Universe::firstEntityTargetedByPlayer, and Universe::firstShipHitByLaserFromShip:inDirection:offset:gettingRangeFound:.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ kIdentityMatrix

◆ kZeroMatrix

const OOMatrix kZeroMatrix
extern

Definition at line 33 of file OOMatrix.m.

33 { .m = {
34 { 0.0f, 0.0f, 0.0f, 0.0f },
35 { 0.0f, 0.0f, 0.0f, 0.0f },
36 { 0.0f, 0.0f, 0.0f, 0.0f },
37 { 0.0f, 0.0f, 0.0f, 0.0f },
38 } };

Referenced by OOMesh::init, OOMatrixInverseWithDeterminant(), OOMatrixLeftTransform(), and OOMatrixRightTransform().