From a4cf0b14abb17c313243d0fb84555aec2cef61a0 Mon Sep 17 00:00:00 2001 From: Mike Turvey Date: Tue, 7 Feb 2017 00:11:39 -0700 Subject: Merging math libraries --- redist/linmath.h | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) (limited to 'redist/linmath.h') diff --git a/redist/linmath.h b/redist/linmath.h index 5cc7b7d..530d291 100644 --- a/redist/linmath.h +++ b/redist/linmath.h @@ -10,14 +10,37 @@ #define PFTHREE(x) x[0], x[1], x[2] #define PFFOUR(x) x[0], x[1], x[2], x[3] -#define LINMATHPI 3.141592653589 +#define LINMATHPI ((FLT)3.141592653589) + +//uncomment the following line to use double precision instead of single precision. +//#define USE_DOUBLE + +#ifdef USE_DOUBLE + +#define FLT double +#define FLT_SQRT sqrt +#define FLT_SIN sin +#define FLT_COS cos +#define FLT_ACOS acos +#define FLT_ASIN asin +#define FLT_ATAN2 atan2 +#define FLT_FABS fabs + +#else -//If you want, you can define FLT to be double for double precision. -#ifndef FLT #define FLT float +#define FLT_SQRT sqrtf +#define FLT_SIN sinf +#define FLT_COS cosf +#define FLT_ACOS acosf +#define FLT_ASIN asinf +#define FLT_ATAN2 atan2f +#define FLT_FABS fabsf + #endif + //NOTE: Inputs may never be output with cross product. void cross3d( FLT * out, const FLT * a, const FLT * b ); @@ -64,6 +87,25 @@ void quatoddproduct( FLT * outvec3, FLT * qa, FLT * qb ); void quatslerp( FLT * q, const FLT * qa, const FLT * qb, FLT t ); void quatrotatevector( FLT * vec3out, const FLT * quat, const FLT * vec3in ); +// Matrix Stuff + +typedef struct +{ + // row, column, (0,0) in upper left + FLT val[3][3]; +} Matrix3x3; + +Matrix3x3 inverseM33(const Matrix3x3 mat); +void get_orthogonal_vector(FLT out[3], const FLT in[3]); +void rotation_between_vecs_to_mat3(FLT m[3][3], const FLT v1[3], const FLT v2[3]); +void unit_m3(FLT m[3][3]); +FLT normalize_v3(FLT n[3]); +void axis_angle_normalized_to_mat3_ex( + FLT mat[3][3], + const FLT axis[3], + const FLT angle_sin, + const FLT angle_cos); + #endif -- cgit v1.2.3 From 0586f134e02938e1a9dd86ad92e41c2b2443fee0 Mon Sep 17 00:00:00 2001 From: mwturvey Date: Tue, 7 Feb 2017 17:43:12 -0700 Subject: Replacing rotation matrix (wip) --- redist/linmath.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'redist/linmath.h') diff --git a/redist/linmath.h b/redist/linmath.h index 530d291..3b11c1b 100644 --- a/redist/linmath.h +++ b/redist/linmath.h @@ -59,7 +59,7 @@ int compare3d( const FLT * a, const FLT * b, FLT epsilon ); void copy3d( FLT * out, const FLT * in ); -FLT magnitude3d( FLT * a ); +FLT magnitude3d(const FLT * a ); FLT anglebetween3d( FLT * a, FLT * b ); @@ -87,6 +87,8 @@ void quatoddproduct( FLT * outvec3, FLT * qa, FLT * qb ); void quatslerp( FLT * q, const FLT * qa, const FLT * qb, FLT t ); void quatrotatevector( FLT * vec3out, const FLT * quat, const FLT * vec3in ); +void getRotationTo(FLT *q, const FLT *src, const FLT *dest); + // Matrix Stuff typedef struct -- cgit v1.2.3 From ae522f8a06848d467c835d87772580fa7cceb5cd Mon Sep 17 00:00:00 2001 From: mwturvey Date: Wed, 8 Feb 2017 11:42:46 -0700 Subject: Replaced rotation algorithm & cleanup --- redist/linmath.h | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'redist/linmath.h') diff --git a/redist/linmath.h b/redist/linmath.h index 3b11c1b..20a7848 100644 --- a/redist/linmath.h +++ b/redist/linmath.h @@ -87,26 +87,22 @@ void quatoddproduct( FLT * outvec3, FLT * qa, FLT * qb ); void quatslerp( FLT * q, const FLT * qa, const FLT * qb, FLT t ); void quatrotatevector( FLT * vec3out, const FLT * quat, const FLT * vec3in ); -void getRotationTo(FLT *q, const FLT *src, const FLT *dest); +void quatfrom2vectors(FLT *q, const FLT *src, const FLT *dest); // Matrix Stuff typedef struct { - // row, column, (0,0) in upper left - FLT val[3][3]; + FLT val[3][3]; // row, column } Matrix3x3; +void rotate_vec(FLT *out, const FLT *in, Matrix3x3 rot); +void rotation_between_vecs_to_m3(Matrix3x3 *m, const FLT v1[3], const FLT v2[3]); Matrix3x3 inverseM33(const Matrix3x3 mat); -void get_orthogonal_vector(FLT out[3], const FLT in[3]); -void rotation_between_vecs_to_mat3(FLT m[3][3], const FLT v1[3], const FLT v2[3]); -void unit_m3(FLT m[3][3]); -FLT normalize_v3(FLT n[3]); -void axis_angle_normalized_to_mat3_ex( - FLT mat[3][3], - const FLT axis[3], - const FLT angle_sin, - const FLT angle_cos); + + + + #endif -- cgit v1.2.3