diff --git a/Math/MAT3mat.c b/Math/MAT3mat.c index 9a1e7c991..4355f1769 100644 --- a/Math/MAT3mat.c +++ b/Math/MAT3mat.c @@ -19,7 +19,12 @@ #include #include -#define USE_MEM +MAT3mat identityMatrix = { + { 1.0, 0.0, 0.0, 0.0 }, + { 0.0, 1.0, 0.0, 0.0 }, + { 0.0, 0.0, 1.0, 0.0 }, + { 0.0, 0.0, 0.0, 1.0 } +}; /* #include "macros.h" */ @@ -32,54 +37,6 @@ #if !defined( USE_XTRA_MAT3_INLINES ) -/* - * Sets a matrix to identity. - */ - -void -MAT3identity (register MAT3mat mat) -{ - register int i; - -#ifdef USE_MEM /* WIN32 */ - memset(mat, 0x00, sizeof(MAT3mat)); -#else - bzero (mat, sizeof(MAT3mat)); -#endif - - for (i = 0; i < 4; i++) - mat[i][i] = 1.0; -} - -/* - * Sets a matrix to zero. - */ - -void -MAT3zero (MAT3mat mat) -{ -#ifdef USE_MEM /* WIN32 */ - memset(mat,0x00, sizeof(MAT3mat)); -#else - bzero (mat, sizeof(MAT3mat)); -#endif -} - - -/* - * Copies one matrix to another. - */ - -void -MAT3copy(MAT3mat to, MAT3mat from) -{ -#ifdef USE_MEM /* WIN32 */ - memcpy(to, from, sizeof(MAT3mat)); -#else - bcopy(from, to, sizeof(MAT3mat)); -#endif -} - /* * This multiplies two matrices, producing a third, which may the same as * either of the first two. diff --git a/Math/mat3.h b/Math/mat3.h index 0090b0cc4..e11896ce1 100644 --- a/Math/mat3.h +++ b/Math/mat3.h @@ -19,6 +19,7 @@ #include #include +#include "Include/fg_memory.h" #ifdef __cplusplus extern "C" { @@ -34,7 +35,6 @@ extern "C" { # define MAT3_PI 3.14159265358979323846 #endif - #define USE_XTRA_MAT3_INLINES /* ------------------------------ Types --------------------------------- */ @@ -45,6 +45,8 @@ typedef double MAT3hvec[4]; /* Vector with homogeneous coord */ /* ------------------------------ Macros -------------------------------- */ +extern MAT3mat identityMatrix; + /* Tests if a number is within EPSILON of zero */ #define MAT3_IS_ZERO(N) ((N) < MAT3_EPSILON && (N) > -MAT3_EPSILON) @@ -127,17 +129,13 @@ typedef double MAT3hvec[4]; /* Vector with homogeneous coord */ /* ------------------------------ Entries ------------------------------- */ -/* In MAT3geom.c */ -void MAT3direction_matrix (MAT3mat result_mat, MAT3mat mat); -int MAT3normal_matrix (MAT3mat result_mat, MAT3mat mat); -void MAT3rotate (MAT3mat result_mat, MAT3vec axis, double angle_in_radians); -void MAT3translate (MAT3mat result_mat, MAT3vec trans); -void MAT3scale (MAT3mat result_mat, MAT3vec scale); -void MAT3shear(MAT3mat result_mat, double xshear, double yshear); +#define MAT3identity(mat) fgmemcpy( mat, identityMatrix, sizeof(MAT3mat) ) +#define MAT3zero(mat) fgmemzero( mat, sizeof(MAT3mat) ) +#define MAT3copy(to, from) fgmemcpy( to, from, sizeof(MAT3mat) ) #if defined( USE_XTRA_MAT3_INLINES ) -#define MAT3mult_vec( result_vec, vec, mat) { \ +# define MAT3mult_vec( result_vec, vec, mat) { \ MAT3vec tempvec; \ tempvec[0]=vec[0]*mat[0][0]+vec[1]*mat[1][0]+vec[2]*mat[2][0]+mat[3][0]; \ tempvec[1]=vec[0]*mat[0][1]+vec[1]*mat[1][1]+vec[2]*mat[2][1]+mat[3][1]; \ @@ -147,7 +145,7 @@ void MAT3shear(MAT3mat result_mat, double xshear, double yshear); result_vec[2] = tempvec[2]; \ } -#define MAT3cross_product(result_vec, vec1, vec2) { \ +# define MAT3cross_product(result_vec, vec1, vec2) { \ MAT3vec tempvec; \ tempvec[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1]; \ tempvec[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2]; \ @@ -157,55 +155,35 @@ void MAT3shear(MAT3mat result_mat, double xshear, double yshear); result_vec[2] = tempvec[2]; \ } -#if defined( USE_MEM ) || defined( WIN32 ) -#define MAT3copy( to, from) memcpy(to, from, sizeof(MAT3mat)) -#define MAT3zero(mat) memset(mat,0x00, sizeof(MAT3mat)) -#define MAT3mult( result_mat, mat1, mat2) { \ +# define MAT3mult( result_mat, mat1, mat2) { \ register int i, j; \ MAT3mat tmp_mat; \ for (i = 0; i < 4; i++) \ for (j = 0; j < 4; j++) \ - tmp_mat[i][j] = (mat1[i][0] * mat2[0][j] + mat1[i][1] * mat2[1][j] \ - + mat1[i][2] * mat2[2][j] + mat1[i][3] * mat2[3][j]); \ - memcpy(result_mat, tmp_mat, sizeof(MAT3mat)); \ + tmp_mat[i][j] = (mat1[i][0] * mat2[0][j] + \ + mat1[i][1] * mat2[1][j] + \ + mat1[i][2] * mat2[2][j] + \ + mat1[i][3] * mat2[3][j]); \ + fgmemcpy(result_mat, tmp_mat, sizeof(MAT3mat)); \ } -#define MAT3identity(mat) { \ - register int i; \ - memset(mat, 0x00, sizeof(MAT3mat)); \ - for (i = 0; i < 4; i++) mat[i][i] = 1.0; \ -} - -#else // !defined( USE_MEM ) || !defined( WIN32 ) - -#define MAT3copy( to, from) bcopy(from, to, sizeof(MAT3mat)) -#define MAT3zero(mat) bzero (mat, sizeof(MAT3mat)) -#define MAT3mult( result_mat, mat1, mat2) { \ - register int i, j; \ - MAT3mat tmp_mat; \ - for (i = 0; i < 4; i++) \ - for (j = 0; j < 4; j++) \ - tmp_mat[i][j] = (mat1[i][0] * mat2[0][j] + mat1[i][1] * mat2[1][j] \ - + mat1[i][2] * mat2[2][j] + mat1[i][3] * mat2[3][j]); \ - bcopy(tmp_mat, result_mat, sizeof(MAT3mat)); \ -} -#define MAT3identity(mat) { \ - register int i; \ - bzero(mat, sizeof(MAT3mat)); \ - for(i = 0; i < 4; i++) mat[i][i] = 1.0; \ -} -#endif #else // !defined( USE_XTRA_MAT3_INLINES ) /* In MAT3mat.c */ -void MAT3identity(MAT3mat); -void MAT3zero(MAT3mat); - -void MAT3copy (MAT3mat to, MAT3mat from); -void MAT3mult (MAT3mat result, MAT3mat, MAT3mat); +void MAT3mult(MAT3mat result, MAT3mat, MAT3mat); +void MAT3mult_vec(MAT3vec result_vec, MAT3vec vec, MAT3mat mat); +void MAT3cross_product(MAT3vec result,MAT3vec,MAT3vec); #endif // defined( USE_XTRA_MAT3_INLINES ) +/* In MAT3geom.c */ +void MAT3direction_matrix (MAT3mat result_mat, MAT3mat mat); +int MAT3normal_matrix (MAT3mat result_mat, MAT3mat mat); +void MAT3rotate (MAT3mat result_mat, MAT3vec axis, double angle_in_radians); +void MAT3translate (MAT3mat result_mat, MAT3vec trans); +void MAT3scale (MAT3mat result_mat, MAT3vec scale); +void MAT3shear(MAT3mat result_mat, double xshear, double yshear); + void MAT3transpose (MAT3mat result, MAT3mat); int MAT3invert (MAT3mat result, MAT3mat); void MAT3print (MAT3mat, FILE *fp); @@ -220,11 +198,6 @@ int MAT3kernel_basis( void ); /* In MAT3vec.c */ int MAT3mult_hvec (MAT3hvec result_vec, MAT3hvec vec, MAT3mat mat, int normalize); void MAT3perp_vec(MAT3vec result_vec, MAT3vec vec, int is_unit); -#if !defined( USE_XTRA_MAT3_INLINES ) -void MAT3mult_vec(MAT3vec result_vec, MAT3vec vec, MAT3mat mat); -void MAT3cross_product(MAT3vec result,MAT3vec,MAT3vec); -#endif // !defined( USE_XTRA_MAT3_INLINES ) - #ifdef __cplusplus }