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 <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" */
|
||||
|
||||
|
@ -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.
|
||||
|
|
69
Math/mat3.h
69
Math/mat3.h
|
@ -19,6 +19,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include <string.h>
|
||||
#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,13 +129,9 @@ 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 )
|
||||
|
||||
|
@ -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) { \
|
||||
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_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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue