Improvements to take advantage of memory portability changes.
This commit is contained in:
parent
f472bc563d
commit
f12840a72e
2 changed files with 31 additions and 101 deletions
|
@ -19,7 +19,12 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <Math/mat3defs.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" */
|
||||||
|
|
||||||
|
@ -32,54 +37,6 @@
|
||||||
|
|
||||||
#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
|
* This multiplies two matrices, producing a third, which may the same as
|
||||||
* either of the first two.
|
* either of the first two.
|
||||||
|
|
77
Math/mat3.h
77
Math/mat3.h
|
@ -19,6 +19,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "Include/fg_memory.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -34,7 +35,6 @@ extern "C" {
|
||||||
# define MAT3_PI 3.14159265358979323846
|
# define MAT3_PI 3.14159265358979323846
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define USE_XTRA_MAT3_INLINES
|
#define USE_XTRA_MAT3_INLINES
|
||||||
|
|
||||||
/* ------------------------------ Types --------------------------------- */
|
/* ------------------------------ 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 */
|
/* Tests if a number is within EPSILON of zero */
|
||||||
#define MAT3_IS_ZERO(N) ((N) < MAT3_EPSILON && (N) > -MAT3_EPSILON)
|
#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 */
|
#define MAT3identity(mat) fgmemcpy( mat, identityMatrix, sizeof(MAT3mat) )
|
||||||
void MAT3direction_matrix (MAT3mat result_mat, MAT3mat mat);
|
#define MAT3zero(mat) fgmemzero( mat, sizeof(MAT3mat) )
|
||||||
int MAT3normal_matrix (MAT3mat result_mat, MAT3mat mat);
|
#define MAT3copy(to, from) fgmemcpy( to, from, sizeof(MAT3mat) )
|
||||||
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 )
|
#if defined( USE_XTRA_MAT3_INLINES )
|
||||||
|
|
||||||
#define MAT3mult_vec( result_vec, vec, mat) { \
|
# define MAT3mult_vec( result_vec, vec, mat) { \
|
||||||
MAT3vec tempvec; \
|
MAT3vec tempvec; \
|
||||||
tempvec[0]=vec[0]*mat[0][0]+vec[1]*mat[1][0]+vec[2]*mat[2][0]+mat[3][0]; \
|
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[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; \
|
MAT3vec tempvec; \
|
||||||
tempvec[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1]; \
|
tempvec[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1]; \
|
||||||
tempvec[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2]; \
|
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 MAT3mult( result_mat, mat1, mat2) { \
|
||||||
#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; \
|
register int i, j; \
|
||||||
MAT3mat tmp_mat; \
|
MAT3mat tmp_mat; \
|
||||||
for (i = 0; i < 4; i++) \
|
for (i = 0; i < 4; i++) \
|
||||||
for (j = 0; j < 4; j++) \
|
for (j = 0; j < 4; j++) \
|
||||||
tmp_mat[i][j] = (mat1[i][0] * mat2[0][j] + mat1[i][1] * mat2[1][j] \
|
tmp_mat[i][j] = (mat1[i][0] * mat2[0][j] + \
|
||||||
+ mat1[i][2] * mat2[2][j] + mat1[i][3] * mat2[3][j]); \
|
mat1[i][1] * mat2[1][j] + \
|
||||||
memcpy(result_mat, tmp_mat, sizeof(MAT3mat)); \
|
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 )
|
#else // !defined( USE_XTRA_MAT3_INLINES )
|
||||||
|
|
||||||
/* In MAT3mat.c */
|
/* In MAT3mat.c */
|
||||||
void MAT3identity(MAT3mat);
|
void MAT3mult(MAT3mat result, MAT3mat, MAT3mat);
|
||||||
void MAT3zero(MAT3mat);
|
void MAT3mult_vec(MAT3vec result_vec, MAT3vec vec, MAT3mat mat);
|
||||||
|
void MAT3cross_product(MAT3vec result,MAT3vec,MAT3vec);
|
||||||
void MAT3copy (MAT3mat to, MAT3mat from);
|
|
||||||
void MAT3mult (MAT3mat result, MAT3mat, MAT3mat);
|
|
||||||
|
|
||||||
#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);
|
void MAT3transpose (MAT3mat result, MAT3mat);
|
||||||
int MAT3invert (MAT3mat result, MAT3mat);
|
int MAT3invert (MAT3mat result, MAT3mat);
|
||||||
void MAT3print (MAT3mat, FILE *fp);
|
void MAT3print (MAT3mat, FILE *fp);
|
||||||
|
@ -220,11 +198,6 @@ int MAT3kernel_basis( void );
|
||||||
/* In MAT3vec.c */
|
/* In MAT3vec.c */
|
||||||
int MAT3mult_hvec (MAT3hvec result_vec, MAT3hvec vec, MAT3mat mat, int normalize);
|
int MAT3mult_hvec (MAT3hvec result_vec, MAT3hvec vec, MAT3mat mat, int normalize);
|
||||||
void MAT3perp_vec(MAT3vec result_vec, MAT3vec vec, int is_unit);
|
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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue