From f40047a4c83d9d5cd57c731c101296131e509332 Mon Sep 17 00:00:00 2001 From: havoc Date: Tue, 22 Sep 2009 20:16:13 +0000 Subject: [PATCH] added float GL/D3D array conversions git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9218 d7cf8633-e32d-0410-b094-e92efae38249 --- matrixlib.c | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++ matrixlib.h | 9 +++ 2 files changed, 165 insertions(+) diff --git a/matrixlib.c b/matrixlib.c index a0bf9c96..505f7d6e 100644 --- a/matrixlib.c +++ b/matrixlib.c @@ -1004,6 +1004,162 @@ void Matrix4x4_FromArrayDoubleD3D (matrix4x4_t *out, const double in[16]) #endif } +void Matrix4x4_ToArrayFloatGL(const matrix4x4_t *in, float out[16]) +{ +#ifdef MATRIX4x4_OPENGLORIENTATION + out[ 0] = in->m[0][0]; + out[ 1] = in->m[0][1]; + out[ 2] = in->m[0][2]; + out[ 3] = in->m[0][3]; + out[ 4] = in->m[1][0]; + out[ 5] = in->m[1][1]; + out[ 6] = in->m[1][2]; + out[ 7] = in->m[1][3]; + out[ 8] = in->m[2][0]; + out[ 9] = in->m[2][1]; + out[10] = in->m[2][2]; + out[11] = in->m[2][3]; + out[12] = in->m[3][0]; + out[13] = in->m[3][1]; + out[14] = in->m[3][2]; + out[15] = in->m[3][3]; +#else + out[ 0] = in->m[0][0]; + out[ 1] = in->m[1][0]; + out[ 2] = in->m[2][0]; + out[ 3] = in->m[3][0]; + out[ 4] = in->m[0][1]; + out[ 5] = in->m[1][1]; + out[ 6] = in->m[2][1]; + out[ 7] = in->m[3][1]; + out[ 8] = in->m[0][2]; + out[ 9] = in->m[1][2]; + out[10] = in->m[2][2]; + out[11] = in->m[3][2]; + out[12] = in->m[0][3]; + out[13] = in->m[1][3]; + out[14] = in->m[2][3]; + out[15] = in->m[3][3]; +#endif +} + +void Matrix4x4_FromArrayFloatGL (matrix4x4_t *out, const float in[16]) +{ +#ifdef MATRIX4x4_OPENGLORIENTATION + out->m[0][0] = in[0]; + out->m[0][1] = in[1]; + out->m[0][2] = in[2]; + out->m[0][3] = in[3]; + out->m[1][0] = in[4]; + out->m[1][1] = in[5]; + out->m[1][2] = in[6]; + out->m[1][3] = in[7]; + out->m[2][0] = in[8]; + out->m[2][1] = in[9]; + out->m[2][2] = in[10]; + out->m[2][3] = in[11]; + out->m[3][0] = in[12]; + out->m[3][1] = in[13]; + out->m[3][2] = in[14]; + out->m[3][3] = in[15]; +#else + out->m[0][0] = in[0]; + out->m[1][0] = in[1]; + out->m[2][0] = in[2]; + out->m[3][0] = in[3]; + out->m[0][1] = in[4]; + out->m[1][1] = in[5]; + out->m[2][1] = in[6]; + out->m[3][1] = in[7]; + out->m[0][2] = in[8]; + out->m[1][2] = in[9]; + out->m[2][2] = in[10]; + out->m[3][2] = in[11]; + out->m[0][3] = in[12]; + out->m[1][3] = in[13]; + out->m[2][3] = in[14]; + out->m[3][3] = in[15]; +#endif +} + +void Matrix4x4_ToArrayFloatD3D(const matrix4x4_t *in, float out[16]) +{ +#ifdef MATRIX4x4_OPENGLORIENTATION + out[ 0] = in->m[0][0]; + out[ 1] = in->m[1][0]; + out[ 2] = in->m[2][0]; + out[ 3] = in->m[3][0]; + out[ 4] = in->m[0][1]; + out[ 5] = in->m[1][1]; + out[ 6] = in->m[2][1]; + out[ 7] = in->m[3][1]; + out[ 8] = in->m[0][2]; + out[ 9] = in->m[1][2]; + out[10] = in->m[2][2]; + out[11] = in->m[3][2]; + out[12] = in->m[0][3]; + out[13] = in->m[1][3]; + out[14] = in->m[2][3]; + out[15] = in->m[3][3]; +#else + out[ 0] = in->m[0][0]; + out[ 1] = in->m[0][1]; + out[ 2] = in->m[0][2]; + out[ 3] = in->m[0][3]; + out[ 4] = in->m[1][0]; + out[ 5] = in->m[1][1]; + out[ 6] = in->m[1][2]; + out[ 7] = in->m[1][3]; + out[ 8] = in->m[2][0]; + out[ 9] = in->m[2][1]; + out[10] = in->m[2][2]; + out[11] = in->m[2][3]; + out[12] = in->m[3][0]; + out[13] = in->m[3][1]; + out[14] = in->m[3][2]; + out[15] = in->m[3][3]; +#endif +} + +void Matrix4x4_FromArrayFloatD3D (matrix4x4_t *out, const float in[16]) +{ +#ifdef MATRIX4x4_OPENGLORIENTATION + out->m[0][0] = in[0]; + out->m[1][0] = in[1]; + out->m[2][0] = in[2]; + out->m[3][0] = in[3]; + out->m[0][1] = in[4]; + out->m[1][1] = in[5]; + out->m[2][1] = in[6]; + out->m[3][1] = in[7]; + out->m[0][2] = in[8]; + out->m[1][2] = in[9]; + out->m[2][2] = in[10]; + out->m[3][2] = in[11]; + out->m[0][3] = in[12]; + out->m[1][3] = in[13]; + out->m[2][3] = in[14]; + out->m[3][3] = in[15]; +#else + out->m[0][0] = in[0]; + out->m[0][1] = in[1]; + out->m[0][2] = in[2]; + out->m[0][3] = in[3]; + out->m[1][0] = in[4]; + out->m[1][1] = in[5]; + out->m[1][2] = in[6]; + out->m[1][3] = in[7]; + out->m[2][0] = in[8]; + out->m[2][1] = in[9]; + out->m[2][2] = in[10]; + out->m[2][3] = in[11]; + out->m[3][0] = in[12]; + out->m[3][1] = in[13]; + out->m[3][2] = in[14]; + out->m[3][3] = in[15]; +#endif +} + void Matrix4x4_ToArray12FloatGL(const matrix4x4_t *in, float out[12]) { #ifdef MATRIX4x4_OPENGLORIENTATION diff --git a/matrixlib.h b/matrixlib.h index 505f7f91..8d7c3a6c 100644 --- a/matrixlib.h +++ b/matrixlib.h @@ -95,6 +95,15 @@ void Matrix4x4_ToArrayDoubleD3D(const matrix4x4_t *in, double out[16]); // creates a matrix4x4 from a double[16] array in the Direct3D orientation void Matrix4x4_FromArrayDoubleD3D(matrix4x4_t *out, const double in[16]); +// converts a matrix4x4 to a float[16] array in the OpenGL orientation +void Matrix4x4_ToArrayFloatGL(const matrix4x4_t *in, float out[16]); +// creates a matrix4x4 from a float[16] array in the OpenGL orientation +void Matrix4x4_FromArrayFloatGL(matrix4x4_t *out, const float in[16]); +// converts a matrix4x4 to a float[16] array in the Direct3D orientation +void Matrix4x4_ToArrayFloatD3D(const matrix4x4_t *in, float out[16]); +// creates a matrix4x4 from a float[16] array in the Direct3D orientation +void Matrix4x4_FromArrayFloatD3D(matrix4x4_t *out, const float in[16]); + // converts a matrix4x4 to a float[12] array in the OpenGL orientation void Matrix4x4_ToArray12FloatGL(const matrix4x4_t *in, float out[12]); // creates a matrix4x4 from a float[12] array in the OpenGL orientation -- 2.39.2