From e79d9bdd1a6aa6d6d9852bf5a380a8cd01cbc315 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 17 Nov 2018 23:21:37 -0800 Subject: Move the vector and matrix declarations to a separate header --- common/vecmat.cpp | 12 ++++++++++++ common/vecmat.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 common/vecmat.cpp create mode 100644 common/vecmat.h (limited to 'common') diff --git a/common/vecmat.cpp b/common/vecmat.cpp new file mode 100644 index 00000000..ccb9ad9f --- /dev/null +++ b/common/vecmat.cpp @@ -0,0 +1,12 @@ + +#include "config.h" + +#include "vecmat.h" + + +const aluMatrixf aluMatrixf::Identity{{ + { 1.0f, 0.0f, 0.0f, 0.0f }, + { 0.0f, 1.0f, 0.0f, 0.0f }, + { 0.0f, 0.0f, 1.0f, 0.0f }, + { 0.0f, 0.0f, 0.0f, 1.0f }, +}}; diff --git a/common/vecmat.h b/common/vecmat.h new file mode 100644 index 00000000..0a60cb9e --- /dev/null +++ b/common/vecmat.h @@ -0,0 +1,46 @@ +#ifndef COMMON_VECMAT_H +#define COMMON_VECMAT_H + +#include "AL/al.h" + + +struct aluVector { + alignas(16) ALfloat v[4]; +}; + +inline void aluVectorSet(aluVector *vector, ALfloat x, ALfloat y, ALfloat z, ALfloat w) +{ + vector->v[0] = x; + vector->v[1] = y; + vector->v[2] = z; + vector->v[3] = w; +} + + +struct aluMatrixf { + alignas(16) ALfloat m[4][4]; + + static const aluMatrixf Identity; +}; + +inline void aluMatrixfSetRow(aluMatrixf *matrix, ALuint row, + ALfloat m0, ALfloat m1, ALfloat m2, ALfloat m3) +{ + matrix->m[row][0] = m0; + matrix->m[row][1] = m1; + matrix->m[row][2] = m2; + matrix->m[row][3] = m3; +} + +inline void aluMatrixfSet(aluMatrixf *matrix, ALfloat m00, ALfloat m01, ALfloat m02, ALfloat m03, + ALfloat m10, ALfloat m11, ALfloat m12, ALfloat m13, + ALfloat m20, ALfloat m21, ALfloat m22, ALfloat m23, + ALfloat m30, ALfloat m31, ALfloat m32, ALfloat m33) +{ + aluMatrixfSetRow(matrix, 0, m00, m01, m02, m03); + aluMatrixfSetRow(matrix, 1, m10, m11, m12, m13); + aluMatrixfSetRow(matrix, 2, m20, m21, m22, m23); + aluMatrixfSetRow(matrix, 3, m30, m31, m32, m33); +} + +#endif /* COMMON_VECMAT_H */ -- cgit v1.2.3