#endif
#include <stdio.h>
+#include <string.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#define MAT3_DET0 -1 /* Indicates singular mat */
#define MAT3_EPSILON 1e-12 /* Close enough to zero */
-#define MAT3_PI 3.141592653589793 /* Pi */
+
+#ifdef M_PI
+# define MAT3_PI M_PI
+#else
+# define MAT3_PI 3.14159265358979323846
+#endif
+
+
+#define USE_XTRA_MAT3_INLINES
/* ------------------------------ Types --------------------------------- */
/* 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 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);
+
+#if defined( USE_XTRA_MAT3_INLINES )
+
+#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]; \
+ tempvec[2]=vec[0]*mat[0][2]+vec[1]*mat[1][2]+vec[2]*mat[2][2]+mat[3][2]; \
+ result_vec[0] = tempvec[0]; \
+ result_vec[1] = tempvec[1]; \
+ result_vec[2] = tempvec[2]; \
+}
+
+#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]; \
+ tempvec[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0]; \
+ result_vec[0] = tempvec[0]; \
+ result_vec[1] = tempvec[1]; \
+ 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) { \
+ 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)); \
+}
+#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 MAT3transpose (MAT3mat result, MAT3mat);
-int MAT3invert (MAT3mat result, MAT3mat);
-void MAT3print (MAT3mat, FILE *fp);
-void MAT3print_formatted (MAT3mat, FILE *fp,
- char *title, char *head, char *format, char *tail);
-extern int MAT3equal();
-extern double MAT3trace();
-extern int MAT3power();
-extern int MAT3column_reduce();
-extern int MAT3kernel_basis();
+void MAT3identity(MAT3mat);
+void MAT3zero(MAT3mat);
+
+void MAT3copy (MAT3mat to, MAT3mat from);
+void MAT3mult (MAT3mat result, MAT3mat, MAT3mat);
+
+#endif // defined( USE_XTRA_MAT3_INLINES )
+
+void MAT3transpose (MAT3mat result, MAT3mat);
+int MAT3invert (MAT3mat result, MAT3mat);
+void MAT3print (MAT3mat, FILE *fp);
+void MAT3print_formatted (MAT3mat, FILE *fp,
+ char *title, char *head, char *format, char *tail);
+int MAT3equal( void );
+double MAT3trace( void );
+int MAT3power( void );
+int MAT3column_reduce( void );
+int MAT3kernel_basis( void );
/* In MAT3vec.c */
-void MAT3mult_vec(MAT3vec result_vec, MAT3vec vec, MAT3mat mat);
-int MAT3mult_hvec (MAT3hvec result_vec, MAT3hvec vec, MAT3mat mat, int normalize);
-void MAT3cross_product(MAT3vec result,MAT3vec,MAT3vec);
-void MAT3perp_vec(MAT3vec result_vec, MAT3vec vec, int is_unit);
+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
+}
+#endif
+
#endif /* MAT3_HAS_BEEN_INCLUDED */