diff --git a/src/c/matrix.c b/src/c/matrix.c index 8cfb9aa..7a5ac6c 100644 --- a/src/c/matrix.c +++ b/src/c/matrix.c @@ -8,6 +8,7 @@ extern inline void Mtx_Identity(float m[16]); extern inline void Mtx_Translation(float m[16], float x, float y, float z); +extern inline void Mtx_Scaled(float m[16], float x, float y, float z); static void MakeRotation(float m[9], float c, float s, float x, float y, float z) { @@ -109,6 +110,19 @@ void Mtx_Translate(float m[16], float x, float y, float z) m[15] += x * m[3] + y * m[7] + z * m[11]; } +void Mtx_Scale(float m[16], float x, float y, float z) +{ + /* + m = { [x 0 0 0] + [0 y 0 0] + [0 0 z 0] + [0 0 0 1] } * m + */ + m[0] *= x; m[1] *= x; m[2] *= x; m[3] *= x; + m[4] *= y; m[5] *= y; m[6] *= y; m[7] *= y; + m[8] *= z; m[9] *= z; m[10] *= z; m[11] *= z; +} + void Mtx_Rotate(float m[16], float angle, float x, float y, float z) { // Set up temporaries diff --git a/src/c/matrix.h b/src/c/matrix.h index 71b70c7..bfdf2e9 100644 --- a/src/c/matrix.h +++ b/src/c/matrix.h @@ -25,12 +25,24 @@ inline void Mtx_Translation(float m[16], float x, float y, float z) }, sizeof(float) * 16); } +inline void Mtx_Scaled(float m[16], float x, float y, float z) +{ + SDL_memcpy(m, (float[]) + { + x, 0, 0, 0, + 0, y, 0, 0, + 0, 0, z, 0, + 0, 0, 0, 1 + }, sizeof(float) * 16); +} + void Mtx_Rotation(float m[16], float angle, float x, float y, float z); void Mtx_Perspective(float m[16], float fovy, float aspect, float near, float far); void Mtx_Multiply(float m[16], const float l[16], const float r[16]); void Mtx_Translate(float m[16], float x, float y, float z); +void Mtx_Scale(float m[16], float x, float y, float z); void Mtx_Rotate(float m[16], float angle, float x, float y, float z); #endif//MATRIX_H