]> git.mxchange.org Git - simgear.git/commitdiff
Improvements to take advantage of memory portability changes.
authorcurt <curt>
Mon, 7 Dec 1998 21:09:52 +0000 (21:09 +0000)
committercurt <curt>
Mon, 7 Dec 1998 21:09:52 +0000 (21:09 +0000)
Math/MAT3mat.c
Math/mat3.h

index 9a1e7c9911641fa46baa2cf29e4097a5490e369d..4355f176904b28fc90b04c9fe4a3f6923553ef70 100644 (file)
 #include <string.h>
 #include <Math/mat3defs.h>
 
 #include <string.h>
 #include <Math/mat3defs.h>
 
-#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" */
 
 
 /* #include "macros.h" */
 
 
 #if !defined( USE_XTRA_MAT3_INLINES )
 
 
 #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.
 /*
  * This multiplies two matrices, producing a third, which may the same as
  * either of the first two.
index 0090b0cc4ec6e55f2542fc10aed1a877aeb69017..e11896ce158d091f1445b08f5c5a515582535c8e 100644 (file)
@@ -19,6 +19,7 @@
 #include <stdio.h>
 
 #include <string.h>
 #include <stdio.h>
 
 #include <string.h>
+#include "Include/fg_memory.h"
 
 #ifdef __cplusplus                                                          
 extern "C" {                            
 
 #ifdef __cplusplus                                                          
 extern "C" {                            
@@ -34,7 +35,6 @@ extern "C" {
 #  define  MAT3_PI    3.14159265358979323846
 #endif
 
 #  define  MAT3_PI    3.14159265358979323846
 #endif
 
-
 #define USE_XTRA_MAT3_INLINES
 
 /* ------------------------------  Types  --------------------------------- */
 #define USE_XTRA_MAT3_INLINES
 
 /* ------------------------------  Types  --------------------------------- */
@@ -45,6 +45,8 @@ typedef double MAT3hvec[4];             /* Vector with homogeneous coord */
 
 /* ------------------------------  Macros  -------------------------------- */
 
 
 /* ------------------------------  Macros  -------------------------------- */
 
+extern MAT3mat identityMatrix;
+
 /* Tests if a number is within EPSILON of zero */
 #define MAT3_IS_ZERO(N)        ((N) < MAT3_EPSILON && (N) > -MAT3_EPSILON)
 
 /* 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  ------------------------------- */
 
 
 /* ------------------------------  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 )
 
 
 #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]; \
    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]; \
 }
 
    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]; \
    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]; \
 } 
 
    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++) \
    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 */
 
 #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 )
 
 
 #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);
 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);
 /* 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
 }
 
 #ifdef __cplusplus
 }