From 23c5d85166873e227209c2f5cc73393b84987ab2 Mon Sep 17 00:00:00 2001 From: cxgeorge <> Date: Sat, 28 Apr 2001 02:58:58 +0000 Subject: [PATCH] hand-optimize linmath, force inlining --- panda/src/linmath/cast_to_double.I | 22 +- panda/src/linmath/cast_to_double.h | 22 +- panda/src/linmath/cast_to_float.I | 22 +- panda/src/linmath/cast_to_float.h | 22 +- panda/src/linmath/cmath.I | 34 +- panda/src/linmath/cmath.h | 26 +- panda/src/linmath/compose_matrix_src.I | 10 +- panda/src/linmath/compose_matrix_src.h | 10 +- panda/src/linmath/coordinateSystem.cxx | 3 +- panda/src/linmath/coordinateSystem.h | 2 + panda/src/linmath/deg_2_rad.h | 4 +- panda/src/linmath/lcast_to_src.I | 24 +- panda/src/linmath/lcast_to_src.h | 24 +- panda/src/linmath/lmat_ops_src.I | 20 +- panda/src/linmath/lmat_ops_src.h | 12 +- panda/src/linmath/lmatrix3_src.I | 664 ++++++++------ panda/src/linmath/lmatrix3_src.cxx | 4 +- panda/src/linmath/lmatrix3_src.h | 139 +-- panda/src/linmath/lmatrix4_src.I | 904 +++++++++++-------- panda/src/linmath/lmatrix4_src.cxx | 4 +- panda/src/linmath/lmatrix4_src.h | 150 +-- panda/src/linmath/lorientation_src.I | 16 +- panda/src/linmath/lorientation_src.h | 16 +- panda/src/linmath/lpoint2_src.I | 34 +- panda/src/linmath/lpoint2_src.h | 34 +- panda/src/linmath/lpoint3_src.I | 43 +- panda/src/linmath/lpoint3_src.h | 42 +- panda/src/linmath/lpoint4_src.I | 38 +- panda/src/linmath/lpoint4_src.h | 38 +- panda/src/linmath/lquaternion_src.I | 88 +- panda/src/linmath/lquaternion_src.cxx | 62 +- panda/src/linmath/lquaternion_src.h | 50 +- panda/src/linmath/lrotation_src.I | 18 +- panda/src/linmath/lrotation_src.h | 18 +- panda/src/linmath/lvec2_ops_src.I | 12 +- panda/src/linmath/lvec2_ops_src.h | 12 +- panda/src/linmath/lvec3_ops_src.I | 16 +- panda/src/linmath/lvec3_ops_src.h | 16 +- panda/src/linmath/lvec4_ops_src.I | 12 +- panda/src/linmath/lvec4_ops_src.h | 12 +- panda/src/linmath/lvecBase2_src.I | 206 +++-- panda/src/linmath/lvecBase2_src.h | 106 ++- panda/src/linmath/lvecBase3_src.I | 262 +++--- panda/src/linmath/lvecBase3_src.h | 113 +-- panda/src/linmath/lvecBase4_src.I | 302 ++++--- panda/src/linmath/lvecBase4_src.h | 116 +-- panda/src/linmath/lvector2_src.I | 41 +- panda/src/linmath/lvector2_src.h | 38 +- panda/src/linmath/lvector3_src.I | 95 +- panda/src/linmath/lvector3_src.h | 61 +- panda/src/linmath/lvector4_src.I | 45 +- panda/src/linmath/lvector4_src.h | 42 +- panda/src/linmath/nearly_zero.h | 4 +- panda/src/mathutil/boundingHexahedron.I | 10 +- panda/src/mathutil/boundingHexahedron.h | 10 +- panda/src/mathutil/boundingLine.I | 8 +- panda/src/mathutil/boundingLine.h | 8 +- panda/src/mathutil/boundingSphere.I | 8 +- panda/src/mathutil/boundingSphere.h | 8 +- panda/src/mathutil/boundingVolume.I | 14 +- panda/src/mathutil/boundingVolume.h | 14 +- panda/src/mathutil/frustum_src.I | 24 +- panda/src/mathutil/frustum_src.h | 24 +- panda/src/mathutil/geometricBoundingVolume.I | 16 +- panda/src/mathutil/geometricBoundingVolume.h | 16 +- panda/src/mathutil/look_at_src.I | 12 +- panda/src/mathutil/look_at_src.cxx | 8 +- panda/src/mathutil/look_at_src.h | 12 +- panda/src/mathutil/mathHelpers.I | 2 +- panda/src/mathutil/mathHelpers.h | 2 +- panda/src/mathutil/omniBoundingVolume.I | 2 +- panda/src/mathutil/omniBoundingVolume.h | 2 +- panda/src/mathutil/plane_src.I | 30 +- panda/src/mathutil/plane_src.h | 32 +- 74 files changed, 2416 insertions(+), 1976 deletions(-) diff --git a/panda/src/linmath/cast_to_double.I b/panda/src/linmath/cast_to_double.I index b4fa0e443e..1d94bd1fa6 100644 --- a/panda/src/linmath/cast_to_double.I +++ b/panda/src/linmath/cast_to_double.I @@ -3,47 +3,47 @@ // //////////////////////////////////////////////////////////////////// -INLINE LVecBase2d cast_to_double(const LVecBase2f &source) { +INLINE_LINMATH LVecBase2d cast_to_double(const LVecBase2f &source) { return LCAST(double, source); } -INLINE LVecBase3d cast_to_double(const LVecBase3f &source) { +INLINE_LINMATH LVecBase3d cast_to_double(const LVecBase3f &source) { return LCAST(double, source); } -INLINE LVecBase4d cast_to_double(const LVecBase4f &source) { +INLINE_LINMATH LVecBase4d cast_to_double(const LVecBase4f &source) { return LCAST(double, source); } -INLINE LVector2d cast_to_double(const LVector2f &source) { +INLINE_LINMATH LVector2d cast_to_double(const LVector2f &source) { return LCAST(double, source); } -INLINE LVector3d cast_to_double(const LVector3f &source) { +INLINE_LINMATH LVector3d cast_to_double(const LVector3f &source) { return LCAST(double, source); } -INLINE LVector4d cast_to_double(const LVector4f &source) { +INLINE_LINMATH LVector4d cast_to_double(const LVector4f &source) { return LCAST(double, source); } -INLINE LPoint2d cast_to_double(const LPoint2f &source) { +INLINE_LINMATH LPoint2d cast_to_double(const LPoint2f &source) { return LCAST(double, source); } -INLINE LPoint3d cast_to_double(const LPoint3f &source) { +INLINE_LINMATH LPoint3d cast_to_double(const LPoint3f &source) { return LCAST(double, source); } -INLINE LPoint4d cast_to_double(const LPoint4f &source) { +INLINE_LINMATH LPoint4d cast_to_double(const LPoint4f &source) { return LCAST(double, source); } -INLINE LMatrix3d cast_to_double(const LMatrix3f &source) { +INLINE_LINMATH LMatrix3d cast_to_double(const LMatrix3f &source) { return LCAST(double, source); } -INLINE LMatrix4d cast_to_double(const LMatrix4f &source) { +INLINE_LINMATH LMatrix4d cast_to_double(const LMatrix4f &source) { return LCAST(double, source); } diff --git a/panda/src/linmath/cast_to_double.h b/panda/src/linmath/cast_to_double.h index bc6f4c7ad6..b7f5e41d3e 100644 --- a/panda/src/linmath/cast_to_double.h +++ b/panda/src/linmath/cast_to_double.h @@ -13,17 +13,17 @@ // These are a number of functions that convert our various math // objects between floats and doubles. -INLINE LVecBase2d cast_to_double(const LVecBase2f &source); -INLINE LVecBase3d cast_to_double(const LVecBase3f &source); -INLINE LVecBase4d cast_to_double(const LVecBase4f &source); -INLINE LVector2d cast_to_double(const LVector2f &source); -INLINE LVector3d cast_to_double(const LVector3f &source); -INLINE LVector4d cast_to_double(const LVector4f &source); -INLINE LPoint2d cast_to_double(const LPoint2f &source); -INLINE LPoint3d cast_to_double(const LPoint3f &source); -INLINE LPoint4d cast_to_double(const LPoint4f &source); -INLINE LMatrix3d cast_to_double(const LMatrix3f &source); -INLINE LMatrix4d cast_to_double(const LMatrix4f &source); +INLINE_LINMATH LVecBase2d cast_to_double(const LVecBase2f &source); +INLINE_LINMATH LVecBase3d cast_to_double(const LVecBase3f &source); +INLINE_LINMATH LVecBase4d cast_to_double(const LVecBase4f &source); +INLINE_LINMATH LVector2d cast_to_double(const LVector2f &source); +INLINE_LINMATH LVector3d cast_to_double(const LVector3f &source); +INLINE_LINMATH LVector4d cast_to_double(const LVector4f &source); +INLINE_LINMATH LPoint2d cast_to_double(const LPoint2f &source); +INLINE_LINMATH LPoint3d cast_to_double(const LPoint3f &source); +INLINE_LINMATH LPoint4d cast_to_double(const LPoint4f &source); +INLINE_LINMATH LMatrix3d cast_to_double(const LMatrix3f &source); +INLINE_LINMATH LMatrix4d cast_to_double(const LMatrix4f &source); #include "cast_to_double.I" diff --git a/panda/src/linmath/cast_to_float.I b/panda/src/linmath/cast_to_float.I index 50ceabe700..fc1ea45cbd 100644 --- a/panda/src/linmath/cast_to_float.I +++ b/panda/src/linmath/cast_to_float.I @@ -3,47 +3,47 @@ // //////////////////////////////////////////////////////////////////// -INLINE LVecBase2f cast_to_float(const LVecBase2d &source) { +INLINE_LINMATH LVecBase2f cast_to_float(const LVecBase2d &source) { return LCAST(float, source); } -INLINE LVecBase3f cast_to_float(const LVecBase3d &source) { +INLINE_LINMATH LVecBase3f cast_to_float(const LVecBase3d &source) { return LCAST(float, source); } -INLINE LVecBase4f cast_to_float(const LVecBase4d &source) { +INLINE_LINMATH LVecBase4f cast_to_float(const LVecBase4d &source) { return LCAST(float, source); } -INLINE LVector2f cast_to_float(const LVector2d &source) { +INLINE_LINMATH LVector2f cast_to_float(const LVector2d &source) { return LCAST(float, source); } -INLINE LVector3f cast_to_float(const LVector3d &source) { +INLINE_LINMATH LVector3f cast_to_float(const LVector3d &source) { return LCAST(float, source); } -INLINE LVector4f cast_to_float(const LVector4d &source) { +INLINE_LINMATH LVector4f cast_to_float(const LVector4d &source) { return LCAST(float, source); } -INLINE LPoint2f cast_to_float(const LPoint2d &source) { +INLINE_LINMATH LPoint2f cast_to_float(const LPoint2d &source) { return LCAST(float, source); } -INLINE LPoint3f cast_to_float(const LPoint3d &source) { +INLINE_LINMATH LPoint3f cast_to_float(const LPoint3d &source) { return LCAST(float, source); } -INLINE LPoint4f cast_to_float(const LPoint4d &source) { +INLINE_LINMATH LPoint4f cast_to_float(const LPoint4d &source) { return LCAST(float, source); } -INLINE LMatrix3f cast_to_float(const LMatrix3d &source) { +INLINE_LINMATH LMatrix3f cast_to_float(const LMatrix3d &source) { return LCAST(float, source); } -INLINE LMatrix4f cast_to_float(const LMatrix4d &source) { +INLINE_LINMATH LMatrix4f cast_to_float(const LMatrix4d &source) { return LCAST(float, source); } diff --git a/panda/src/linmath/cast_to_float.h b/panda/src/linmath/cast_to_float.h index 64a4c9e0d7..178872aa65 100644 --- a/panda/src/linmath/cast_to_float.h +++ b/panda/src/linmath/cast_to_float.h @@ -13,17 +13,17 @@ // These are a number of functions that convert our various math // objects between floats and doubles. -INLINE LVecBase2f cast_to_float(const LVecBase2d &source); -INLINE LVecBase3f cast_to_float(const LVecBase3d &source); -INLINE LVecBase4f cast_to_float(const LVecBase4d &source); -INLINE LVector2f cast_to_float(const LVector2d &source); -INLINE LVector3f cast_to_float(const LVector3d &source); -INLINE LVector4f cast_to_float(const LVector4d &source); -INLINE LPoint2f cast_to_float(const LPoint2d &source); -INLINE LPoint3f cast_to_float(const LPoint3d &source); -INLINE LPoint4f cast_to_float(const LPoint4d &source); -INLINE LMatrix3f cast_to_float(const LMatrix3d &source); -INLINE LMatrix4f cast_to_float(const LMatrix4d &source); +INLINE_LINMATH LVecBase2f cast_to_float(const LVecBase2d &source); +INLINE_LINMATH LVecBase3f cast_to_float(const LVecBase3d &source); +INLINE_LINMATH LVecBase4f cast_to_float(const LVecBase4d &source); +INLINE_LINMATH LVector2f cast_to_float(const LVector2d &source); +INLINE_LINMATH LVector3f cast_to_float(const LVector3d &source); +INLINE_LINMATH LVector4f cast_to_float(const LVector4d &source); +INLINE_LINMATH LPoint2f cast_to_float(const LPoint2d &source); +INLINE_LINMATH LPoint3f cast_to_float(const LPoint3d &source); +INLINE_LINMATH LPoint4f cast_to_float(const LPoint4d &source); +INLINE_LINMATH LMatrix3f cast_to_float(const LMatrix3d &source); +INLINE_LINMATH LMatrix4f cast_to_float(const LMatrix4d &source); #include "cast_to_float.I" diff --git a/panda/src/linmath/cmath.I b/panda/src/linmath/cmath.I index e6865ce5a9..df2bc63602 100644 --- a/panda/src/linmath/cmath.I +++ b/panda/src/linmath/cmath.I @@ -9,19 +9,19 @@ #include #endif -INLINE float csqrt(float v) { +INLINE_LINMATH float csqrt(float v) { return sqrtf(v); } -INLINE float csin(float v) { +INLINE_LINMATH float csin(float v) { return sinf(v); } -INLINE float ccos(float v) { +INLINE_LINMATH float ccos(float v) { return cosf(v); } -INLINE void +INLINE_LINMATH void sincosf(float v, float *pSinResult, float *pCosResult) { // MS VC defines _M_IX86 for x86. gcc should define _X86_ @@ -41,8 +41,8 @@ sincosf(float v, float *pSinResult, float *pCosResult) { #endif //!_X86_ } -INLINE void -sincos(double v, double *pSinResult, double *pCosResult) { +INLINE_LINMATH void +sincosd(double v, double *pSinResult, double *pCosResult) { #if defined(_M_IX86) || defined(_X86_) //#define fsincos_opcode __asm _emit 0xd9 __asm _emit 0xfb __asm { @@ -59,43 +59,43 @@ sincos(double v, double *pSinResult, double *pCosResult) { #endif //!_X86_ } -INLINE void csincos(float v,float *pSinResult, float *pCosResult) { +INLINE_LINMATH void csincos(float v,float *pSinResult, float *pCosResult) { sincosf(v,pSinResult,pCosResult); } -INLINE void csincos(double v,double *pSinResult, double *pCosResult) { - sincos(v,pSinResult,pCosResult); +INLINE_LINMATH void csincos(double v,double *pSinResult, double *pCosResult) { + sincosd(v,pSinResult,pCosResult); } -INLINE float cabs(float v) { +INLINE_LINMATH float cabs(float v) { return fabs(v); } -INLINE float catan2(float y, float x) { +INLINE_LINMATH float catan2(float y, float x) { return atan2f(y, x); } -INLINE double csqrt(double v) { +INLINE_LINMATH double csqrt(double v) { return sqrt(v); } -INLINE double csin(double v) { +INLINE_LINMATH double csin(double v) { return sin(v); } -INLINE double ccos(double v) { +INLINE_LINMATH double ccos(double v) { return cos(v); } -INLINE double cabs(double v) { +INLINE_LINMATH double cabs(double v) { return fabs(v); } -INLINE double catan2(double y, double x) { +INLINE_LINMATH double catan2(double y, double x) { return atan2(y, x); } -INLINE bool cnan(double v) { +INLINE_LINMATH bool cnan(double v) { #ifndef _WIN32 return (isnan(v) != 0); #else diff --git a/panda/src/linmath/cmath.h b/panda/src/linmath/cmath.h index ccb164edbb..4d05ad107a 100644 --- a/panda/src/linmath/cmath.h +++ b/panda/src/linmath/cmath.h @@ -16,23 +16,23 @@ // explicitly whether we need to call, for instance, sqrtf() or // sqrt(). -INLINE float csqrt(float v); -INLINE float csin(float v); -INLINE float ccos(float v); -INLINE void csincos(float v, float *pSinResult, float *pCosResult); // does both at once (faster on x86) -INLINE float cabs(float v); -INLINE float catan2(float y, float x); +INLINE_LINMATH float csqrt(float v); +INLINE_LINMATH float csin(float v); +INLINE_LINMATH float ccos(float v); +INLINE_LINMATH void csincos(float v, float *pSinResult, float *pCosResult); // does both at once (faster on x86) +INLINE_LINMATH float cabs(float v); +INLINE_LINMATH float catan2(float y, float x); -INLINE double csqrt(double v); -INLINE double csin(double v); -INLINE double ccos(double v); -INLINE double cabs(double v); -INLINE double catan2(double y, double x); -INLINE void csincos(double v, double *pSinResult, double *pCosResult); // does both at once (faster on x86) +INLINE_LINMATH double csqrt(double v); +INLINE_LINMATH double csin(double v); +INLINE_LINMATH double ccos(double v); +INLINE_LINMATH double cabs(double v); +INLINE_LINMATH double catan2(double y, double x); +INLINE_LINMATH void csincos(double v, double *pSinResult, double *pCosResult); // does both at once (faster on x86) // Returns true if the number is nan, false if it's a genuine number // or infinity. -INLINE bool cnan(double v); +INLINE_LINMATH bool cnan(double v); #include "cmath.I" diff --git a/panda/src/linmath/compose_matrix_src.I b/panda/src/linmath/compose_matrix_src.I index 78ca9519ca..ebc0ce1ac0 100644 --- a/panda/src/linmath/compose_matrix_src.I +++ b/panda/src/linmath/compose_matrix_src.I @@ -10,7 +10,7 @@ // Description: Computes the 4x4 matrix according to scale, rotation, // and translation. //////////////////////////////////////////////////////////////////// -INLINE void +INLINE_LINMATH void compose_matrix(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVecBase3) &scale, const FLOATNAME(LVecBase3) &hpr, @@ -21,7 +21,7 @@ compose_matrix(FLOATNAME(LMatrix4) &mat, mat = FLOATNAME(LMatrix4)(upper3, translate); } -INLINE void +INLINE_LINMATH void compose_matrix(FLOATNAME(LMatrix4) &mat, const FLOATTYPE components[9], CoordinateSystem cs) { @@ -46,7 +46,7 @@ compose_matrix(FLOATNAME(LMatrix4) &mat, // also a shear component or if the matrix is not // affine. //////////////////////////////////////////////////////////////////// -INLINE bool +INLINE_LINMATH bool decompose_matrix(const FLOATNAME(LMatrix4) &mat, FLOATNAME(LVecBase3) &scale, FLOATNAME(LVecBase3) &hpr, @@ -71,7 +71,7 @@ decompose_matrix(const FLOATNAME(LMatrix4) &mat, // by examining the matrix; this helps alleviate roll // instability due to roundoff errors or gimbal lock. //////////////////////////////////////////////////////////////////// -INLINE bool +INLINE_LINMATH bool decompose_matrix(const FLOATNAME(LMatrix4) &mat, FLOATNAME(LVecBase3) &scale, FLOATNAME(LVecBase3) &hpr, @@ -83,7 +83,7 @@ decompose_matrix(const FLOATNAME(LMatrix4) &mat, return decompose_matrix(mat.get_upper_3(), scale, hpr, roll, cs); } -INLINE bool +INLINE_LINMATH bool decompose_matrix(const FLOATNAME(LMatrix4) &mat, FLOATTYPE components[9], CoordinateSystem cs) { diff --git a/panda/src/linmath/compose_matrix_src.h b/panda/src/linmath/compose_matrix_src.h index 079005b6f2..140fd84f3f 100644 --- a/panda/src/linmath/compose_matrix_src.h +++ b/panda/src/linmath/compose_matrix_src.h @@ -12,14 +12,14 @@ compose_matrix(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVecBase3) &hpr, CoordinateSystem cs = CS_default); -INLINE void +INLINE_LINMATH void compose_matrix(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVecBase3) &scale, const FLOATNAME(LVecBase3) &hpr, const FLOATNAME(LVecBase3) &translate, CoordinateSystem cs = CS_default); -INLINE void +INLINE_LINMATH void compose_matrix(FLOATNAME(LMatrix4) &mat, const FLOATTYPE components[9], CoordinateSystem cs = CS_default); @@ -36,14 +36,14 @@ decompose_matrix(const FLOATNAME(LMatrix3) &mat, FLOATTYPE roll, CoordinateSystem cs = CS_default); -INLINE bool +INLINE_LINMATH bool decompose_matrix(const FLOATNAME(LMatrix4) &mat, FLOATNAME(LVecBase3) &scale, FLOATNAME(LVecBase3) &hpr, FLOATNAME(LVecBase3) &translate, CoordinateSystem cs = CS_default); -INLINE bool +INLINE_LINMATH bool decompose_matrix(const FLOATNAME(LMatrix4) &mat, FLOATNAME(LVecBase3) &scale, FLOATNAME(LVecBase3) &hpr, @@ -51,7 +51,7 @@ decompose_matrix(const FLOATNAME(LMatrix4) &mat, FLOATTYPE roll, CoordinateSystem cs = CS_default); -INLINE bool +INLINE_LINMATH bool decompose_matrix(const FLOATNAME(LMatrix4) &mat, FLOATTYPE components[9], CoordinateSystem CS = CS_default); diff --git a/panda/src/linmath/coordinateSystem.cxx b/panda/src/linmath/coordinateSystem.cxx index c1317ade4b..601aeb6a68 100644 --- a/panda/src/linmath/coordinateSystem.cxx +++ b/panda/src/linmath/coordinateSystem.cxx @@ -14,7 +14,6 @@ CoordinateSystem default_coordinate_system; - CoordinateSystem parse_coordinate_system_string(const string &str) { // First, make sure the string is lowercase before we compare it, so @@ -45,7 +44,7 @@ parse_coordinate_system_string(const string &str) { return CS_invalid; } -bool +INLINE_LINMATH bool is_right_handed(CoordinateSystem cs) { if (cs == CS_default) { cs = default_coordinate_system; diff --git a/panda/src/linmath/coordinateSystem.h b/panda/src/linmath/coordinateSystem.h index f82b0efa2e..eb18613fc0 100644 --- a/panda/src/linmath/coordinateSystem.h +++ b/panda/src/linmath/coordinateSystem.h @@ -39,6 +39,8 @@ extern CoordinateSystem EXPCL_PANDA default_coordinate_system; CoordinateSystem EXPCL_PANDA parse_coordinate_system_string(const string &str); bool EXPCL_PANDA is_right_handed(CoordinateSystem cs = CS_default); +#define IS_LEFT_HANDED_COORDSYSTEM(cs) ((cs==CS_zup_left) || (cs==CS_yup_left)) + ostream EXPCL_PANDA &operator << (ostream &out, CoordinateSystem cs); diff --git a/panda/src/linmath/deg_2_rad.h b/panda/src/linmath/deg_2_rad.h index b7a29d9b30..8d2f68912d 100644 --- a/panda/src/linmath/deg_2_rad.h +++ b/panda/src/linmath/deg_2_rad.h @@ -11,8 +11,8 @@ #include "mathNumbers.h" BEGIN_PUBLISH -INLINE double deg_2_rad( double f ) { return f * MathNumbers::pi / 180.0; } -INLINE double rad_2_deg( double f ) { return f * 180.0 / MathNumbers::pi; } +INLINE_LINMATH double deg_2_rad( double f ) { return f * MathNumbers::pi / 180.0; } +INLINE_LINMATH double rad_2_deg( double f ) { return f * 180.0 / MathNumbers::pi; } END_PUBLISH #endif diff --git a/panda/src/linmath/lcast_to_src.I b/panda/src/linmath/lcast_to_src.I index 49b3420053..8a8730494e 100644 --- a/panda/src/linmath/lcast_to_src.I +++ b/panda/src/linmath/lcast_to_src.I @@ -1,55 +1,55 @@ -INLINE FLOATNAME2(LVecBase2) +INLINE_LINMATH FLOATNAME2(LVecBase2) lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase2) &source) { return FLOATNAME2(LVecBase2)(source[0], source[1]); } -INLINE FLOATNAME2(LVecBase3) +INLINE_LINMATH FLOATNAME2(LVecBase3) lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase3) &source) { return FLOATNAME2(LVecBase3)(source[0], source[1], source[2]); } -INLINE FLOATNAME2(LVecBase4) +INLINE_LINMATH FLOATNAME2(LVecBase4) lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase4) &source) { return FLOATNAME2(LVecBase4)(source[0], source[1], source[2], source[3]); } -INLINE FLOATNAME2(LVector2) +INLINE_LINMATH FLOATNAME2(LVector2) lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector2) &source) { return FLOATNAME2(LVector2)(source[0], source[1]); } -INLINE FLOATNAME2(LVector3) +INLINE_LINMATH FLOATNAME2(LVector3) lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector3) &source) { return FLOATNAME2(LVector3)(source[0], source[1], source[2]); } -INLINE FLOATNAME2(LVector4) +INLINE_LINMATH FLOATNAME2(LVector4) lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector4) &source) { return FLOATNAME2(LVector4)(source[0], source[1], source[2], source[3]); } -INLINE FLOATNAME2(LPoint2) +INLINE_LINMATH FLOATNAME2(LPoint2) lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint2) &source) { return FLOATNAME2(LPoint2)(source[0], source[1]); } -INLINE FLOATNAME2(LPoint3) +INLINE_LINMATH FLOATNAME2(LPoint3) lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint3) &source) { return FLOATNAME2(LPoint3)(source[0], source[1], source[2]); } -INLINE FLOATNAME2(LPoint4) +INLINE_LINMATH FLOATNAME2(LPoint4) lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint4) &source) { return FLOATNAME2(LPoint4)(source[0], source[1], source[2], source[3]); } -INLINE FLOATNAME2(LQuaternion) +INLINE_LINMATH FLOATNAME2(LQuaternion) lcast_to(FLOATTYPE2 *, const FLOATNAME(LQuaternion)& c) { return FLOATNAME2(LQuaternion)(c.get_r(), c.get_i(), c.get_j(), c.get_k()); } -INLINE FLOATNAME2(LMatrix3) +INLINE_LINMATH FLOATNAME2(LMatrix3) lcast_to(FLOATTYPE2 *, const FLOATNAME(LMatrix3) &source) { return FLOATNAME2(LMatrix3) (source(0, 0), source(0, 1), source(0, 2), @@ -57,7 +57,7 @@ lcast_to(FLOATTYPE2 *, const FLOATNAME(LMatrix3) &source) { source(2, 0), source(2, 1), source(2, 2)); } -INLINE FLOATNAME2(LMatrix4) +INLINE_LINMATH FLOATNAME2(LMatrix4) lcast_to(FLOATTYPE2 *, const FLOATNAME(LMatrix4) &source) { return FLOATNAME2(LMatrix4) (source(0, 0), source(0, 1), source(0, 2), source(0, 3), diff --git a/panda/src/linmath/lcast_to_src.h b/panda/src/linmath/lcast_to_src.h index 90ef16af01..9f658f65f6 100644 --- a/panda/src/linmath/lcast_to_src.h +++ b/panda/src/linmath/lcast_to_src.h @@ -3,40 +3,40 @@ // //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME2(LVecBase2) +INLINE_LINMATH FLOATNAME2(LVecBase2) lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase2) &source); -INLINE FLOATNAME2(LVecBase3) +INLINE_LINMATH FLOATNAME2(LVecBase3) lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase3) &source); -INLINE FLOATNAME2(LVecBase4) +INLINE_LINMATH FLOATNAME2(LVecBase4) lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase4) &source); -INLINE FLOATNAME2(LVector2) +INLINE_LINMATH FLOATNAME2(LVector2) lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector2) &source); -INLINE FLOATNAME2(LVector3) +INLINE_LINMATH FLOATNAME2(LVector3) lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector3) &source); -INLINE FLOATNAME2(LVector4) +INLINE_LINMATH FLOATNAME2(LVector4) lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector4) &source); -INLINE FLOATNAME2(LPoint2) +INLINE_LINMATH FLOATNAME2(LPoint2) lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint2) &source); -INLINE FLOATNAME2(LPoint3) +INLINE_LINMATH FLOATNAME2(LPoint3) lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint3) &source); -INLINE FLOATNAME2(LPoint4) +INLINE_LINMATH FLOATNAME2(LPoint4) lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint4) &source); -INLINE FLOATNAME2(LQuaternion) +INLINE_LINMATH FLOATNAME2(LQuaternion) lcast_to(FLOATTYPE2 *, const FLOATNAME(LQuaternion)& c); -INLINE FLOATNAME2(LMatrix3) +INLINE_LINMATH FLOATNAME2(LMatrix3) lcast_to(FLOATTYPE2 *, const FLOATNAME(LMatrix3) &source); -INLINE FLOATNAME2(LMatrix4) +INLINE_LINMATH FLOATNAME2(LMatrix4) lcast_to(FLOATTYPE2 *, const FLOATNAME(LMatrix4) &source); #include "lcast_to_src.I" diff --git a/panda/src/linmath/lmat_ops_src.I b/panda/src/linmath/lmat_ops_src.I index 4f0cbfd515..28023f1e5f 100644 --- a/panda/src/linmath/lmat_ops_src.I +++ b/panda/src/linmath/lmat_ops_src.I @@ -9,17 +9,17 @@ // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) +INLINE_LINMATH FLOATNAME(LVecBase3) operator * (const FLOATNAME(LVecBase3) &v, const FLOATNAME(LMatrix3) &m) { return m.xform(v); } -INLINE FLOATNAME(LVector3) +INLINE_LINMATH FLOATNAME(LVector3) operator * (const FLOATNAME(LVector3) &v, const FLOATNAME(LMatrix3) &m) { return m.xform(v); } -INLINE FLOATNAME(LPoint3) +INLINE_LINMATH FLOATNAME(LPoint3) operator * (const FLOATNAME(LPoint3) &v, const FLOATNAME(LMatrix3) &m) { return m.xform(v); } @@ -29,7 +29,7 @@ operator * (const FLOATNAME(LPoint3) &v, const FLOATNAME(LMatrix3) &m) { // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector2) +INLINE_LINMATH FLOATNAME(LVector2) operator * (const FLOATNAME(LVector2) &v, const FLOATNAME(LMatrix3) &m) { return m.xform_vec(v); } @@ -39,7 +39,7 @@ operator * (const FLOATNAME(LVector2) &v, const FLOATNAME(LMatrix3) &m) { // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint2) +INLINE_LINMATH FLOATNAME(LPoint2) operator * (const FLOATNAME(LPoint2) &v, const FLOATNAME(LMatrix3) &m) { return m.xform_point(v); } @@ -50,17 +50,17 @@ operator * (const FLOATNAME(LPoint2) &v, const FLOATNAME(LMatrix3) &m) { // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4) +INLINE_LINMATH FLOATNAME(LVecBase4) operator * (const FLOATNAME(LVecBase4) &v, const FLOATNAME(LMatrix4) &m) { return m.xform(v); } -INLINE FLOATNAME(LVector4) +INLINE_LINMATH FLOATNAME(LVector4) operator * (const FLOATNAME(LVector4) &v, const FLOATNAME(LMatrix4) &m) { return m.xform(v); } -INLINE FLOATNAME(LPoint4) +INLINE_LINMATH FLOATNAME(LPoint4) operator * (const FLOATNAME(LPoint4) &v, const FLOATNAME(LMatrix4) &m) { return m.xform(v); } @@ -71,7 +71,7 @@ operator * (const FLOATNAME(LPoint4) &v, const FLOATNAME(LMatrix4) &m) { // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) +INLINE_LINMATH FLOATNAME(LVector3) operator * (const FLOATNAME(LVector3) &v, const FLOATNAME(LMatrix4) &m) { return m.xform_vec(v); } @@ -81,7 +81,7 @@ operator * (const FLOATNAME(LVector3) &v, const FLOATNAME(LMatrix4) &m) { // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint3) +INLINE_LINMATH FLOATNAME(LPoint3) operator * (const FLOATNAME(LPoint3) &v, const FLOATNAME(LMatrix4) &m) { return m.xform_point(v); } diff --git a/panda/src/linmath/lmat_ops_src.h b/panda/src/linmath/lmat_ops_src.h index 9114e95b82..c568df6b55 100644 --- a/panda/src/linmath/lmat_ops_src.h +++ b/panda/src/linmath/lmat_ops_src.h @@ -7,25 +7,25 @@ BEGIN_PUBLISH // vector times matrix3 -INLINE FLOATNAME(LVecBase3) +INLINE_LINMATH FLOATNAME(LVecBase3) operator * (const FLOATNAME(LVecBase3) &v, const FLOATNAME(LMatrix3) &m); -INLINE FLOATNAME(LVector2) +INLINE_LINMATH FLOATNAME(LVector2) operator * (const FLOATNAME(LVector2) &v, const FLOATNAME(LMatrix3) &m); -INLINE FLOATNAME(LPoint2) +INLINE_LINMATH FLOATNAME(LPoint2) operator * (const FLOATNAME(LPoint2) &v, const FLOATNAME(LMatrix3) &m); // vector times matrix4 -INLINE FLOATNAME(LVecBase4) +INLINE_LINMATH FLOATNAME(LVecBase4) operator * (const FLOATNAME(LVecBase4) &v, const FLOATNAME(LMatrix4) &m); -INLINE FLOATNAME(LVector3) +INLINE_LINMATH FLOATNAME(LVector3) operator * (const FLOATNAME(LVector3) &v, const FLOATNAME(LMatrix4) &m); -INLINE FLOATNAME(LPoint3) +INLINE_LINMATH FLOATNAME(LPoint3) operator * (const FLOATNAME(LPoint3) &v, const FLOATNAME(LMatrix4) &m); END_PUBLISH diff --git a/panda/src/linmath/lmatrix3_src.I b/panda/src/linmath/lmatrix3_src.I index b97d1e6cfe..ff0b5acc3b 100644 --- a/panda/src/linmath/lmatrix3_src.I +++ b/panda/src/linmath/lmatrix3_src.I @@ -11,7 +11,7 @@ // This function definition must appear first, since // some inline functions below take advantage of it. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3):: +INLINE_LINMATH const FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3):: ident_mat() { return _ident_mat; } @@ -21,7 +21,7 @@ ident_mat() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3):: FLOATNAME(LMatrix3)() { } @@ -30,9 +30,10 @@ FLOATNAME(LMatrix3)() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3):: FLOATNAME(LMatrix3)(const FLOATNAME(LMatrix3) ©) { - (*this) = copy; + memcpy(_m.data,copy._m.data,sizeof(_m.data)); +// (*this) = copy; } //////////////////////////////////////////////////////////////////// @@ -40,11 +41,12 @@ FLOATNAME(LMatrix3)(const FLOATNAME(LMatrix3) ©) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3):: operator = (const FLOATNAME(LMatrix3) ©) { - set(copy(0, 0), copy(0, 1), copy(0, 2), - copy(1, 0), copy(1, 1), copy(1, 2), - copy(2, 0), copy(2, 1), copy(2, 2)); + memcpy(_m.data,copy._m.data,sizeof(_m.data)); +// set(copy(0, 0), copy(0, 1), copy(0, 2), +// copy(1, 0), copy(1, 1), copy(1, 2), +// copy(2, 0), copy(2, 1), copy(2, 2)); return *this; } @@ -53,7 +55,7 @@ operator = (const FLOATNAME(LMatrix3) ©) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3):: operator = (FLOATTYPE fill_value) { fill(fill_value); return *this; @@ -64,13 +66,23 @@ operator = (FLOATTYPE fill_value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3):: FLOATNAME(LMatrix3)(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12, FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22) { - set(e00, e01, e02, - e10, e11, e12, - e20, e21, e22); + _m.m._00 = e00; + _m.m._01 = e01; + _m.m._02 = e02; + _m.m._10 = e10; + _m.m._11 = e11; + _m.m._12 = e12; + _m.m._20 = e20; + _m.m._21 = e21; + _m.m._22 = e22; + +// set(e00, e01, e02, +// e10, e11, e12, +// e20, e21, e22); } //////////////////////////////////////////////////////////////////// @@ -78,19 +90,30 @@ FLOATNAME(LMatrix3)(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix3):: +INLINE_LINMATH void FLOATNAME(LMatrix3):: set(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12, FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22) { - (*this)(0, 0) = e00; - (*this)(0, 1) = e01; - (*this)(0, 2) = e02; - (*this)(1, 0) = e10; - (*this)(1, 1) = e11; - (*this)(1, 2) = e12; - (*this)(2, 0) = e20; - (*this)(2, 1) = e21; - (*this)(2, 2) = e22; + _m.m._00 = e00; + _m.m._01 = e01; + _m.m._02 = e02; + _m.m._10 = e10; + _m.m._11 = e11; + _m.m._12 = e12; + _m.m._20 = e20; + _m.m._21 = e21; + _m.m._22 = e22; + /* + _m.m._00 = e00; + _m.m._01 = e01; + _m.m._02 = e02; + _m.m._10 = e10; + _m.m._11 = e11; + _m.m._12 = e12; + _m.m._20 = e20; + _m.m._21 = e21; + _m.m._22 = e22; + */ } //////////////////////////////////////////////////////////////////// @@ -99,11 +122,11 @@ set(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, // Description: Replaces the indicated row of the matrix from a // three-component vector. //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix3):: +INLINE_LINMATH void FLOATNAME(LMatrix3):: set_row(int row, const FLOATNAME(LVecBase3) &v) { - (*this)(row, 0) = v[0]; - (*this)(row, 1) = v[1]; - (*this)(row, 2) = v[2]; + (*this)(row, 0) = v._v.v._0; + (*this)(row, 1) = v._v.v._1; + (*this)(row, 2) = v._v.v._2; } //////////////////////////////////////////////////////////////////// @@ -112,11 +135,11 @@ set_row(int row, const FLOATNAME(LVecBase3) &v) { // Description: Replaces the indicated column of the matrix from a // three-component vector. //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix3):: +INLINE_LINMATH void FLOATNAME(LMatrix3):: set_col(int col, const FLOATNAME(LVecBase3) &v) { - (*this)(0, col) = v[0]; - (*this)(1, col) = v[1]; - (*this)(2, col) = v[2]; + (*this)(0, col) = v._v.v._0; + (*this)(1, col) = v._v.v._1; + (*this)(2, col) = v._v.v._2; } //////////////////////////////////////////////////////////////////// @@ -125,10 +148,10 @@ set_col(int col, const FLOATNAME(LVecBase3) &v) { // Description: Replaces the indicated row of the matrix from a // two-component vector, ignoring the last column. //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix3):: +INLINE_LINMATH void FLOATNAME(LMatrix3):: set_row(int row, const FLOATNAME(LVecBase2) &v) { - (*this)(row, 0) = v[0]; - (*this)(row, 1) = v[1]; + (*this)(row, 0) = v._v.v._0; + (*this)(row, 1) = v._v.v._1; } //////////////////////////////////////////////////////////////////// @@ -137,10 +160,10 @@ set_row(int row, const FLOATNAME(LVecBase2) &v) { // Description: Replaces the indicated column of the matrix from a // two-component vector, ignoring the last row. //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix3):: +INLINE_LINMATH void FLOATNAME(LMatrix3):: set_col(int col, const FLOATNAME(LVecBase2) &v) { - (*this)(0, col) = v[0]; - (*this)(1, col) = v[1]; + (*this)(0, col) = v._v.v._0; + (*this)(1, col) = v._v.v._1; } //////////////////////////////////////////////////////////////////// @@ -149,7 +172,7 @@ set_col(int col, const FLOATNAME(LVecBase2) &v) { // Description: Returns the indicated row of the matrix as a // three-component vector. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix3):: get_row(int row) const { return FLOATNAME(LVecBase3)((*this)(row, 0), (*this)(row, 1), (*this)(row, 2)); } @@ -160,7 +183,7 @@ get_row(int row) const { // Description: Returns the indicated column of the matrix as a // three-component vector. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix3):: get_col(int col) const { return FLOATNAME(LVecBase3)((*this)(0, col), (*this)(1, col), (*this)(2, col)); } @@ -171,7 +194,7 @@ get_col(int col) const { // Description: Returns the indicated row of the matrix as a // two-component vector, ignoring the last column. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2) FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LMatrix3):: get_row2(int row) const { return FLOATNAME(LVecBase2)((*this)(row, 0), (*this)(row, 1)); } @@ -182,7 +205,7 @@ get_row2(int row) const { // Description: Returns the indicated column of the matrix as a // two-component vector, ignoring the last row. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2) FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LMatrix3):: get_col2(int col) const { return FLOATNAME(LVecBase2)((*this)(0, col), (*this)(1, col)); } @@ -192,11 +215,11 @@ get_col2(int col) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE &FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATTYPE &FLOATNAME(LMatrix3):: operator () (int row, int col) { -// nassertr(row >= 0 && row < 3, _data[0]); -// nassertr(col >= 0 && col < 3, _data[0]); - return _data[row * 3 + col]; +// nassertr(row >= 0 && row < 3, _m.data[0]); +// nassertr(col >= 0 && col < 3, _m.data[0]); + return _m.data[row * 3 + col]; } //////////////////////////////////////////////////////////////////// @@ -204,11 +227,11 @@ operator () (int row, int col) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix3):: operator () (int row, int col) const { // nassertr(row >= 0 && row < 3, 0.0); // nassertr(col >= 0 && col < 3, 0.0); - return _data[row * 3 + col]; + return _m.data[row * 3 + col]; } //////////////////////////////////////////////////////////////////// @@ -217,12 +240,12 @@ operator () (int row, int col) const { // Description: Returns true if any component of the matrix is // not-a-number, false otherwise. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LMatrix3):: +INLINE_LINMATH bool FLOATNAME(LMatrix3):: is_nan() const { return - cnan(_data[0]) || cnan(_data[1]) || cnan(_data[2]) || - cnan(_data[3]) || cnan(_data[4]) || cnan(_data[5]) || - cnan(_data[6]) || cnan(_data[7]) || cnan(_data[8]); + cnan(_m.data[0]) || cnan(_m.data[1]) || cnan(_m.data[2]) || + cnan(_m.data[3]) || cnan(_m.data[4]) || cnan(_m.data[5]) || + cnan(_m.data[6]) || cnan(_m.data[7]) || cnan(_m.data[8]); } //////////////////////////////////////////////////////////////////// @@ -230,11 +253,11 @@ is_nan() const { // Access: Public // Description: Returns a particular element of the matrix. //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix3):: get_cell(int row, int col) const { // nassertr(row >= 0 && row < 3, 0.0); // nassertr(col >= 0 && col < 3, 0.0); - return _data[row * 3 + col]; + return _m.data[row * 3 + col]; } //////////////////////////////////////////////////////////////////// @@ -242,11 +265,11 @@ get_cell(int row, int col) const { // Access: Public // Description: Changes a particular element of the matrix. //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix3):: +INLINE_LINMATH void FLOATNAME(LMatrix3):: set_cell(int row, int col, FLOATTYPE value) { // nassertv(row >= 0 && row < 3); // nassertv(col >= 0 && col < 3); - _data[row * 3 + col] = value; + _m.data[row * 3 + col] = value; } //////////////////////////////////////////////////////////////////// @@ -256,9 +279,9 @@ set_cell(int row, int col, FLOATTYPE value) { // elements in the matrix. The remaining elements // occupy the next eight positions in row-major order. //////////////////////////////////////////////////////////////////// -INLINE const FLOATTYPE *FLOATNAME(LMatrix3):: +INLINE_LINMATH const FLOATTYPE *FLOATNAME(LMatrix3):: get_data() const { - return _data; + return _m.data; } //////////////////////////////////////////////////////////////////// @@ -266,7 +289,7 @@ get_data() const { // Access: Public // Description: Returns the number of elements in the matrix, nine. //////////////////////////////////////////////////////////////////// -INLINE int FLOATNAME(LMatrix3):: +INLINE_LINMATH int FLOATNAME(LMatrix3):: get_num_components() const { return 9; } @@ -277,9 +300,9 @@ get_num_components() const { // Description: Returns an iterator that may be used to traverse the // elements of the matrix, STL-style. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3)::iterator FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3)::iterator FLOATNAME(LMatrix3):: begin() { - return _data; + return _m.data; } //////////////////////////////////////////////////////////////////// @@ -288,7 +311,7 @@ begin() { // Description: Returns an iterator that may be used to traverse the // elements of the matrix, STL-style. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3)::iterator FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3)::iterator FLOATNAME(LMatrix3):: end() { return begin() + get_num_components(); } @@ -299,9 +322,9 @@ end() { // Description: Returns an iterator that may be used to traverse the // elements of the matrix, STL-style. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3)::const_iterator FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3)::const_iterator FLOATNAME(LMatrix3):: begin() const { - return _data; + return _m.data; } //////////////////////////////////////////////////////////////////// @@ -310,7 +333,7 @@ begin() const { // Description: Returns an iterator that may be used to traverse the // elements of the matrix, STL-style. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3)::const_iterator FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3)::const_iterator FLOATNAME(LMatrix3):: end() const { return begin() + get_num_components(); } @@ -324,7 +347,7 @@ end() const { // especially in an STL container. Also see // compare_to(). //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LMatrix3):: +INLINE_LINMATH bool FLOATNAME(LMatrix3):: operator < (const FLOATNAME(LMatrix3) &other) const { return compare_to(other) < 0; } @@ -334,7 +357,7 @@ operator < (const FLOATNAME(LMatrix3) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LMatrix3):: +INLINE_LINMATH bool FLOATNAME(LMatrix3):: operator == (const FLOATNAME(LMatrix3) &other) const { return compare_to(other) == 0; } @@ -344,7 +367,7 @@ operator == (const FLOATNAME(LMatrix3) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LMatrix3):: +INLINE_LINMATH bool FLOATNAME(LMatrix3):: operator != (const FLOATNAME(LMatrix3) &other) const { return !operator == (other); } @@ -355,22 +378,40 @@ operator != (const FLOATNAME(LMatrix3) &other) const { // Description: This flavor of compare_to uses a default threshold // value based on the numeric type. //////////////////////////////////////////////////////////////////// -INLINE int FLOATNAME(LMatrix3):: +INLINE_LINMATH int FLOATNAME(LMatrix3):: compare_to(const FLOATNAME(LMatrix3) &other) const { return compare_to(other, NEARLY_ZERO(FLOATTYPE)); } +#define VECTOR3_MATRIX3_PRODUCT(v_res, v, mat) \ +v_res._v.v._0 = v._v.v._0*mat._m.m._00 + v._v.v._1*mat._m.m._10 + v._v.v._2*mat._m.m._20; \ +v_res._v.v._1 = v._v.v._0*mat._m.m._01 + v._v.v._1*mat._m.m._11 + v._v.v._2*mat._m.m._21; \ +v_res._v.v._2 = v._v.v._0*mat._m.m._02 + v._v.v._1*mat._m.m._12 + v._v.v._2*mat._m.m._22; + +// bugbug: need 2 check if this is correct, or reversed from previous implementation +// before checkin + //////////////////////////////////////////////////////////////////// // Function: LMatrix3::xform // Access: Public // Description: 3-component vector or point times matrix. This is a // fully general operation. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix3):: xform(const FLOATNAME(LVecBase3) &v) const { - return FLOATNAME(LVecBase3)(v.dot(get_col(0)), - v.dot(get_col(1)), - v.dot(get_col(2))); + FLOATNAME(LVecBase3) v_res; + + + + VECTOR3_MATRIX3_PRODUCT(v_res, v,(*this)); + + + + return v_res; + +// return FLOATNAME(LVecBase3)(v.dot(get_col(0)), +// v.dot(get_col(1)), +// v.dot(get_col(2))); } //////////////////////////////////////////////////////////////////// @@ -380,10 +421,20 @@ xform(const FLOATNAME(LVecBase3) &v) const { // translation component) and returns the result. This // assumes the matrix is an affine transform. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2) FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LMatrix3):: xform_point(const FLOATNAME(LVecBase2) &v) const { - return FLOATNAME(LVecBase2)(v.dot(get_col2(0)) + (*this)(2, 0), - v.dot(get_col2(1)) + (*this)(2, 1)); + + FLOATNAME(LVecBase2) v_res; + + // v._v.v._2 == 1.0 for this case + + v_res._v.v._0 = v._v.v._0*_m.m._00 + v._v.v._1*_m.m._10 + _m.m._20; + v_res._v.v._1 = v._v.v._0*_m.m._01 + v._v.v._1*_m.m._11 + _m.m._21; + + return v_res; + +// return FLOATNAME(LVecBase2)(v.dot(get_col2(0)) + _m.m._20, +// v.dot(get_col2(1)) + _m.m._21); } //////////////////////////////////////////////////////////////////// @@ -393,10 +444,20 @@ xform_point(const FLOATNAME(LVecBase2) &v) const { // translation component) and returns the result. This // assumes the matrix is an affine transform. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2) FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LMatrix3):: xform_vec(const FLOATNAME(LVecBase2) &v) const { - return FLOATNAME(LVecBase2)(v.dot(get_col2(0)), - v.dot(get_col2(1))); + + FLOATNAME(LVecBase2) v_res; + + // v._v.v._2 == 0.0 for this case + + v_res._v.v._0 = v._v.v._0*_m.m._00 + v._v.v._1*_m.m._10; + v_res._v.v._1 = v._v.v._0*_m.m._01 + v._v.v._1*_m.m._11; + + return v_res; + +// return FLOATNAME(LVecBase2)(v.dot(get_col2(0)), +// v.dot(get_col2(1))); } //////////////////////////////////////////////////////////////////// @@ -405,9 +466,9 @@ xform_vec(const FLOATNAME(LVecBase2) &v) const { // Description: Returns one cell of the result of a matrix-matrix // multiplication operation. //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix3):: mult_cel(const FLOATNAME(LMatrix3) &other, int row, int col) const { - return get_row(row).dot(other.get_col(col)); + return get_row(row).dot(other.get_col(col)); } //////////////////////////////////////////////////////////////////// @@ -415,9 +476,11 @@ mult_cel(const FLOATNAME(LMatrix3) &other, int row, int col) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3):: operator *= (const FLOATNAME(LMatrix3) &other) { (*this) = (*this) * other; + + // bugbug can we do any optimization here? return *this; } @@ -426,19 +489,19 @@ operator *= (const FLOATNAME(LMatrix3) &other) { // Access: Public // Description: Performs a memberwise scale. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3):: operator *= (FLOATTYPE scalar) { - (*this)(0, 0) *= scalar; - (*this)(0, 1) *= scalar; - (*this)(0, 2) *= scalar; + _m.m._00 *= scalar; + _m.m._01 *= scalar; + _m.m._02 *= scalar; - (*this)(1, 0) *= scalar; - (*this)(1, 1) *= scalar; - (*this)(1, 2) *= scalar; + _m.m._10 *= scalar; + _m.m._11 *= scalar; + _m.m._12 *= scalar; - (*this)(2, 0) *= scalar; - (*this)(2, 1) *= scalar; - (*this)(2, 2) *= scalar; + _m.m._20 *= scalar; + _m.m._21 *= scalar; + _m.m._22 *= scalar; return *this; } @@ -448,19 +511,20 @@ operator *= (FLOATTYPE scalar) { // Access: Public // Description: Performs a memberwise scale. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3):: operator /= (FLOATTYPE scalar) { - (*this)(0, 0) /= scalar; - (*this)(0, 1) /= scalar; - (*this)(0, 2) /= scalar; + FLOATTYPE recip_scalar = 1.0/scalar; + _m.m._00 *= recip_scalar; + _m.m._01 *= recip_scalar; + _m.m._02 *= recip_scalar; - (*this)(1, 0) /= scalar; - (*this)(1, 1) /= scalar; - (*this)(1, 2) /= scalar; + _m.m._10 *= recip_scalar; + _m.m._11 *= recip_scalar; + _m.m._12 *= recip_scalar; - (*this)(2, 0) /= scalar; - (*this)(2, 1) /= scalar; - (*this)(2, 2) /= scalar; + _m.m._20 *= recip_scalar; + _m.m._21 *= recip_scalar; + _m.m._22 *= recip_scalar; return *this; } @@ -470,19 +534,19 @@ operator /= (FLOATTYPE scalar) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix3):: +INLINE_LINMATH void FLOATNAME(LMatrix3):: transpose_from(const FLOATNAME(LMatrix3) &other) { - (*this)(0, 0) = other(0, 0); - (*this)(0, 1) = other(1, 0); - (*this)(0, 2) = other(2, 0); + _m.m._00 = other._m.m._00; + _m.m._01 = other._m.m._10; + _m.m._02 = other._m.m._20; - (*this)(1, 0) = other(0, 1); - (*this)(1, 1) = other(1, 1); - (*this)(1, 2) = other(2, 1); + _m.m._10 = other._m.m._01; + _m.m._11 = other._m.m._11; + _m.m._12 = other._m.m._21; - (*this)(2, 0) = other(0, 2); - (*this)(2, 1) = other(1, 2); - (*this)(2, 2) = other(2, 2); + _m.m._20 = other._m.m._02; + _m.m._21 = other._m.m._12; + _m.m._22 = other._m.m._22; } @@ -491,22 +555,50 @@ transpose_from(const FLOATNAME(LMatrix3) &other) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix3):: +INLINE_LINMATH void FLOATNAME(LMatrix3):: transpose_in_place() { - FLOATNAME(LMatrix3) temp = (*this); - transpose_from(temp); +// FLOATNAME(LMatrix3) temp = (*this); +// transpose_from(temp); + + #define SWAP__(x,y) { FLOATTYPE temp = (x); (x) = (y); (y) = temp;} + SWAP__(_m.m._01,_m.m._10); + SWAP__(_m.m._02,_m.m._20); + SWAP__(_m.m._12,_m.m._21); + #undef SWAP__ +} + + +//////////////////////////////////////////////////////////////////// +// Function: LMatrix3::transpose +// Description: Transposes the given matrix and returns it. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LMatrix3) +transpose(const FLOATNAME(LMatrix3) &a) { + + FLOATNAME(LMatrix3) result; + result.transpose_from(a); + return result; } // Matrix inversion code from Numerical Recipes in C. +// dont trust compilers to inline these +#define DET2(E00,E01,E10,E11) ((E00)*(E11) - (E10)*(E01)) +#define MATRIX3_DETERMINANT(mat) \ + ( (mat)._00 * DET2((mat)._11,(mat)._12,(mat)._21,(mat)._22) \ + -(mat)._01 * DET2((mat)._10,(mat)._12,(mat)._20,(mat)._22) \ + +(mat)._01 * DET2((mat)._10,(mat)._11,(mat)._20,(mat)._21)) + + //////////////////////////////////////////////////////////////////// // Function: LMatrix3::det2 // Access: Private, Static // Description: Returns the determinant of a 2x2 matrix. //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix3):: det2(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e10, FLOATTYPE e11) const { - return (e00 * e11 - e10 * e01); +// return (e00 * e11 - e10 * e01); + return DET2(e00,e01,e10,e11); } //////////////////////////////////////////////////////////////////// @@ -514,12 +606,16 @@ det2(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e10, FLOATTYPE e11) const { // Access: Public // Description: Returns the determinant of the matrix. //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix3):: determinant() const { +/* return (*this)(0,0) * det2((*this)(1,1),(*this)(1,2),(*this)(2,1),(*this)(2,2)) -(*this)(0,1) * det2((*this)(1,0),(*this)(1,2),(*this)(2,0),(*this)(2,2)) +(*this)(0,2) * det2((*this)(1,0),(*this)(1,1),(*this)(2,0),(*this)(2,1)); +*/ + + return MATRIX3_DETERMINANT(_m.m); } //////////////////////////////////////////////////////////////////// @@ -538,29 +634,31 @@ determinant() const { // successfully inverted, false if the was a // singularity. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LMatrix3):: +INLINE_LINMATH bool FLOATNAME(LMatrix3):: invert_from(const FLOATNAME(LMatrix3) &other) { - FLOATTYPE d = other.determinant(); + + FLOATTYPE other_det = MATRIX3_DETERMINANT(other._m.m); - if (IS_NEARLY_ZERO(d)) { - linmath_cat.warning() - << "Tried to invert singular LMatrix3.\n"; + if (IS_NEARLY_ZERO(other_det)) { + #ifndef NDEBUG + linmath_cat.warning() << "Tried to invert singular LMatrix3.\n"; + #endif (*this) = ident_mat(); return false; } - d = 1.0 / d; - (*this)(0,0) = d * det2(other(1,1), other(1,2), other(2,1), other(2,2)); - (*this)(1,0) = -d * det2(other(1,0), other(1,2), other(2,0), other(2,2)); - (*this)(2,0) = d * det2(other(1,0), other(1,1), other(2,0), other(2,1)); + other_det = 1.0 / other_det; + _m.m._00 = other_det * DET2(other._m.m._11, other._m.m._12, other._m.m._21, other._m.m._22); + _m.m._10 = -other_det * DET2(other._m.m._10, other._m.m._12, other._m.m._20, other._m.m._22); + _m.m._20 = other_det * DET2(other._m.m._10, other._m.m._11, other._m.m._20, other._m.m._21); - (*this)(0,1) = -d * det2(other(0,1), other(0,2), other(2,1), other(2,2)); - (*this)(1,1) = d * det2(other(0,0), other(0,2), other(2,0), other(2,2)); - (*this)(2,1) = -d * det2(other(0,0), other(0,1), other(2,0), other(2,1)); + _m.m._01 = -other_det * DET2(other._m.m._01, other._m.m._02, other._m.m._21, other._m.m._22); + _m.m._11 = other_det * DET2(other._m.m._00, other._m.m._02, other._m.m._20, other._m.m._22); + _m.m._21 = -other_det * DET2(other._m.m._00, other._m.m._01, other._m.m._20, other._m.m._21); - (*this)(0,2) = d * det2(other(0,1), other(0,2), other(1,1), other(1,2)); - (*this)(1,2) = -d * det2(other(0,0), other(0,2), other(1,0), other(1,2)); - (*this)(2,2) = d * det2(other(0,0), other(0,1), other(1,0), other(1,1)); + _m.m._02 = other_det * DET2(other._m.m._01, other._m.m._02, other._m.m._11, other._m.m._12); + _m.m._12 = -other_det * DET2(other._m.m._00, other._m.m._02, other._m.m._10, other._m.m._12); + _m.m._22 = other_det * DET2(other._m.m._00, other._m.m._01, other._m.m._10, other._m.m._11); return true; } @@ -572,23 +670,22 @@ invert_from(const FLOATNAME(LMatrix3) &other) { // inverse is successful, false if the matrix was // singular. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LMatrix3):: +INLINE_LINMATH bool FLOATNAME(LMatrix3):: invert_in_place() { FLOATNAME(LMatrix3) temp = (*this); return invert_from(temp); } //////////////////////////////////////////////////////////////////// -// Function: LMatrix::translate_mat -// Access: Public, Static -// Description: Returns a matrix that applies the indicated -// translation. +// Function: LMatrix3::invert +// Description: Inverts the given matrix and returns it. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: -translate_mat(const FLOATNAME(LVecBase2) &trans) { - return FLOATNAME(LMatrix3)(1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - trans[0], trans[1], 1.0); +INLINE_LINMATH FLOATNAME(LMatrix3) +invert(const FLOATNAME(LMatrix3) &a) { + FLOATNAME(LMatrix3) result; + bool nonsingular = result.invert_from(a); + nassertr(nonsingular, FLOATNAME(LMatrix3)::ident_mat()); + return result; } //////////////////////////////////////////////////////////////////// @@ -597,7 +694,20 @@ translate_mat(const FLOATNAME(LVecBase2) &trans) { // Description: Returns a matrix that applies the indicated // translation. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: +translate_mat(const FLOATNAME(LVecBase2) &trans) { + return FLOATNAME(LMatrix3)(1.0, 0.0, 0.0, + 0.0, 1.0, 0.0, + trans._v.v._0, trans._v.v._1, 1.0); +} + +//////////////////////////////////////////////////////////////////// +// Function: LMatrix::translate_mat +// Access: Public, Static +// Description: Returns a matrix that applies the indicated +// translation. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: translate_mat(FLOATTYPE tx, FLOATTYPE ty) { return FLOATNAME(LMatrix3)(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, @@ -610,10 +720,10 @@ translate_mat(FLOATTYPE tx, FLOATTYPE ty) { // Description: Returns a matrix that rotates by the given angle in // degrees counterclockwise. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: rotate_mat(FLOATTYPE angle) { - double angle_rad=deg_2_rad(angle); - double s,c; + FLOATTYPE angle_rad=deg_2_rad(angle); + FLOATTYPE s,c; csincos(angle_rad,&s,&c); return FLOATNAME(LMatrix3)( c, s, 0.0, -s, c, 0.0, @@ -626,10 +736,10 @@ rotate_mat(FLOATTYPE angle) { // Description: Returns a matrix that applies the indicated // scale in each of the two axes. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: scale_mat(const FLOATNAME(LVecBase2) &scale) { - return FLOATNAME(LMatrix3)(scale[0], 0.0, 0.0, - 0.0, scale[1], 0.0, + return FLOATNAME(LMatrix3)(scale._v.v._0, 0.0, 0.0, + 0.0, scale._v.v._1, 0.0, 0.0, 0.0, 1.0); } @@ -639,7 +749,7 @@ scale_mat(const FLOATNAME(LVecBase2) &scale) { // Description: Returns a matrix that applies the indicated // scale in each of the two axes. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: scale_mat(FLOATTYPE sx, FLOATTYPE sy) { return FLOATNAME(LMatrix3)(sx, 0.0, 0.0, 0.0, sy, 0.0, @@ -652,42 +762,71 @@ scale_mat(FLOATTYPE sx, FLOATTYPE sy) { // Description: Returns a matrix that rotates by the given angle in // degrees counterclockwise about the indicated vector. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: -rotate_mat(FLOATTYPE angle, FLOATNAME(LVecBase3) axis, +INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: +rotate_mat(FLOATTYPE angle, FLOATNAME(LVecBase3) &axis, CoordinateSystem cs) { if (cs == CS_default) { cs = default_coordinate_system; } FLOATNAME(LMatrix3) mat; - if (!is_right_handed(cs)) { + if(IS_LEFT_HANDED_COORDSYSTEM(cs)) { // In a left-handed coordinate system, counterclockwise is the // other direction. angle = -angle; } + FLOATTYPE axis_0 = axis._v.v._0; + FLOATTYPE axis_1 = axis._v.v._1; + FLOATTYPE axis_2 = axis._v.v._2; + // Normalize the axis. - FLOATTYPE length = axis.dot(axis); - nassertr(length != 0.0, ident_mat()); - FLOATTYPE recip_length=1.0f/length; + FLOATTYPE length_sq = axis_0 * axis_0 + axis_1 * axis_1 + axis_2 * axis_2; + #ifdef _DEBUG + nassertr(length_sq != 0.0, ident_mat()); + #endif + FLOATTYPE recip_length=1.0f/csqrt(length_sq); axis *= recip_length; - double angle_rad=deg_2_rad(angle); - double s,c; + FLOATTYPE angle_rad=deg_2_rad(angle); + FLOATTYPE s,c; csincos(angle_rad,&s,&c); - double t = 1.0 - c; + FLOATTYPE t = 1.0 - c; - mat(0, 0) = t * axis[0] * axis[0] + c; - mat(0, 1) = t * axis[0] * axis[1] + s * axis[2]; - mat(0, 2) = t * axis[0] * axis[2] - s * axis[1]; + FLOATTYPE t0,t1,t2,s0,s1,s2; - mat(1, 0) = t * axis[1] * axis[0] - s * axis[2]; - mat(1, 1) = t * axis[1] * axis[1] + c; - mat(1, 2) = t * axis[1] * axis[2] + s * axis[0]; + t0 = t * axis_0; + t1 = t * axis_1; + t2 = t * axis_2; + s0 = s * axis_0; + s1 = s * axis_1; + s2 = s * axis_2; - mat(2, 0) = t * axis[2] * axis[0] + s * axis[1]; - mat(2, 1) = t * axis[2] * axis[1] - s * axis[0]; - mat(2, 2) = t * axis[2] * axis[2] + c; + mat._m.m._00 = t0 * axis_0 + c; + mat._m.m._01 = t0 * axis_1 + s2; + mat._m.m._02 = t0 * axis_2 - s1; + + mat._m.m._10 = t1 * axis_0 - s2; + mat._m.m._11 = t1 * axis_1 + c; + mat._m.m._12 = t1 * axis_2 + s0; + + mat._m.m._20 = t2 * axis_0 + s1; + mat._m.m._21 = t2 * axis_1 - s0; + mat._m.m._22 = t2 * axis_2 + c; + +/* + mat._m.m._00 = t * axis._v.v._0 * axis._v.v._0 + c; + mat._m.m._01 = t * axis._v.v._0 * axis._v.v._1 + s * axis._v.v._2; + mat._m.m._02 = t * axis._v.v._0 * axis._v.v._2 - s * axis._v.v._1; + + mat._m.m._10 = t * axis._v.v._1 * axis._v.v._0 - s * axis._v.v._2; + mat._m.m._11 = t * axis._v.v._1 * axis._v.v._1 + c; + mat._m.m._12 = t * axis._v.v._1 * axis._v.v._2 + s * axis._v.v._0; + + mat._m.m._20 = t * axis._v.v._2 * axis._v.v._0 + s * axis._v.v._1; + mat._m.m._21 = t * axis._v.v._2 * axis._v.v._1 - s * axis._v.v._0; + mat._m.m._22 = t * axis._v.v._2 * axis._v.v._2 + c; +*/ return mat; } @@ -698,11 +837,11 @@ rotate_mat(FLOATTYPE angle, FLOATNAME(LVecBase3) axis, // Description: Returns a matrix that applies the indicated // scale in each of the three axes. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: scale_mat(const FLOATNAME(LVecBase3) &scale) { return FLOATNAME(LMatrix3)(scale[0], 0.0, 0.0, - 0.0, scale[1], 0.0, - 0.0, 0.0, scale[2]); + 0.0, scale._v.v._1, 0.0, + 0.0, 0.0, scale._v.v._2); } //////////////////////////////////////////////////////////////////// @@ -711,7 +850,7 @@ scale_mat(const FLOATNAME(LVecBase3) &scale) { // Description: Returns a matrix that applies the indicated // scale in each of the three axes. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: scale_mat(FLOATTYPE sx, FLOATTYPE sy, FLOATTYPE sz) { return FLOATNAME(LMatrix3)(sx, 0.0, 0.0, 0.0, sy, 0.0, @@ -724,7 +863,7 @@ scale_mat(FLOATTYPE sx, FLOATTYPE sy, FLOATTYPE sz) { // Description: Returns true if two matrices are memberwise equal // within a default tolerance based on the numeric type. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LMatrix3):: +INLINE_LINMATH bool FLOATNAME(LMatrix3):: almost_equal(const FLOATNAME(LMatrix3) &other) const { return almost_equal(other, NEARLY_ZERO(FLOATTYPE)); } @@ -734,80 +873,90 @@ almost_equal(const FLOATNAME(LMatrix3) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix3):: +INLINE_LINMATH void FLOATNAME(LMatrix3):: output(ostream &out) const { out << "[ " - << MAYBE_ZERO((*this)(0, 0)) << " " - << MAYBE_ZERO((*this)(0, 1)) << " " - << MAYBE_ZERO((*this)(0, 2)) + << MAYBE_ZERO(_m.m._00) << " " + << MAYBE_ZERO(_m.m._01) << " " + << MAYBE_ZERO(_m.m._02) << " ] [ " - << MAYBE_ZERO((*this)(1, 0)) << " " - << MAYBE_ZERO((*this)(1, 1)) << " " - << MAYBE_ZERO((*this)(1, 2)) + << MAYBE_ZERO(_m.m._10) << " " + << MAYBE_ZERO(_m.m._11) << " " + << MAYBE_ZERO(_m.m._12) << " ] [ " - << MAYBE_ZERO((*this)(2, 0)) << " " - << MAYBE_ZERO((*this)(2, 1)) << " " - << MAYBE_ZERO((*this)(2, 2)) + << MAYBE_ZERO(_m.m._20) << " " + << MAYBE_ZERO(_m.m._21) << " " + << MAYBE_ZERO(_m.m._22) << " ]"; } -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::transpose -// Description: Transposes the given matrix and returns it. -//////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) -transpose(const FLOATNAME(LMatrix3) &a) { - FLOATNAME(LMatrix3) result; - result.transpose_from(a); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: LMatrix3::invert -// Description: Inverts the given matrix and returns it. -//////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) -invert(const FLOATNAME(LMatrix3) &a) { - FLOATNAME(LMatrix3) result; - bool nonsingular = result.invert_from(a); - nassertr(nonsingular, FLOATNAME(LMatrix3)::ident_mat()); - return result; -} - //////////////////////////////////////////////////////////////////// // Function: LMatrix3::write // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix3):: +INLINE_LINMATH void FLOATNAME(LMatrix3):: write(ostream &out, int indent_level) const { indent(out, indent_level) - << MAYBE_ZERO((*this)(0, 0)) << " " - << MAYBE_ZERO((*this)(0, 1)) << " " - << MAYBE_ZERO((*this)(0, 2)) + << MAYBE_ZERO(_m.m._00) << " " + << MAYBE_ZERO(_m.m._01) << " " + << MAYBE_ZERO(_m.m._02) << "\n"; indent(out, indent_level) - << MAYBE_ZERO((*this)(1, 0)) << " " - << MAYBE_ZERO((*this)(1, 1)) << " " - << MAYBE_ZERO((*this)(1, 2)) + << MAYBE_ZERO(_m.m._10) << " " + << MAYBE_ZERO(_m.m._11) << " " + << MAYBE_ZERO(_m.m._12) << "\n"; indent(out, indent_level) - << MAYBE_ZERO((*this)(2, 0)) << " " - << MAYBE_ZERO((*this)(2, 1)) << " " - << MAYBE_ZERO((*this)(2, 2)) + << MAYBE_ZERO(_m.m._20) << " " + << MAYBE_ZERO(_m.m._21) << " " + << MAYBE_ZERO(_m.m._22) << "\n"; } +#define MATRIX3_PRODUCT(res, a, b) \ +res._m.m._00 = a._m.m._00*b._m.m._00 + a._m.m._01*b._m.m._10 + a._m.m._02*b._m.m._20; \ +res._m.m._01 = a._m.m._00*b._m.m._01 + a._m.m._01*b._m.m._11 + a._m.m._02*b._m.m._21; \ +res._m.m._02 = a._m.m._00*b._m.m._02 + a._m.m._01*b._m.m._12 + a._m.m._02*b._m.m._22; \ +res._m.m._10 = a._m.m._10*b._m.m._00 + a._m.m._11*b._m.m._10 + a._m.m._12*b._m.m._20; \ +res._m.m._11 = a._m.m._10*b._m.m._01 + a._m.m._11*b._m.m._11 + a._m.m._12*b._m.m._21; \ +res._m.m._12 = a._m.m._10*b._m.m._02 + a._m.m._11*b._m.m._12 + a._m.m._12*b._m.m._22; \ +res._m.m._20 = a._m.m._20*b._m.m._00 + a._m.m._21*b._m.m._10 + a._m.m._22*b._m.m._20; \ +res._m.m._21 = a._m.m._20*b._m.m._01 + a._m.m._21*b._m.m._11 + a._m.m._22*b._m.m._21; \ +res._m.m._22 = a._m.m._20*b._m.m._02 + a._m.m._21*b._m.m._12 + a._m.m._22*b._m.m._22; + + //////////////////////////////////////////////////////////////////// // Function: LMatrix3::matrix * matrix // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: operator * (const FLOATNAME(LMatrix3) &other) const { - FLOATNAME(LMatrix3) t; + FLOATNAME(LMatrix3) t; + MATRIX3_PRODUCT(t,(*this),other); +/* +typedef union { + struct { + FLOATTYPE _m.m._11, _m.m._12, _m.m._13; + FLOATTYPE _m.m._21, _m.m._22, _m.m._23; + FLOATTYPE _m.m._31, _m.m._32, _m.m._33; + }; + + FLOATTYPE m[3][3]; + } MYMATRIX3; + + FLOATNAME(LMatrix3) t; + + MYMATRIX3 *result_ptr=(MYMATRIX3 *)t.get_m.data(); + MYMATRIX3 *mat1_ptr=(MYMATRIX3 *)this->get_m.data(); + MYMATRIX3 *mat2_ptr=(MYMATRIX3 *)other.get_m.data(); + + MATRIX3_PRODUCT(result_ptr,mat1_ptr,mat2_ptr); +*/ +/* t(0, 0) = mult_cel(other, 0, 0); t(0, 1) = mult_cel(other, 0, 1); t(0, 2) = mult_cel(other, 0, 2); @@ -819,7 +968,7 @@ operator * (const FLOATNAME(LMatrix3) &other) const { t(2, 0) = mult_cel(other, 2, 0); t(2, 1) = mult_cel(other, 2, 1); t(2, 2) = mult_cel(other, 2, 2); - +*/ return t; } @@ -828,21 +977,21 @@ operator * (const FLOATNAME(LMatrix3) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: operator * (FLOATTYPE scalar) const { FLOATNAME(LMatrix3) t; - t(0, 0) = (*this)(0, 0) * scalar; - t(0, 1) = (*this)(0, 1) * scalar; - t(0, 2) = (*this)(0, 2) * scalar; + t._m.m._00 = _m.m._00 * scalar; + t._m.m._01 = _m.m._01 * scalar; + t._m.m._02 = _m.m._02 * scalar; - t(1, 0) = (*this)(1, 0) * scalar; - t(1, 1) = (*this)(1, 1) * scalar; - t(1, 2) = (*this)(1, 2) * scalar; + t._m.m._10 = _m.m._10 * scalar; + t._m.m._11 = _m.m._11 * scalar; + t._m.m._12 = _m.m._12 * scalar; - t(2, 0) = (*this)(2, 0) * scalar; - t(2, 1) = (*this)(2, 1) * scalar; - t(2, 2) = (*this)(2, 2) * scalar; + t._m.m._20 = _m.m._20 * scalar; + t._m.m._21 = _m.m._21 * scalar; + t._m.m._22 = _m.m._22 * scalar; return t; } @@ -852,23 +1001,12 @@ operator * (FLOATTYPE scalar) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3):: operator / (FLOATTYPE scalar) const { FLOATNAME(LMatrix3) t; - t(0, 0) = (*this)(0, 0) / scalar; - t(0, 1) = (*this)(0, 1) / scalar; - t(0, 2) = (*this)(0, 2) / scalar; - - t(1, 0) = (*this)(1, 0) / scalar; - t(1, 1) = (*this)(1, 1) / scalar; - t(1, 2) = (*this)(1, 2) / scalar; - - t(2, 0) = (*this)(2, 0) / scalar; - t(2, 1) = (*this)(2, 1) / scalar; - t(2, 2) = (*this)(2, 2) / scalar; - - return t; + FLOATTYPE recip_scalar = 1.0/scalar; + return (*this) * recip_scalar; } //////////////////////////////////////////////////////////////////// @@ -876,19 +1014,19 @@ operator / (FLOATTYPE scalar) const { // Access: Public // Description: Performs a memberwise addition between two matrices. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3):: operator += (const FLOATNAME(LMatrix3) &other) { - (*this)(0, 0) += other(0, 0); - (*this)(0, 1) += other(0, 1); - (*this)(0, 2) += other(0, 2); + _m.m._00 += other._m.m._00; + _m.m._01 += other._m.m._01; + _m.m._02 += other._m.m._02; - (*this)(1, 0) += other(1, 0); - (*this)(1, 1) += other(1, 1); - (*this)(1, 2) += other(1, 2); + _m.m._10 += other._m.m._10; + _m.m._11 += other._m.m._11; + _m.m._12 += other._m.m._12; - (*this)(2, 0) += other(2, 0); - (*this)(2, 1) += other(2, 1); - (*this)(2, 2) += other(2, 2); + _m.m._20 += other._m.m._20; + _m.m._21 += other._m.m._21; + _m.m._22 += other._m.m._22; return *this; } @@ -898,19 +1036,19 @@ operator += (const FLOATNAME(LMatrix3) &other) { // Access: Public // Description: Performs a memberwise subtraction between two matrices. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3):: +INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3):: operator -= (const FLOATNAME(LMatrix3) &other) { - (*this)(0, 0) -= other(0, 0); - (*this)(0, 1) -= other(0, 1); - (*this)(0, 2) -= other(0, 2); + _m.m._00 -= other._m.m._00; + _m.m._01 -= other._m.m._01; + _m.m._02 -= other._m.m._02; - (*this)(1, 0) -= other(1, 0); - (*this)(1, 1) -= other(1, 1); - (*this)(1, 2) -= other(1, 2); + _m.m._10 -= other._m.m._10; + _m.m._11 -= other._m.m._11; + _m.m._12 -= other._m.m._12; - (*this)(2, 0) -= other(2, 0); - (*this)(2, 1) -= other(2, 1); - (*this)(2, 2) -= other(2, 2); + _m.m._20 -= other._m.m._20; + _m.m._21 -= other._m.m._21; + _m.m._22 -= other._m.m._22; return *this; } diff --git a/panda/src/linmath/lmatrix3_src.cxx b/panda/src/linmath/lmatrix3_src.cxx index 284964cf18..c7445fa477 100644 --- a/panda/src/linmath/lmatrix3_src.cxx +++ b/panda/src/linmath/lmatrix3_src.cxx @@ -36,8 +36,8 @@ fill(FLOATTYPE fill_value) { int FLOATNAME(LMatrix3):: compare_to(const FLOATNAME(LMatrix3) &other, FLOATTYPE threshold) const { for (int i = 0; i < 9; i++) { - if (!IS_THRESHOLD_EQUAL(_data[i], other._data[i], threshold)) { - return (_data[i] < other._data[i]) ? -1 : 1; + if (!IS_THRESHOLD_EQUAL(_m.data[i], other._m.data[i], threshold)) { + return (_m.data[i] < other._m.data[i]) ? -1 : 1; } } return 0; diff --git a/panda/src/linmath/lmatrix3_src.h b/panda/src/linmath/lmatrix3_src.h index 988ca10169..d346c16ec0 100644 --- a/panda/src/linmath/lmatrix3_src.h +++ b/panda/src/linmath/lmatrix3_src.h @@ -16,87 +16,87 @@ PUBLISHED: typedef const FLOATTYPE *iterator; typedef const FLOATTYPE *const_iterator; - INLINE FLOATNAME(LMatrix3)(); - INLINE FLOATNAME(LMatrix3)(const FLOATNAME(LMatrix3) &other); - INLINE FLOATNAME(LMatrix3) &operator = (const FLOATNAME(LMatrix3) &other); - INLINE FLOATNAME(LMatrix3) &operator = (FLOATTYPE fill_value); - INLINE FLOATNAME(LMatrix3)(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, + INLINE_LINMATH FLOATNAME(LMatrix3)(); + INLINE_LINMATH FLOATNAME(LMatrix3)(const FLOATNAME(LMatrix3) &other); + INLINE_LINMATH FLOATNAME(LMatrix3) &operator = (const FLOATNAME(LMatrix3) &other); + INLINE_LINMATH FLOATNAME(LMatrix3) &operator = (FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LMatrix3)(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12, FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22); void fill(FLOATTYPE fill_value); - INLINE void set(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, + INLINE_LINMATH void set(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12, FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22); - INLINE void set_row(int row, const FLOATNAME(LVecBase3) &v); - INLINE void set_col(int col, const FLOATNAME(LVecBase3) &v); + INLINE_LINMATH void set_row(int row, const FLOATNAME(LVecBase3) &v); + INLINE_LINMATH void set_col(int col, const FLOATNAME(LVecBase3) &v); - INLINE void set_row(int row, const FLOATNAME(LVecBase2) &v); - INLINE void set_col(int col, const FLOATNAME(LVecBase2) &v); + INLINE_LINMATH void set_row(int row, const FLOATNAME(LVecBase2) &v); + INLINE_LINMATH void set_col(int col, const FLOATNAME(LVecBase2) &v); - INLINE FLOATNAME(LVecBase3) get_row(int row) const; - INLINE FLOATNAME(LVecBase3) get_col(int col) const; + INLINE_LINMATH FLOATNAME(LVecBase3) get_row(int row) const; + INLINE_LINMATH FLOATNAME(LVecBase3) get_col(int col) const; - INLINE FLOATNAME(LVecBase2) get_row2(int row) const; - INLINE FLOATNAME(LVecBase2) get_col2(int col) const; + INLINE_LINMATH FLOATNAME(LVecBase2) get_row2(int row) const; + INLINE_LINMATH FLOATNAME(LVecBase2) get_col2(int col) const; - INLINE FLOATTYPE &operator () (int row, int col); - INLINE FLOATTYPE operator () (int row, int col) const; + INLINE_LINMATH FLOATTYPE &operator () (int row, int col); + INLINE_LINMATH FLOATTYPE operator () (int row, int col) const; - INLINE bool is_nan() const; + INLINE_LINMATH bool is_nan() const; - INLINE FLOATTYPE get_cell(int row, int col) const; - INLINE void set_cell(int row, int col, FLOATTYPE value); + INLINE_LINMATH FLOATTYPE get_cell(int row, int col) const; + INLINE_LINMATH void set_cell(int row, int col, FLOATTYPE value); - INLINE const FLOATTYPE *get_data() const; - INLINE int get_num_components() const; + INLINE_LINMATH const FLOATTYPE *get_data() const; + INLINE_LINMATH int get_num_components() const; public: - INLINE iterator begin(); - INLINE iterator end(); + INLINE_LINMATH iterator begin(); + INLINE_LINMATH iterator end(); - INLINE const_iterator begin() const; - INLINE const_iterator end() const; + INLINE_LINMATH const_iterator begin() const; + INLINE_LINMATH const_iterator end() const; PUBLISHED: - INLINE bool operator < (const FLOATNAME(LMatrix3) &other) const; - INLINE bool operator == (const FLOATNAME(LMatrix3) &other) const; - INLINE bool operator != (const FLOATNAME(LMatrix3) &other) const; + INLINE_LINMATH bool operator < (const FLOATNAME(LMatrix3) &other) const; + INLINE_LINMATH bool operator == (const FLOATNAME(LMatrix3) &other) const; + INLINE_LINMATH bool operator != (const FLOATNAME(LMatrix3) &other) const; - INLINE int compare_to(const FLOATNAME(LMatrix3) &other) const; + INLINE_LINMATH int compare_to(const FLOATNAME(LMatrix3) &other) const; int compare_to(const FLOATNAME(LMatrix3) &other, FLOATTYPE threshold) const; - INLINE FLOATNAME(LVecBase3) + INLINE_LINMATH FLOATNAME(LVecBase3) xform(const FLOATNAME(LVecBase3) &v) const; - INLINE FLOATNAME(LVecBase2) + INLINE_LINMATH FLOATNAME(LVecBase2) xform_point(const FLOATNAME(LVecBase2) &v) const; - INLINE FLOATNAME(LVecBase2) + INLINE_LINMATH FLOATNAME(LVecBase2) xform_vec(const FLOATNAME(LVecBase2) &v) const; - INLINE FLOATNAME(LMatrix3) operator * (const FLOATNAME(LMatrix3) &other) const; - INLINE FLOATNAME(LMatrix3) operator * (FLOATTYPE scalar) const; - INLINE FLOATNAME(LMatrix3) operator / (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATNAME(LMatrix3) operator * (const FLOATNAME(LMatrix3) &other) const; + INLINE_LINMATH FLOATNAME(LMatrix3) operator * (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATNAME(LMatrix3) operator / (FLOATTYPE scalar) const; - INLINE FLOATNAME(LMatrix3) &operator += (const FLOATNAME(LMatrix3) &other); - INLINE FLOATNAME(LMatrix3) &operator -= (const FLOATNAME(LMatrix3) &other); + INLINE_LINMATH FLOATNAME(LMatrix3) &operator += (const FLOATNAME(LMatrix3) &other); + INLINE_LINMATH FLOATNAME(LMatrix3) &operator -= (const FLOATNAME(LMatrix3) &other); - INLINE FLOATNAME(LMatrix3) &operator *= (const FLOATNAME(LMatrix3) &other); + INLINE_LINMATH FLOATNAME(LMatrix3) &operator *= (const FLOATNAME(LMatrix3) &other); - INLINE FLOATNAME(LMatrix3) &operator *= (FLOATTYPE scalar); - INLINE FLOATNAME(LMatrix3) &operator /= (FLOATTYPE scalar); + INLINE_LINMATH FLOATNAME(LMatrix3) &operator *= (FLOATTYPE scalar); + INLINE_LINMATH FLOATNAME(LMatrix3) &operator /= (FLOATTYPE scalar); - INLINE FLOATTYPE determinant() const; + INLINE_LINMATH FLOATTYPE determinant() const; - INLINE void transpose_from(const FLOATNAME(LMatrix3) &other); - INLINE void transpose_in_place(); + INLINE_LINMATH void transpose_from(const FLOATNAME(LMatrix3) &other); + INLINE_LINMATH void transpose_in_place(); - INLINE bool invert_from(const FLOATNAME(LMatrix3) &other); - INLINE bool invert_in_place(); + INLINE_LINMATH bool invert_from(const FLOATNAME(LMatrix3) &other); + INLINE_LINMATH bool invert_in_place(); - static INLINE const FLOATNAME(LMatrix3) &ident_mat(); + static INLINE_LINMATH const FLOATNAME(LMatrix3) &ident_mat(); // A 3x3 matrix is likely to be used for one of two purposes. In // 2-d coordinate space (e.g. texture or surface coordinates), it @@ -108,19 +108,19 @@ PUBLISHED: // The following named constructors return 3x3 matrices suitable for // affine transforms in 2-d coordinate space. - static INLINE FLOATNAME(LMatrix3) translate_mat(const FLOATNAME(LVecBase2) &trans); - static INLINE FLOATNAME(LMatrix3) translate_mat(FLOATTYPE tx, FLOATTYPE ty); - static INLINE FLOATNAME(LMatrix3) rotate_mat(FLOATTYPE angle); - static INLINE FLOATNAME(LMatrix3) scale_mat(const FLOATNAME(LVecBase2) &scale); - static INLINE FLOATNAME(LMatrix3) scale_mat(FLOATTYPE sx, FLOATTYPE sy); + static INLINE_LINMATH FLOATNAME(LMatrix3) translate_mat(const FLOATNAME(LVecBase2) &trans); + static INLINE_LINMATH FLOATNAME(LMatrix3) translate_mat(FLOATTYPE tx, FLOATTYPE ty); + static INLINE_LINMATH FLOATNAME(LMatrix3) rotate_mat(FLOATTYPE angle); + static INLINE_LINMATH FLOATNAME(LMatrix3) scale_mat(const FLOATNAME(LVecBase2) &scale); + static INLINE_LINMATH FLOATNAME(LMatrix3) scale_mat(FLOATTYPE sx, FLOATTYPE sy); // The following named constructors return 3x3 matrices suitable for // scale/rotate transforms in 3-d coordinate space. - static INLINE FLOATNAME(LMatrix3) rotate_mat(FLOATTYPE angle, - FLOATNAME(LVecBase3) axis, + static INLINE_LINMATH FLOATNAME(LMatrix3) rotate_mat(FLOATTYPE angle, + FLOATNAME(LVecBase3) &axis, CoordinateSystem cs = CS_default); - static INLINE FLOATNAME(LMatrix3) scale_mat(const FLOATNAME(LVecBase3) &scale); - static INLINE FLOATNAME(LMatrix3) scale_mat(FLOATTYPE sx, FLOATTYPE sy, FLOATTYPE sz); + static INLINE_LINMATH FLOATNAME(LMatrix3) scale_mat(const FLOATNAME(LVecBase3) &scale); + static INLINE_LINMATH FLOATNAME(LMatrix3) scale_mat(FLOATTYPE sx, FLOATTYPE sy, FLOATTYPE sz); // We don't have a scale_mat() that takes a single uniform scale // parameter, because it would be ambiguous whether we mean a 2-d or @@ -129,16 +129,27 @@ PUBLISHED: bool almost_equal(const FLOATNAME(LMatrix3) &other, FLOATTYPE threshold) const; - INLINE bool almost_equal(const FLOATNAME(LMatrix3) &other) const; + INLINE_LINMATH bool almost_equal(const FLOATNAME(LMatrix3) &other) const; - INLINE void output(ostream &out) const; - INLINE void write(ostream &out, int indent_level = 0) const; + INLINE_LINMATH void output(ostream &out) const; + INLINE_LINMATH void write(ostream &out, int indent_level = 0) const; + +public: + + union { + struct { + FLOATTYPE _00, _01, _02; + FLOATTYPE _10, _11, _12; + FLOATTYPE _20, _21, _22; + } m; + + FLOATTYPE data[3 * 3]; + } _m; private: - INLINE FLOATTYPE mult_cel(const FLOATNAME(LMatrix3) &other, int x, int y) const; - INLINE FLOATTYPE det2(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e10, FLOATTYPE e11) const; + INLINE_LINMATH FLOATTYPE mult_cel(const FLOATNAME(LMatrix3) &other, int x, int y) const; + INLINE_LINMATH FLOATTYPE det2(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e10, FLOATTYPE e11) const; - FLOATTYPE _data[3 * 3]; static FLOATNAME(LMatrix3) _ident_mat; //Functionality for reading and writing from/to a binary source @@ -157,12 +168,12 @@ private: }; -INLINE ostream &operator << (ostream &out, const FLOATNAME(LMatrix3) &mat) { +INLINE_LINMATH ostream &operator << (ostream &out, const FLOATNAME(LMatrix3) &mat) { mat.output(out); return out; } -INLINE FLOATNAME(LMatrix3) transpose(const FLOATNAME(LMatrix3) &a); -INLINE FLOATNAME(LMatrix3) invert(const FLOATNAME(LMatrix3) &a); +INLINE_LINMATH FLOATNAME(LMatrix3) transpose(const FLOATNAME(LMatrix3) &a); +INLINE_LINMATH FLOATNAME(LMatrix3) invert(const FLOATNAME(LMatrix3) &a); #include "lmatrix3_src.I" diff --git a/panda/src/linmath/lmatrix4_src.I b/panda/src/linmath/lmatrix4_src.I index bf1591984e..bb420adb32 100644 --- a/panda/src/linmath/lmatrix4_src.I +++ b/panda/src/linmath/lmatrix4_src.I @@ -11,7 +11,7 @@ // This function definition must appear first, since // some inline functions below take advantage of it. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4):: +INLINE_LINMATH const FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4):: ident_mat() { return _ident_mat; } @@ -21,7 +21,7 @@ ident_mat() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4):: FLOATNAME(LMatrix4)() { } @@ -30,9 +30,10 @@ FLOATNAME(LMatrix4)() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4):: FLOATNAME(LMatrix4)(const FLOATNAME(LMatrix4) ©) { - (*this) = copy; + memcpy(_m.data,copy._m.data,sizeof(_m.data)); +// (*this) = copy; } //////////////////////////////////////////////////////////////////// @@ -40,13 +41,16 @@ FLOATNAME(LMatrix4)(const FLOATNAME(LMatrix4) ©) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4):: operator = (const FLOATNAME(LMatrix4) ©) { - set(copy(0, 0), copy(0, 1), copy(0, 2), copy(0, 3), - copy(1, 0), copy(1, 1), copy(1, 2), copy(1, 3), - copy(2, 0), copy(2, 1), copy(2, 2), copy(2, 3), - copy(3, 0), copy(3, 1), copy(3, 2), copy(3, 3)); + //xxx888 + memcpy(_m.data,copy._m.data,sizeof(_m.data)); +// set(copy(0, 0), copy(0, 1), copy(0, 2), copy(0, 3), +// copy(1, 0), copy(1, 1), copy(1, 2), copy(1, 3), +// copy(2, 0), copy(2, 1), copy(2, 2), copy(2, 3), +// copy(3, 0), copy(3, 1), copy(3, 2), copy(3, 3)); return *this; + //xxx000 } //////////////////////////////////////////////////////////////////// @@ -54,7 +58,7 @@ operator = (const FLOATNAME(LMatrix4) ©) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4):: operator = (FLOATTYPE fill_value) { fill(fill_value); return *this; @@ -65,15 +69,31 @@ operator = (FLOATTYPE fill_value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4):: FLOATNAME(LMatrix4)(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, FLOATTYPE e03, FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12, FLOATTYPE e13, FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22, FLOATTYPE e23, FLOATTYPE e30, FLOATTYPE e31, FLOATTYPE e32, FLOATTYPE e33) { - set(e00, e01, e02, e03, - e10, e11, e12, e13, - e20, e21, e22, e23, - e30, e31, e32, e33); + + _m.m._00 = e00; + _m.m._01 = e01; + _m.m._02 = e02; + _m.m._03 = e03; + + _m.m._10 = e10; + _m.m._11 = e11; + _m.m._12 = e12; + _m.m._13 = e13; + + _m.m._20 = e20; + _m.m._21 = e21; + _m.m._22 = e22; + _m.m._23 = e23; + + _m.m._30 = e30; + _m.m._31 = e31; + _m.m._32 = e32; + _m.m._33 = e33; } //////////////////////////////////////////////////////////////////// @@ -81,12 +101,33 @@ FLOATNAME(LMatrix4)(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, FLOATTYPE e03, // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4):: FLOATNAME(LMatrix4)(const FLOATNAME(LMatrix3) &upper3) { - set(upper3(0, 0), upper3(0, 1), upper3(0, 2), 0.0, - upper3(1, 0), upper3(1, 1), upper3(1, 2), 0.0, - upper3(2, 0), upper3(2, 1), upper3(2, 2), 0.0, - 0.0, 0.0, 0.0, 1.0); + + _m.m._00 = upper3._m.m._00; + _m.m._01 = upper3._m.m._01; + _m.m._02 = upper3._m.m._02; + _m.m._03 = 0.0; + + _m.m._10 = upper3._m.m._10; + _m.m._11 = upper3._m.m._11; + _m.m._12 = upper3._m.m._12; + _m.m._13 = 0.0; + + _m.m._20 = upper3._m.m._20; + _m.m._21 = upper3._m.m._21; + _m.m._22 = upper3._m.m._22; + _m.m._23 = 0.0; + + _m.m._30 = 0.0; + _m.m._31 = 0.0; + _m.m._32 = 0.0; + _m.m._33 = 1.0; + +// set(upper3(0, 0), upper3(0, 1), upper3(0, 2), 0.0, +// upper3(1, 0), upper3(1, 1), upper3(1, 2), 0.0, +// upper3(2, 0), upper3(2, 1), upper3(2, 2), 0.0, +// 0.0, 0.0, 0.0, 1.0); } //////////////////////////////////////////////////////////////////// @@ -94,13 +135,34 @@ FLOATNAME(LMatrix4)(const FLOATNAME(LMatrix3) &upper3) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4):: FLOATNAME(LMatrix4)(const FLOATNAME(LMatrix3) &upper3, const FLOATNAME(LVecBase3) &trans) { - set(upper3(0, 0), upper3(0, 1), upper3(0, 2), 0.0, - upper3(1, 0), upper3(1, 1), upper3(1, 2), 0.0, - upper3(2, 0), upper3(2, 1), upper3(2, 2), 0.0, - trans[0], trans[1], trans[2], 1.0); + + _m.m._00 = upper3._m.m._00; + _m.m._01 = upper3._m.m._01; + _m.m._02 = upper3._m.m._02; + _m.m._03 = 0.0; + + _m.m._10 = upper3._m.m._10; + _m.m._11 = upper3._m.m._11; + _m.m._12 = upper3._m.m._12; + _m.m._13 = 0.0; + + _m.m._20 = upper3._m.m._20; + _m.m._21 = upper3._m.m._21; + _m.m._22 = upper3._m.m._22; + _m.m._23 = 0.0; + + _m.m._30 = trans._v.v._0; + _m.m._31 = trans._v.v._1; + _m.m._32 = trans._v.v._2; + _m.m._33 = 1.0; + +// set(upper3(0, 0), upper3(0, 1), upper3(0, 2), 0.0, +// upper3(1, 0), upper3(1, 1), upper3(1, 2), 0.0, +// upper3(2, 0), upper3(2, 1), upper3(2, 2), 0.0, +// trans[0], trans[1], trans[2], 1.0); } //////////////////////////////////////////////////////////////////// @@ -110,7 +172,7 @@ FLOATNAME(LMatrix4)(const FLOATNAME(LMatrix3) &upper3, // fill_value. This is of questionable value, but is // sometimes useful when initializing to zero. //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix4):: +INLINE_LINMATH void FLOATNAME(LMatrix4):: fill(FLOATTYPE fill_value) { set(fill_value, fill_value, fill_value, fill_value, fill_value, fill_value, fill_value, fill_value, @@ -123,30 +185,31 @@ fill(FLOATTYPE fill_value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix4):: +INLINE_LINMATH void FLOATNAME(LMatrix4):: set(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, FLOATTYPE e03, FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12, FLOATTYPE e13, FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22, FLOATTYPE e23, FLOATTYPE e30, FLOATTYPE e31, FLOATTYPE e32, FLOATTYPE e33) { - (*this)(0, 0) = e00; - (*this)(0, 1) = e01; - (*this)(0, 2) = e02; - (*this)(0, 3) = e03; - (*this)(1, 0) = e10; - (*this)(1, 1) = e11; - (*this)(1, 2) = e12; - (*this)(1, 3) = e13; + _m.m._00 = e00; + _m.m._01 = e01; + _m.m._02 = e02; + _m.m._03 = e03; - (*this)(2, 0) = e20; - (*this)(2, 1) = e21; - (*this)(2, 2) = e22; - (*this)(2, 3) = e23; + _m.m._10 = e10; + _m.m._11 = e11; + _m.m._12 = e12; + _m.m._13 = e13; - (*this)(3, 0) = e30; - (*this)(3, 1) = e31; - (*this)(3, 2) = e32; - (*this)(3, 3) = e33; + _m.m._20 = e20; + _m.m._21 = e21; + _m.m._22 = e22; + _m.m._23 = e23; + + _m.m._30 = e30; + _m.m._31 = e31; + _m.m._32 = e32; + _m.m._33 = e33; } //////////////////////////////////////////////////////////////////// @@ -154,19 +217,19 @@ set(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, FLOATTYPE e03, // Access: Public // Description: Sets the upper 3x3 submatrix. //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix4):: +INLINE_LINMATH void FLOATNAME(LMatrix4):: set_upper_3(const FLOATNAME(LMatrix3) &upper3) { - (*this)(0, 0) = upper3(0, 0); - (*this)(0, 1) = upper3(0, 1); - (*this)(0, 2) = upper3(0, 2); + _m.m._00 = upper3(0, 0); + _m.m._01 = upper3(0, 1); + _m.m._02 = upper3(0, 2); - (*this)(1, 0) = upper3(1, 0); - (*this)(1, 1) = upper3(1, 1); - (*this)(1, 2) = upper3(1, 2); + _m.m._10 = upper3(1, 0); + _m.m._11 = upper3(1, 1); + _m.m._12 = upper3(1, 2); - (*this)(2, 0) = upper3(2, 0); - (*this)(2, 1) = upper3(2, 1); - (*this)(2, 2) = upper3(2, 2); + _m.m._20 = upper3(2, 0); + _m.m._21 = upper3(2, 1); + _m.m._22 = upper3(2, 2); } //////////////////////////////////////////////////////////////////// @@ -174,12 +237,12 @@ set_upper_3(const FLOATNAME(LMatrix3) &upper3) { // Access: Public // Description: Retrieves the upper 3x3 submatrix. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix4):: get_upper_3() const { return FLOATNAME(LMatrix3) - ((*this)(0, 0), (*this)(0, 1), (*this)(0, 2), - (*this)(1, 0), (*this)(1, 1), (*this)(1, 2), - (*this)(2, 0), (*this)(2, 1), (*this)(2, 2)); + (_m.m._00, _m.m._01, _m.m._02, + _m.m._10, _m.m._11, _m.m._12, + _m.m._20, _m.m._21, _m.m._22); } //////////////////////////////////////////////////////////////////// @@ -187,12 +250,12 @@ get_upper_3() const { // Access: Public // Description: Replaces the indicated row of the matrix. //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix4):: +INLINE_LINMATH void FLOATNAME(LMatrix4):: set_row(int row, const FLOATNAME(LVecBase4) &v) { - (*this)(row, 0) = v[0]; - (*this)(row, 1) = v[1]; - (*this)(row, 2) = v[2]; - (*this)(row, 3) = v[3]; + (*this)(row, 0) = v._v.v._0; + (*this)(row, 1) = v._v.v._1; + (*this)(row, 2) = v._v.v._2; + (*this)(row, 3) = v._v.v._3; } //////////////////////////////////////////////////////////////////// @@ -200,12 +263,12 @@ set_row(int row, const FLOATNAME(LVecBase4) &v) { // Access: Public // Description: Replaces the indicated column of the matrix. //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix4):: +INLINE_LINMATH void FLOATNAME(LMatrix4):: set_col(int col, const FLOATNAME(LVecBase4) &v) { - (*this)(0, col) = v[0]; - (*this)(1, col) = v[1]; - (*this)(2, col) = v[2]; - (*this)(3, col) = v[3]; + (*this)(0, col) = v._v.v._0; + (*this)(1, col) = v._v.v._1; + (*this)(2, col) = v._v.v._2; + (*this)(3, col) = v._v.v._3; } //////////////////////////////////////////////////////////////////// @@ -215,11 +278,11 @@ set_col(int col, const FLOATNAME(LVecBase4) &v) { // indicated 3-component vector, ignoring the last // column. //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix4):: +INLINE_LINMATH void FLOATNAME(LMatrix4):: set_row(int row, const FLOATNAME(LVecBase3) &v) { - (*this)(row, 0) = v[0]; - (*this)(row, 1) = v[1]; - (*this)(row, 2) = v[2]; + (*this)(row, 0) = v._v.v._0; + (*this)(row, 1) = v._v.v._1; + (*this)(row, 2) = v._v.v._2; } //////////////////////////////////////////////////////////////////// @@ -229,11 +292,11 @@ set_row(int row, const FLOATNAME(LVecBase3) &v) { // indicated 3-component vector, ignoring the last // row. //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix4):: +INLINE_LINMATH void FLOATNAME(LMatrix4):: set_col(int col, const FLOATNAME(LVecBase3) &v) { - (*this)(0, col) = v[0]; - (*this)(1, col) = v[1]; - (*this)(2, col) = v[2]; + (*this)(0, col) = v._v.v._0; + (*this)(1, col) = v._v.v._1; + (*this)(2, col) = v._v.v._2; } //////////////////////////////////////////////////////////////////// @@ -242,7 +305,7 @@ set_col(int col, const FLOATNAME(LVecBase3) &v) { // Description: Retrieves the indicated row of the matrix as a // 4-component vector. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4) FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LMatrix4):: get_row(int row) const { return FLOATNAME(LVecBase4)((*this)(row, 0), (*this)(row, 1), @@ -256,7 +319,7 @@ get_row(int row) const { // Description: Retrieves the indicated column of the matrix as a // 4-component vector. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4) FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LMatrix4):: get_col(int col) const { return FLOATNAME(LVecBase4)((*this)(0, col), (*this)(1, col), @@ -270,7 +333,7 @@ get_col(int col) const { // Description: Retrieves the row column of the matrix as a // 3-component vector, ignoring the last column. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix4):: get_row3(int row) const { return FLOATNAME(LVecBase3)((*this)(row, 0), (*this)(row, 1), @@ -283,7 +346,7 @@ get_row3(int row) const { // Description: Retrieves the indicated column of the matrix as a // 3-component vector, ignoring the last row. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix4):: get_col3(int col) const { return FLOATNAME(LVecBase3)((*this)(0, col), (*this)(1, col), @@ -295,11 +358,11 @@ get_col3(int col) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE &FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATTYPE &FLOATNAME(LMatrix4):: operator () (int row, int col) { - // nassertr(row >= 0 && row < 4, _data[0]); - // nassertr(col >= 0 && col < 4, _data[0]); - return _data[row * 4 + col]; + // nassertr(row >= 0 && row < 4, _m.data[0]); + // nassertr(col >= 0 && col < 4, _m.data[0]); + return _m.data[row * 4 + col]; } //////////////////////////////////////////////////////////////////// @@ -307,11 +370,11 @@ operator () (int row, int col) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix4):: operator () (int row, int col) const { // nassertr(row >= 0 && row < 4, 0.0); // nassertr(col >= 0 && col < 4, 0.0); - return _data[row * 4 + col]; + return _m.data[row * 4 + col]; } //////////////////////////////////////////////////////////////////// @@ -320,13 +383,13 @@ operator () (int row, int col) const { // Description: Returns true if any component of the matrix is // not-a-number, false otherwise. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LMatrix4):: +INLINE_LINMATH bool FLOATNAME(LMatrix4):: is_nan() const { return - cnan(_data[0]) || cnan(_data[1]) || cnan(_data[2]) || cnan(_data[3]) || - cnan(_data[4]) || cnan(_data[5]) || cnan(_data[6]) || cnan(_data[7]) || - cnan(_data[8]) || cnan(_data[9]) || cnan(_data[10]) || cnan(_data[11]) || - cnan(_data[12]) || cnan(_data[13]) || cnan(_data[14]) || cnan(_data[15]); + cnan(_m.data[0]) || cnan(_m.data[1]) || cnan(_m.data[2]) || cnan(_m.data[3]) || + cnan(_m.data[4]) || cnan(_m.data[5]) || cnan(_m.data[6]) || cnan(_m.data[7]) || + cnan(_m.data[8]) || cnan(_m.data[9]) || cnan(_m.data[10]) || cnan(_m.data[11]) || + cnan(_m.data[12]) || cnan(_m.data[13]) || cnan(_m.data[14]) || cnan(_m.data[15]); } //////////////////////////////////////////////////////////////////// @@ -334,11 +397,11 @@ is_nan() const { // Access: Public // Description: Returns a particular element of the matrix. //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix4):: get_cell(int row, int col) const { // nassertr(row >= 0 && row < 4, 0.0); // nassertr(col >= 0 && col < 4, 0.0); - return _data[row * 4 + col]; + return _m.data[row * 4 + col]; } //////////////////////////////////////////////////////////////////// @@ -346,11 +409,11 @@ get_cell(int row, int col) const { // Access: Public // Description: Changes a particular element of the matrix. //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix4):: +INLINE_LINMATH void FLOATNAME(LMatrix4):: set_cell(int row, int col, FLOATTYPE value) { // nassertv(row >= 0 && row < 4); // nassertv(col >= 0 && col < 4); - _data[row * 4 + col] = value; + _m.data[row * 4 + col] = value; } //////////////////////////////////////////////////////////////////// @@ -360,9 +423,9 @@ set_cell(int row, int col, FLOATTYPE value) { // elements in the matrix. The remaining elements // occupy the next eight positions in row-major order. //////////////////////////////////////////////////////////////////// -INLINE const FLOATTYPE *FLOATNAME(LMatrix4):: +INLINE_LINMATH const FLOATTYPE *FLOATNAME(LMatrix4):: get_data() const { - return _data; + return _m.data; } //////////////////////////////////////////////////////////////////// @@ -370,7 +433,7 @@ get_data() const { // Access: Public // Description: Returns the number of elements in the matrix, 16. //////////////////////////////////////////////////////////////////// -INLINE int FLOATNAME(LMatrix4):: +INLINE_LINMATH int FLOATNAME(LMatrix4):: get_num_components() const { return 16; } @@ -381,9 +444,9 @@ get_num_components() const { // Description: Returns an iterator that may be used to traverse the // elements of the matrix, STL-style. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4)::iterator FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4)::iterator FLOATNAME(LMatrix4):: begin() { - return _data; + return _m.data; } //////////////////////////////////////////////////////////////////// @@ -392,7 +455,7 @@ begin() { // Description: Returns an iterator that may be used to traverse the // elements of the matrix, STL-style. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4)::iterator FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4)::iterator FLOATNAME(LMatrix4):: end() { return begin() + 16; } @@ -403,9 +466,9 @@ end() { // Description: Returns an iterator that may be used to traverse the // elements of the matrix, STL-style. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4)::const_iterator FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4)::const_iterator FLOATNAME(LMatrix4):: begin() const { - return _data; + return _m.data; } //////////////////////////////////////////////////////////////////// @@ -414,7 +477,7 @@ begin() const { // Description: Returns an iterator that may be used to traverse the // elements of the matrix, STL-style. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4)::const_iterator FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4)::const_iterator FLOATNAME(LMatrix4):: end() const { return begin() + 16; } @@ -428,7 +491,7 @@ end() const { // especially in an STL container. Also see // compare_to(). //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LMatrix4):: +INLINE_LINMATH bool FLOATNAME(LMatrix4):: operator < (const FLOATNAME(LMatrix4) &other) const { return compare_to(other) < 0; } @@ -438,7 +501,7 @@ operator < (const FLOATNAME(LMatrix4) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LMatrix4):: +INLINE_LINMATH bool FLOATNAME(LMatrix4):: operator == (const FLOATNAME(LMatrix4) &other) const { return compare_to(other) == 0; } @@ -448,7 +511,7 @@ operator == (const FLOATNAME(LMatrix4) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LMatrix4):: +INLINE_LINMATH bool FLOATNAME(LMatrix4):: operator != (const FLOATNAME(LMatrix4) &other) const { return !operator == (other); } @@ -459,11 +522,16 @@ operator != (const FLOATNAME(LMatrix4) &other) const { // Description: This flavor of compare_to uses a default threshold // value based on the numeric type. //////////////////////////////////////////////////////////////////// -INLINE int FLOATNAME(LMatrix4):: +INLINE_LINMATH int FLOATNAME(LMatrix4):: compare_to(const FLOATNAME(LMatrix4) &other) const { return compare_to(other, NEARLY_ZERO(FLOATTYPE)); } +#define VECTOR4_MATRIX4_PRODUCT(v_res, v, mat) \ +v_res._v.v._0 = v._v.v._0*mat._m.m._00 + v._v.v._1*mat._m.m._10 + v._v.v._2*mat._m.m._20 + v._v.v._3*mat._m.m._30; \ +v_res._v.v._1 = v._v.v._0*mat._m.m._01 + v._v.v._1*mat._m.m._11 + v._v.v._2*mat._m.m._21 + v._v.v._3*mat._m.m._31; \ +v_res._v.v._2 = v._v.v._0*mat._m.m._02 + v._v.v._1*mat._m.m._12 + v._v.v._2*mat._m.m._22 + v._v.v._3*mat._m.m._32; \ +v_res._v.v._3 = v._v.v._0*mat._m.m._03 + v._v.v._1*mat._m.m._13 + v._v.v._2*mat._m.m._23 + v._v.v._3*mat._m.m._33; //////////////////////////////////////////////////////////////////// // Function: LMatrix4::xform @@ -471,12 +539,18 @@ compare_to(const FLOATNAME(LMatrix4) &other) const { // Description: 4-component vector or point times matrix. This is a // fully general operation. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4) FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LMatrix4):: xform(const FLOATNAME(LVecBase4) &v) const { - return FLOATNAME(LVecBase4)(v.dot(get_col(0)), + FLOATNAME(LVecBase4) v_res; + + VECTOR4_MATRIX4_PRODUCT(v_res, v,(*this)); + return v_res; + +/* return FLOATNAME(LVecBase4)(v.dot(get_col(0)), v.dot(get_col(1)), v.dot(get_col(2)), v.dot(get_col(3))); +*/ } //////////////////////////////////////////////////////////////////// @@ -486,11 +560,24 @@ xform(const FLOATNAME(LVecBase4) &v) const { // translation component) and returns the result. This // assumes the matrix is an affine transform. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix4):: xform_point(const FLOATNAME(LVecBase3) &v) const { - return FLOATNAME(LVecBase3)(v.dot(get_col3(0)) + (*this)(3, 0), - v.dot(get_col3(1)) + (*this)(3, 1), - v.dot(get_col3(2)) + (*this)(3, 2)); + + FLOATNAME(LVecBase3) v_res; + + // v._v.v._3 == 1.0 for this case + + v_res._v.v._0 = v._v.v._0*_m.m._00 + v._v.v._1*_m.m._10 + v._v.v._2*_m.m._20 + _m.m._30; + v_res._v.v._1 = v._v.v._0*_m.m._01 + v._v.v._1*_m.m._11 + v._v.v._2*_m.m._21 + _m.m._31; + v_res._v.v._2 = v._v.v._0*_m.m._02 + v._v.v._1*_m.m._12 + v._v.v._2*_m.m._22 + _m.m._32; + + return v_res; + +/* + return FLOATNAME(LVecBase3)(v.dot(get_col3(0)) + _m.m._30, + v.dot(get_col3(1)) + _m.m._31, + v.dot(get_col3(2)) + _m.m._32); +*/ } //////////////////////////////////////////////////////////////////// @@ -500,11 +587,22 @@ xform_point(const FLOATNAME(LVecBase3) &v) const { // translation component) and returns the result. This // assumes the matrix is an affine transform. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix4):: xform_vec(const FLOATNAME(LVecBase3) &v) const { + FLOATNAME(LVecBase3) v_res; + + // v._v.v._3 == 0.0 for this case + + v_res._v.v._0 = v._v.v._0*_m.m._00 + v._v.v._1*_m.m._10 + v._v.v._2*_m.m._20; + v_res._v.v._1 = v._v.v._0*_m.m._01 + v._v.v._1*_m.m._11 + v._v.v._2*_m.m._21; + v_res._v.v._2 = v._v.v._0*_m.m._02 + v._v.v._1*_m.m._12 + v._v.v._2*_m.m._22; + + return v_res; +/* return FLOATNAME(LVecBase3)(v.dot(get_col3(0)), v.dot(get_col3(1)), v.dot(get_col3(2))); +*/ } //////////////////////////////////////////////////////////////////// @@ -513,20 +611,64 @@ xform_vec(const FLOATNAME(LVecBase3) &v) const { // Description: Returns one cell of the result of a matrix-matrix // multiplication operation. //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix4):: mult_cel(const FLOATNAME(LMatrix4) &other, int row, int col) const { return get_row(row).dot(other.get_col(col)); } +#define MATRIX4_PRODUCT(res, a, b) \ +res._m.m._00 = a._m.m._00*b._m.m._00 + a._m.m._01*b._m.m._10 + a._m.m._02*b._m.m._20 + a._m.m._03*b._m.m._30; \ +res._m.m._01 = a._m.m._00*b._m.m._01 + a._m.m._01*b._m.m._11 + a._m.m._02*b._m.m._21 + a._m.m._03*b._m.m._31; \ +res._m.m._02 = a._m.m._00*b._m.m._02 + a._m.m._01*b._m.m._12 + a._m.m._02*b._m.m._22 + a._m.m._03*b._m.m._32; \ +res._m.m._03 = a._m.m._00*b._m.m._03 + a._m.m._01*b._m.m._13 + a._m.m._02*b._m.m._23 + a._m.m._03*b._m.m._33; \ + \ +res._m.m._10 = a._m.m._10*b._m.m._00 + a._m.m._11*b._m.m._10 + a._m.m._12*b._m.m._20 + a._m.m._13*b._m.m._30; \ +res._m.m._11 = a._m.m._10*b._m.m._01 + a._m.m._11*b._m.m._11 + a._m.m._12*b._m.m._21 + a._m.m._13*b._m.m._31; \ +res._m.m._12 = a._m.m._10*b._m.m._02 + a._m.m._11*b._m.m._12 + a._m.m._12*b._m.m._22 + a._m.m._13*b._m.m._32; \ +res._m.m._13 = a._m.m._10*b._m.m._03 + a._m.m._11*b._m.m._13 + a._m.m._12*b._m.m._23 + a._m.m._13*b._m.m._33; \ + \ +res._m.m._20 = a._m.m._20*b._m.m._00 + a._m.m._21*b._m.m._10 + a._m.m._22*b._m.m._20 + a._m.m._23*b._m.m._30; \ +res._m.m._21 = a._m.m._20*b._m.m._01 + a._m.m._21*b._m.m._11 + a._m.m._22*b._m.m._21 + a._m.m._23*b._m.m._31; \ +res._m.m._22 = a._m.m._20*b._m.m._02 + a._m.m._21*b._m.m._12 + a._m.m._22*b._m.m._22 + a._m.m._23*b._m.m._32; \ +res._m.m._23 = a._m.m._20*b._m.m._03 + a._m.m._21*b._m.m._13 + a._m.m._22*b._m.m._23 + a._m.m._23*b._m.m._33; \ + \ +res._m.m._30 = a._m.m._30*b._m.m._00 + a._m.m._31*b._m.m._10 + a._m.m._32*b._m.m._20 + a._m.m._33*b._m.m._30; \ +res._m.m._31 = a._m.m._30*b._m.m._01 + a._m.m._31*b._m.m._11 + a._m.m._32*b._m.m._21 + a._m.m._33*b._m.m._31; \ +res._m.m._32 = a._m.m._30*b._m.m._02 + a._m.m._31*b._m.m._12 + a._m.m._32*b._m.m._22 + a._m.m._33*b._m.m._32; \ +res._m.m._33 = a._m.m._30*b._m.m._03 + a._m.m._31*b._m.m._13 + a._m.m._32*b._m.m._23 + a._m.m._33*b._m.m._33; //////////////////////////////////////////////////////////////////// // Function: LMatrix4::matrix * matrix // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4) FLOATNAME(LMatrix4):: operator * (const FLOATNAME(LMatrix4) &other) const { - FLOATNAME(LMatrix4) t; + FLOATNAME(LMatrix4) t; + + MATRIX4_PRODUCT(t,(*this),other); +/* +typedef union { + struct { + FLOATTYPE _m.m._11, _m.m._12, _m.m._13, _m.m._14; + FLOATTYPE _m.m._21, _m.m._22, _m.m._23, _m.m._24; + FLOATTYPE _m.m._31, _m.m._32, _m.m._33, _m.m._34; + FLOATTYPE _m.m._41, _m.m._42, _m.m._43, _m.m._44; + }; + + FLOATTYPE m[4][4]; + } MYMATRIX4; + + FLOATNAME(LMatrix4) t; + + MYMATRIX4 *result_ptr=(MYMATRIX4 *)t.get_m.data(); + MYMATRIX4 *mat1_ptr=(MYMATRIX4 *)this->get_m.data(); + MYMATRIX4 *mat2_ptr=(MYMATRIX4 *)other.get_m.data(); + + MATRIX4_PRODUCT(result_ptr,mat1_ptr,mat2_ptr); +*/ + +/* t(0, 0) = mult_cel(other, 0, 0); t(0, 1) = mult_cel(other, 0, 1); @@ -547,7 +689,7 @@ operator * (const FLOATNAME(LMatrix4) &other) const { t(3, 1) = mult_cel(other, 3, 1); t(3, 2) = mult_cel(other, 3, 2); t(3, 3) = mult_cel(other, 3, 3); - +*/ return t; } @@ -556,29 +698,29 @@ operator * (const FLOATNAME(LMatrix4) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4) FLOATNAME(LMatrix4):: operator * (FLOATTYPE scalar) const { FLOATNAME(LMatrix4) t; - t(0, 0) = (*this)(0, 0) * scalar; - t(0, 1) = (*this)(0, 1) * scalar; - t(0, 2) = (*this)(0, 2) * scalar; - t(0, 3) = (*this)(0, 3) * scalar; + t._m.m._00 = _m.m._00 * scalar; + t._m.m._01 = _m.m._01 * scalar; + t._m.m._02 = _m.m._02 * scalar; + t._m.m._03 = _m.m._03 * scalar; - t(1, 0) = (*this)(1, 0) * scalar; - t(1, 1) = (*this)(1, 1) * scalar; - t(1, 2) = (*this)(1, 2) * scalar; - t(1, 3) = (*this)(1, 3) * scalar; + t._m.m._10 = _m.m._10 * scalar; + t._m.m._11 = _m.m._11 * scalar; + t._m.m._12 = _m.m._12 * scalar; + t._m.m._13 = _m.m._13 * scalar; - t(2, 0) = (*this)(2, 0) * scalar; - t(2, 1) = (*this)(2, 1) * scalar; - t(2, 2) = (*this)(2, 2) * scalar; - t(2, 3) = (*this)(2, 3) * scalar; + t._m.m._20 = _m.m._20 * scalar; + t._m.m._21 = _m.m._21 * scalar; + t._m.m._22 = _m.m._22 * scalar; + t._m.m._23 = _m.m._23 * scalar; - t(3, 0) = (*this)(3, 0) * scalar; - t(3, 1) = (*this)(3, 1) * scalar; - t(3, 2) = (*this)(3, 2) * scalar; - t(3, 3) = (*this)(3, 3) * scalar; + t._m.m._30 = _m.m._30 * scalar; + t._m.m._31 = _m.m._31 * scalar; + t._m.m._32 = _m.m._32 * scalar; + t._m.m._33 = _m.m._33 * scalar; return t; } @@ -588,29 +730,30 @@ operator * (FLOATTYPE scalar) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4) FLOATNAME(LMatrix4):: operator / (FLOATTYPE scalar) const { FLOATNAME(LMatrix4) t; + FLOATTYPE recip_scalar = 1.0/scalar; - t(0, 0) = (*this)(0, 0) / scalar; - t(0, 1) = (*this)(0, 1) / scalar; - t(0, 2) = (*this)(0, 2) / scalar; - t(0, 3) = (*this)(0, 3) / scalar; + t._m.m._00 = _m.m._00 * recip_scalar; + t._m.m._01 = _m.m._01 * recip_scalar; + t._m.m._02 = _m.m._02 * recip_scalar; + t._m.m._03 = _m.m._03 * recip_scalar; - t(1, 0) = (*this)(1, 0) / scalar; - t(1, 1) = (*this)(1, 1) / scalar; - t(1, 2) = (*this)(1, 2) / scalar; - t(1, 3) = (*this)(1, 3) / scalar; + t._m.m._10 = _m.m._10 * recip_scalar; + t._m.m._11 = _m.m._11 * recip_scalar; + t._m.m._12 = _m.m._12 * recip_scalar; + t._m.m._13 = _m.m._13 * recip_scalar; - t(2, 0) = (*this)(2, 0) / scalar; - t(2, 1) = (*this)(2, 1) / scalar; - t(2, 2) = (*this)(2, 2) / scalar; - t(2, 3) = (*this)(2, 3) / scalar; + t._m.m._20 = _m.m._20 * recip_scalar; + t._m.m._21 = _m.m._21 * recip_scalar; + t._m.m._22 = _m.m._22 * recip_scalar; + t._m.m._23 = _m.m._23 * recip_scalar; - t(3, 0) = (*this)(3, 0) / scalar; - t(3, 1) = (*this)(3, 1) / scalar; - t(3, 2) = (*this)(3, 2) / scalar; - t(3, 3) = (*this)(3, 3) / scalar; + t._m.m._30 = _m.m._30 * recip_scalar; + t._m.m._31 = _m.m._31 * recip_scalar; + t._m.m._32 = _m.m._32 * recip_scalar; + t._m.m._33 = _m.m._33 * recip_scalar; return t; } @@ -620,27 +763,27 @@ operator / (FLOATTYPE scalar) const { // Access: Public // Description: Performs a memberwise addition between two matrices. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4):: operator += (const FLOATNAME(LMatrix4) &other) { - (*this)(0, 0) += other(0, 0); - (*this)(0, 1) += other(0, 1); - (*this)(0, 2) += other(0, 2); - (*this)(0, 3) += other(0, 3); + _m.m._00 += other._m.m._00; + _m.m._01 += other._m.m._01; + _m.m._02 += other._m.m._02; + _m.m._03 += other._m.m._03; - (*this)(1, 0) += other(1, 0); - (*this)(1, 1) += other(1, 1); - (*this)(1, 2) += other(1, 2); - (*this)(1, 3) += other(1, 3); + _m.m._10 += other._m.m._10; + _m.m._11 += other._m.m._11; + _m.m._12 += other._m.m._12; + _m.m._13 += other._m.m._13; - (*this)(2, 0) += other(2, 0); - (*this)(2, 1) += other(2, 1); - (*this)(2, 2) += other(2, 2); - (*this)(2, 3) += other(2, 3); + _m.m._20 += other._m.m._20; + _m.m._21 += other._m.m._21; + _m.m._22 += other._m.m._22; + _m.m._23 += other._m.m._23; - (*this)(3, 0) += other(3, 0); - (*this)(3, 1) += other(3, 1); - (*this)(3, 2) += other(3, 2); - (*this)(3, 3) += other(3, 3); + _m.m._30 += other._m.m._30; + _m.m._31 += other._m.m._31; + _m.m._32 += other._m.m._32; + _m.m._33 += other._m.m._33; return *this; } @@ -650,27 +793,27 @@ operator += (const FLOATNAME(LMatrix4) &other) { // Access: Public // Description: Performs a memberwise addition between two matrices. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4):: operator -= (const FLOATNAME(LMatrix4) &other) { - (*this)(0, 0) -= other(0, 0); - (*this)(0, 1) -= other(0, 1); - (*this)(0, 2) -= other(0, 2); - (*this)(0, 3) -= other(0, 3); + _m.m._00 -= other._m.m._00; + _m.m._01 -= other._m.m._01; + _m.m._02 -= other._m.m._02; + _m.m._03 -= other._m.m._03; - (*this)(1, 0) -= other(1, 0); - (*this)(1, 1) -= other(1, 1); - (*this)(1, 2) -= other(1, 2); - (*this)(1, 3) -= other(1, 3); + _m.m._10 -= other._m.m._10; + _m.m._11 -= other._m.m._11; + _m.m._12 -= other._m.m._12; + _m.m._13 -= other._m.m._13; - (*this)(2, 0) -= other(2, 0); - (*this)(2, 1) -= other(2, 1); - (*this)(2, 2) -= other(2, 2); - (*this)(2, 3) -= other(2, 3); + _m.m._20 -= other._m.m._20; + _m.m._21 -= other._m.m._21; + _m.m._22 -= other._m.m._22; + _m.m._23 -= other._m.m._23; - (*this)(3, 0) -= other(3, 0); - (*this)(3, 1) -= other(3, 1); - (*this)(3, 2) -= other(3, 2); - (*this)(3, 3) -= other(3, 3); + _m.m._30 -= other._m.m._30; + _m.m._31 -= other._m.m._31; + _m.m._32 -= other._m.m._32; + _m.m._33 -= other._m.m._33; return *this; } @@ -680,7 +823,7 @@ operator -= (const FLOATNAME(LMatrix4) &other) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4):: operator *= (const FLOATNAME(LMatrix4) &other) { (*this) = (*this) * other; return *this; @@ -691,27 +834,27 @@ operator *= (const FLOATNAME(LMatrix4) &other) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4):: operator *= (FLOATTYPE scalar) { - (*this)(0, 0) *= scalar; - (*this)(0, 1) *= scalar; - (*this)(0, 2) *= scalar; - (*this)(0, 3) *= scalar; + _m.m._00 *= scalar; + _m.m._01 *= scalar; + _m.m._02 *= scalar; + _m.m._03 *= scalar; - (*this)(1, 0) *= scalar; - (*this)(1, 1) *= scalar; - (*this)(1, 2) *= scalar; - (*this)(1, 3) *= scalar; + _m.m._10 *= scalar; + _m.m._11 *= scalar; + _m.m._12 *= scalar; + _m.m._13 *= scalar; - (*this)(2, 0) *= scalar; - (*this)(2, 1) *= scalar; - (*this)(2, 2) *= scalar; - (*this)(2, 3) *= scalar; + _m.m._20 *= scalar; + _m.m._21 *= scalar; + _m.m._22 *= scalar; + _m.m._23 *= scalar; - (*this)(3, 0) *= scalar; - (*this)(3, 1) *= scalar; - (*this)(3, 2) *= scalar; - (*this)(3, 3) *= scalar; + _m.m._30 *= scalar; + _m.m._31 *= scalar; + _m.m._32 *= scalar; + _m.m._33 *= scalar; return *this; } @@ -721,27 +864,27 @@ operator *= (FLOATTYPE scalar) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4):: operator /= (FLOATTYPE scalar) { - (*this)(0, 0) /= scalar; - (*this)(0, 1) /= scalar; - (*this)(0, 2) /= scalar; - (*this)(0, 3) /= scalar; + _m.m._00 /= scalar; + _m.m._01 /= scalar; + _m.m._02 /= scalar; + _m.m._03 /= scalar; - (*this)(1, 0) /= scalar; - (*this)(1, 1) /= scalar; - (*this)(1, 2) /= scalar; - (*this)(1, 3) /= scalar; + _m.m._10 /= scalar; + _m.m._11 /= scalar; + _m.m._12 /= scalar; + _m.m._13 /= scalar; - (*this)(2, 0) /= scalar; - (*this)(2, 1) /= scalar; - (*this)(2, 2) /= scalar; - (*this)(2, 3) /= scalar; + _m.m._20 /= scalar; + _m.m._21 /= scalar; + _m.m._22 /= scalar; + _m.m._23 /= scalar; - (*this)(3, 0) /= scalar; - (*this)(3, 1) /= scalar; - (*this)(3, 2) /= scalar; - (*this)(3, 3) /= scalar; + _m.m._30 /= scalar; + _m.m._31 /= scalar; + _m.m._32 /= scalar; + _m.m._33 /= scalar; return *this; } @@ -752,42 +895,59 @@ operator /= (FLOATTYPE scalar) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix4):: +INLINE_LINMATH void FLOATNAME(LMatrix4):: transpose_from(const FLOATNAME(LMatrix4) &other) { - (*this)(0, 0) = other(0, 0); - (*this)(0, 1) = other(1, 0); - (*this)(0, 2) = other(2, 0); - (*this)(0, 3) = other(3, 0); + _m.m._00 = other._m.m._00; + _m.m._01 = other._m.m._10; + _m.m._02 = other._m.m._20; + _m.m._03 = other._m.m._30; - (*this)(1, 0) = other(0, 1); - (*this)(1, 1) = other(1, 1); - (*this)(1, 2) = other(2, 1); - (*this)(1, 3) = other(3, 1); + _m.m._10 = other._m.m._01; + _m.m._11 = other._m.m._11; + _m.m._12 = other._m.m._21; + _m.m._13 = other._m.m._31; - (*this)(2, 0) = other(0, 2); - (*this)(2, 1) = other(1, 2); - (*this)(2, 2) = other(2, 2); - (*this)(2, 3) = other(3, 2); + _m.m._20 = other._m.m._02; + _m.m._21 = other._m.m._12; + _m.m._22 = other._m.m._22; + _m.m._23 = other._m.m._32; - (*this)(3, 0) = other(0, 3); - (*this)(3, 1) = other(1, 3); - (*this)(3, 2) = other(2, 3); - (*this)(3, 3) = other(3, 3); + _m.m._30 = other._m.m._03; + _m.m._31 = other._m.m._13; + _m.m._32 = other._m.m._23; + _m.m._33 = other._m.m._33; } - //////////////////////////////////////////////////////////////////// // Function: LMatrix4::transpose_in_place // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix4):: +INLINE_LINMATH void FLOATNAME(LMatrix4):: transpose_in_place() { - FLOATNAME(LMatrix4) temp = (*this); - transpose_from(temp); +// FLOATNAME(LMatrix4) temp = (*this); +// transpose_from(temp); + + #define SWAP__(x,y) { FLOATTYPE temp = (x); (x) = (y); (y) = temp;} + SWAP__(_m.m._01,_m.m._10); + SWAP__(_m.m._02,_m.m._20); + SWAP__(_m.m._03,_m.m._30); + SWAP__(_m.m._12,_m.m._21); + SWAP__(_m.m._13,_m.m._31); + SWAP__(_m.m._23,_m.m._32); + #undef SWAP__ } - +//////////////////////////////////////////////////////////////////// +// Function: LMatrix4::transpose +// Description: Transposes the given matrix and returns it. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LMatrix4) +transpose(const FLOATNAME(LMatrix4) &a) { + FLOATNAME(LMatrix4) result; + result.transpose_from(a); + return result; +} //////////////////////////////////////////////////////////////////// // Function: LMatrix4::invert_from @@ -805,12 +965,15 @@ transpose_in_place() { // successfully inverted, false if the was a // singularity. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LMatrix4):: + +// bugbug: we could optimize this for rotation/scale/translation matrices +// (transpose upper 3x3 and take negative of translation component) +INLINE_LINMATH bool FLOATNAME(LMatrix4):: invert_from(const FLOATNAME(LMatrix4) &other) { - if (IS_NEARLY_EQUAL(other(3, 0), 0.0) && - IS_NEARLY_EQUAL(other(3, 1), 0.0) && - IS_NEARLY_EQUAL(other(3, 2), 0.0) && - IS_NEARLY_EQUAL(other(3, 3), 1.0)) { + if (IS_NEARLY_EQUAL(other._m.m._30, 0.0) && + IS_NEARLY_EQUAL(other._m.m._31, 0.0) && + IS_NEARLY_EQUAL(other._m.m._32, 0.0) && + IS_NEARLY_EQUAL(other._m.m._33, 1.0)) { return invert_affine_from(other); } @@ -819,8 +982,9 @@ invert_from(const FLOATNAME(LMatrix4) &other) { int index[4]; if (!decompose_mat(index)) { - linmath_cat.warning() - << "Tried to invert singular LMatrix4.\n"; +#ifdef NDEBUG + linmath_cat.warning() << "Tried to invert singular LMatrix4.\n"; +#endif return false; } @@ -851,21 +1015,44 @@ invert_from(const FLOATNAME(LMatrix4) &other) { // successfully inverted, false if the was a // singularity. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LMatrix4):: + +// bugbug: we could optimize this for rotation/scale/translation matrices +// (transpose upper 3x3 and take negative of translation component) +INLINE_LINMATH bool FLOATNAME(LMatrix4):: invert_affine_from(const FLOATNAME(LMatrix4) &other) { FLOATNAME(LMatrix3) rot; - rot.invert_from(other.get_upper_3()); + + rot.invert_from(other.get_upper_3()); // probably could use transpose here set_upper_3(rot); - set_col(3, FLOATNAME(LVecBase4)(0.0, 0.0, 0.0, 1.0)); +// set_col(3, FLOATNAME(LVecBase4)(0.0, 0.0, 0.0, 1.0)); + + _m.m._03 = 0.0; + _m.m._13 = 0.0; + _m.m._23 = 0.0; + _m.m._33 = 1.0; // compute -C*inv(A) +/* for (int i = 0; i < 3; i++) { (*this)(3, i) = 0.0; for (int j = 0; j < 3; j++) { (*this)(3, i) -= other(3, j) * (*this)(j, i); } } +*/ + + _m.m._30 = -(other._m.m._30 * _m.m._00 + + other._m.m._31 * _m.m._10 + + other._m.m._32 * _m.m._20); + + _m.m._31 = -(other._m.m._30 * _m.m._01 + + other._m.m._31 * _m.m._11 + + other._m.m._32 * _m.m._21); + + _m.m._32 = -(other._m.m._30 * _m.m._02 + + other._m.m._31 * _m.m._12 + + other._m.m._32 * _m.m._22); return true; } @@ -877,24 +1064,22 @@ invert_affine_from(const FLOATNAME(LMatrix4) &other) { // inverse is successful, false if the matrix was // singular. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LMatrix4):: +INLINE_LINMATH bool FLOATNAME(LMatrix4):: invert_in_place() { FLOATNAME(LMatrix4) temp = (*this); return invert_from(temp); } //////////////////////////////////////////////////////////////////// -// Function: LMatrix::translate_mat -// Access: Public, Static -// Description: Returns a matrix that applies the indicated -// translation. +// Function: LMatrix4::invert +// Description: Inverts the given matrix and returns it. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) FLOATNAME(LMatrix4):: -translate_mat(const FLOATNAME(LVecBase3) &trans) { - return FLOATNAME(LMatrix4)(1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - trans[0], trans[1], trans[2], 1.0); +INLINE_LINMATH FLOATNAME(LMatrix4) +invert(const FLOATNAME(LMatrix4) &a) { + FLOATNAME(LMatrix4) result; + bool nonsingular = result.invert_from(a); + nassertr(nonsingular, FLOATNAME(LMatrix4)::ident_mat()); + return result; } //////////////////////////////////////////////////////////////////// @@ -903,7 +1088,21 @@ translate_mat(const FLOATNAME(LVecBase3) &trans) { // Description: Returns a matrix that applies the indicated // translation. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4) FLOATNAME(LMatrix4):: +translate_mat(const FLOATNAME(LVecBase3) &trans) { + return FLOATNAME(LMatrix4)(1.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + trans._v.v._0, trans._v.v._1, trans._v.v._2, 1.0); +} + +//////////////////////////////////////////////////////////////////// +// Function: LMatrix::translate_mat +// Access: Public, Static +// Description: Returns a matrix that applies the indicated +// translation. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LMatrix4) FLOATNAME(LMatrix4):: translate_mat(FLOATTYPE tx, FLOATTYPE ty, FLOATTYPE tz) { return FLOATNAME(LMatrix4)(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, @@ -917,51 +1116,66 @@ translate_mat(FLOATTYPE tx, FLOATTYPE ty, FLOATTYPE tz) { // Description: Returns a matrix that rotates by the given angle in // degrees counterclockwise about the indicated vector. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) FLOATNAME(LMatrix4):: -rotate_mat(FLOATTYPE angle, FLOATNAME(LVecBase3) axis, +INLINE_LINMATH FLOATNAME(LMatrix4) FLOATNAME(LMatrix4):: +rotate_mat(FLOATTYPE angle, FLOATNAME(LVecBase3) &axis, CoordinateSystem cs) { + if (cs == CS_default) { cs = default_coordinate_system; } FLOATNAME(LMatrix4) mat; - if (!is_right_handed(cs)) { + if(IS_LEFT_HANDED_COORDSYSTEM(cs)) { // In a left-handed coordinate system, counterclockwise is the // other direction. angle = -angle; } + FLOATTYPE axis_0 = axis._v.v._0; + FLOATTYPE axis_1 = axis._v.v._1; + FLOATTYPE axis_2 = axis._v.v._2; + // Normalize the axis. - FLOATTYPE length2 = axis.dot(axis); + FLOATTYPE length_sq = axis_0 * axis_0 + axis_1 * axis_1 + axis_2 * axis_2; // Cannot rotate about a zero-length axis. - nassertr(length2 != 0.0, ident_mat()); - FLOATTYPE recip_sqrt_length2=1.0f/csqrt(length2); - axis *= recip_sqrt_length2; + nassertr(length_sq != 0.0, ident_mat()); + FLOATTYPE recip_length=1.0f/csqrt(length_sq); + axis *= recip_length; - double angle_rad=deg_2_rad(angle); - double s,c; + FLOATTYPE angle_rad=deg_2_rad(angle); + FLOATTYPE s,c; csincos(angle_rad,&s,&c); - double t = 1.0 - c; + FLOATTYPE t = 1.0 - c; - mat(0, 0) = t * axis[0] * axis[0] + c; - mat(0, 1) = t * axis[0] * axis[1] + s * axis[2]; - mat(0, 2) = t * axis[0] * axis[2] - s * axis[1]; - mat(0, 3) = 0.0; + FLOATTYPE t0,t1,t2,s0,s1,s2; - mat(1, 0) = t * axis[1] * axis[0] - s * axis[2]; - mat(1, 1) = t * axis[1] * axis[1] + c; - mat(1, 2) = t * axis[1] * axis[2] + s * axis[0]; - mat(1, 3) = 0.0; + t0 = t * axis_0; + t1 = t * axis_1; + t2 = t * axis_2; + s0 = s * axis_0; + s1 = s * axis_1; + s2 = s * axis_2; - mat(2, 0) = t * axis[2] * axis[0] + s * axis[1]; - mat(2, 1) = t * axis[2] * axis[1] - s * axis[0]; - mat(2, 2) = t * axis[2] * axis[2] + c; - mat(2, 3) = 0.0; + mat._m.m._00 = t0 * axis_0 + c; + mat._m.m._01 = t0 * axis_1 + s2; + mat._m.m._02 = t0 * axis_2 - s1; - mat(3, 0) = 0.0; - mat(3, 1) = 0.0; - mat(3, 2) = 0.0; - mat(3, 3) = 1.0; + mat._m.m._10 = t1 * axis_0 - s2; + mat._m.m._11 = t1 * axis_1 + c; + mat._m.m._12 = t1 * axis_2 + s0; + + mat._m.m._20 = t2 * axis_0 + s1; + mat._m.m._21 = t2 * axis_1 - s0; + mat._m.m._22 = t2 * axis_2 + c; + + mat._m.m._03 = 0.0; + mat._m.m._13 = 0.0; + mat._m.m._23 = 0.0; + + mat._m.m._30 = 0.0; + mat._m.m._31 = 0.0; + mat._m.m._32 = 0.0; + mat._m.m._33 = 1.0; return mat; } @@ -972,11 +1186,11 @@ rotate_mat(FLOATTYPE angle, FLOATNAME(LVecBase3) axis, // Description: Returns a matrix that applies the indicated // scale in each of the three axes. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4) FLOATNAME(LMatrix4):: scale_mat(const FLOATNAME(LVecBase3) &scale) { - return FLOATNAME(LMatrix4)(scale[0], 0.0, 0.0, 0.0, - 0.0, scale[1], 0.0, 0.0, - 0.0, 0.0, scale[2], 0.0, + return FLOATNAME(LMatrix4)(scale._v.v._0, 0.0, 0.0, 0.0, + 0.0, scale._v.v._1, 0.0, 0.0, + 0.0, 0.0, scale._v.v._2, 0.0, 0.0, 0.0, 0.0, 1.0); } @@ -987,7 +1201,7 @@ scale_mat(const FLOATNAME(LVecBase3) &scale) { // Description: Returns a matrix that applies the indicated // scale in each of the three axes. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4) FLOATNAME(LMatrix4):: scale_mat(FLOATTYPE sx, FLOATTYPE sy, FLOATTYPE sz) { return FLOATNAME(LMatrix4)(sx, 0.0, 0.0, 0.0, 0.0, sy, 0.0, 0.0, @@ -1002,7 +1216,7 @@ scale_mat(FLOATTYPE sx, FLOATTYPE sy, FLOATTYPE sz) { // Description: Returns a matrix that applies the indicated // uniform scale. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) FLOATNAME(LMatrix4):: +INLINE_LINMATH FLOATNAME(LMatrix4) FLOATNAME(LMatrix4):: scale_mat(FLOATTYPE scale) { return FLOATNAME(LMatrix4)(scale, 0.0, 0.0, 0.0, 0.0, scale, 0.0, 0.0, @@ -1017,7 +1231,7 @@ scale_mat(FLOATTYPE scale) { // Description: Returns a matrix that transforms from the Y-up // coordinate system to the Z-up coordinate system. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4):: +INLINE_LINMATH const FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4):: y_to_z_up_mat() { return _y_to_z_up_mat; } @@ -1028,7 +1242,7 @@ y_to_z_up_mat() { // Description: Returns a matrix that transforms from the Y-up // coordinate system to the Z-up coordinate system. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4):: +INLINE_LINMATH const FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4):: z_to_y_up_mat() { return _z_to_y_up_mat; } @@ -1039,7 +1253,7 @@ z_to_y_up_mat() { // Description: Returns true if two matrices are memberwise equal // within a default tolerance based on the numeric type. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LMatrix4):: +INLINE_LINMATH bool FLOATNAME(LMatrix4):: almost_equal(const FLOATNAME(LMatrix4) &other) const { return almost_equal(other, NEARLY_ZERO(FLOATTYPE)); } @@ -1049,28 +1263,29 @@ almost_equal(const FLOATNAME(LMatrix4) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix4):: + +INLINE_LINMATH void FLOATNAME(LMatrix4):: output(ostream &out) const { out << "[ " - << MAYBE_ZERO((*this)(0, 0)) << " " - << MAYBE_ZERO((*this)(0, 1)) << " " - << MAYBE_ZERO((*this)(0, 2)) << " " - << MAYBE_ZERO((*this)(0, 3)) + << MAYBE_ZERO(_m.m._00) << " " + << MAYBE_ZERO(_m.m._01) << " " + << MAYBE_ZERO(_m.m._02) << " " + << MAYBE_ZERO(_m.m._03) << " ] [ " - << MAYBE_ZERO((*this)(1, 0)) << " " - << MAYBE_ZERO((*this)(1, 1)) << " " - << MAYBE_ZERO((*this)(1, 2)) << " " - << MAYBE_ZERO((*this)(1, 3)) + << MAYBE_ZERO(_m.m._10) << " " + << MAYBE_ZERO(_m.m._11) << " " + << MAYBE_ZERO(_m.m._12) << " " + << MAYBE_ZERO(_m.m._13) << " ] [ " - << MAYBE_ZERO((*this)(2, 0)) << " " - << MAYBE_ZERO((*this)(2, 1)) << " " - << MAYBE_ZERO((*this)(2, 2)) << " " - << MAYBE_ZERO((*this)(2, 3)) + << MAYBE_ZERO(_m.m._20) << " " + << MAYBE_ZERO(_m.m._21) << " " + << MAYBE_ZERO(_m.m._22) << " " + << MAYBE_ZERO(_m.m._23) << " ] [ " - << MAYBE_ZERO((*this)(3, 0)) << " " - << MAYBE_ZERO((*this)(3, 1)) << " " - << MAYBE_ZERO((*this)(3, 2)) << " " - << MAYBE_ZERO((*this)(3, 3)) + << MAYBE_ZERO(_m.m._30) << " " + << MAYBE_ZERO(_m.m._31) << " " + << MAYBE_ZERO(_m.m._32) << " " + << MAYBE_ZERO(_m.m._33) << " ]"; } @@ -1079,53 +1294,32 @@ output(ostream &out) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LMatrix4):: +INLINE_LINMATH void FLOATNAME(LMatrix4):: write(ostream &out, int indent_level) const { indent(out, indent_level) - << MAYBE_ZERO((*this)(0, 0)) << " " - << MAYBE_ZERO((*this)(0, 1)) << " " - << MAYBE_ZERO((*this)(0, 2)) << " " - << MAYBE_ZERO((*this)(0, 3)) + << MAYBE_ZERO(_m.m._00) << " " + << MAYBE_ZERO(_m.m._01) << " " + << MAYBE_ZERO(_m.m._02) << " " + << MAYBE_ZERO(_m.m._03) << "\n"; indent(out, indent_level) - << MAYBE_ZERO((*this)(1, 0)) << " " - << MAYBE_ZERO((*this)(1, 1)) << " " - << MAYBE_ZERO((*this)(1, 2)) << " " - << MAYBE_ZERO((*this)(1, 3)) + << MAYBE_ZERO(_m.m._10) << " " + << MAYBE_ZERO(_m.m._11) << " " + << MAYBE_ZERO(_m.m._12) << " " + << MAYBE_ZERO(_m.m._13) << "\n"; indent(out, indent_level) - << MAYBE_ZERO((*this)(2, 0)) << " " - << MAYBE_ZERO((*this)(2, 1)) << " " - << MAYBE_ZERO((*this)(2, 2)) << " " - << MAYBE_ZERO((*this)(2, 3)) + << MAYBE_ZERO(_m.m._20) << " " + << MAYBE_ZERO(_m.m._21) << " " + << MAYBE_ZERO(_m.m._22) << " " + << MAYBE_ZERO(_m.m._23) << "\n"; indent(out, indent_level) - << MAYBE_ZERO((*this)(3, 0)) << " " - << MAYBE_ZERO((*this)(3, 1)) << " " - << MAYBE_ZERO((*this)(3, 2)) << " " - << MAYBE_ZERO((*this)(3, 3)) + << MAYBE_ZERO(_m.m._30) << " " + << MAYBE_ZERO(_m.m._31) << " " + << MAYBE_ZERO(_m.m._32) << " " + << MAYBE_ZERO(_m.m._33) << "\n"; } -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::transpose -// Description: Transposes the given matrix and returns it. -//////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) -transpose(const FLOATNAME(LMatrix4) &a) { - FLOATNAME(LMatrix4) result; - result.transpose_from(a); - return result; -} -//////////////////////////////////////////////////////////////////// -// Function: LMatrix4::invert -// Description: Inverts the given matrix and returns it. -//////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) -invert(const FLOATNAME(LMatrix4) &a) { - FLOATNAME(LMatrix4) result; - bool nonsingular = result.invert_from(a); - nassertr(nonsingular, FLOATNAME(LMatrix4)::ident_mat()); - return result; -} diff --git a/panda/src/linmath/lmatrix4_src.cxx b/panda/src/linmath/lmatrix4_src.cxx index 243cfe49a7..0df87482cf 100644 --- a/panda/src/linmath/lmatrix4_src.cxx +++ b/panda/src/linmath/lmatrix4_src.cxx @@ -283,8 +283,8 @@ read_datagram(DatagramIterator &scan) int FLOATNAME(LMatrix4):: compare_to(const FLOATNAME(LMatrix4) &other, FLOATTYPE threshold) const { for (int i = 0; i < 16; i++) { - if (!IS_THRESHOLD_EQUAL(_data[i], other._data[i], threshold)) { - return (_data[i] < other._data[i]) ? -1 : 1; + if (!IS_THRESHOLD_EQUAL(_m.data[i], other._m.data[i], threshold)) { + return (_m.data[i] < other._m.data[i]) ? -1 : 1; } } return 0; diff --git a/panda/src/linmath/lmatrix4_src.h b/panda/src/linmath/lmatrix4_src.h index 15bcd3aa5d..8ef783d216 100644 --- a/panda/src/linmath/lmatrix4_src.h +++ b/panda/src/linmath/lmatrix4_src.h @@ -13,124 +13,136 @@ PUBLISHED: typedef const FLOATTYPE *iterator; typedef const FLOATTYPE *const_iterator; - INLINE FLOATNAME(LMatrix4)(); - INLINE FLOATNAME(LMatrix4)(const FLOATNAME(LMatrix4) &other); - INLINE FLOATNAME(LMatrix4) &operator = (const FLOATNAME(LMatrix4) &other); - INLINE FLOATNAME(LMatrix4) &operator = (FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LMatrix4)(); + INLINE_LINMATH FLOATNAME(LMatrix4)(const FLOATNAME(LMatrix4) &other); + INLINE_LINMATH FLOATNAME(LMatrix4) &operator = (const FLOATNAME(LMatrix4) &other); + INLINE_LINMATH FLOATNAME(LMatrix4) &operator = (FLOATTYPE fill_value); - INLINE FLOATNAME(LMatrix4)(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, FLOATTYPE e03, + INLINE_LINMATH FLOATNAME(LMatrix4)(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, FLOATTYPE e03, FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12, FLOATTYPE e13, FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22, FLOATTYPE e23, FLOATTYPE e30, FLOATTYPE e31, FLOATTYPE e32, FLOATTYPE e33); // Construct a 4x4 matrix given a 3x3 rotation matrix and an optional // translation component. - INLINE FLOATNAME(LMatrix4)(const FLOATNAME(LMatrix3) &upper3); - INLINE FLOATNAME(LMatrix4)(const FLOATNAME(LMatrix3) &upper3,const FLOATNAME(LVecBase3) &trans); + INLINE_LINMATH FLOATNAME(LMatrix4)(const FLOATNAME(LMatrix3) &upper3); + INLINE_LINMATH FLOATNAME(LMatrix4)(const FLOATNAME(LMatrix3) &upper3,const FLOATNAME(LVecBase3) &trans); - INLINE void fill(FLOATTYPE fill_value); - INLINE void set(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, FLOATTYPE e03, + INLINE_LINMATH void fill(FLOATTYPE fill_value); + INLINE_LINMATH void set(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, FLOATTYPE e03, FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12, FLOATTYPE e13, FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22, FLOATTYPE e23, FLOATTYPE e30, FLOATTYPE e31, FLOATTYPE e32, FLOATTYPE e33); // Get and set the upper 3x3 rotation matrix. - INLINE void set_upper_3(const FLOATNAME(LMatrix3) &upper3); - INLINE FLOATNAME(LMatrix3) get_upper_3() const; + INLINE_LINMATH void set_upper_3(const FLOATNAME(LMatrix3) &upper3); + INLINE_LINMATH FLOATNAME(LMatrix3) get_upper_3() const; - INLINE void set_row(int row, const FLOATNAME(LVecBase4) &v); - INLINE void set_col(int col, const FLOATNAME(LVecBase4) &v); + INLINE_LINMATH void set_row(int row, const FLOATNAME(LVecBase4) &v); + INLINE_LINMATH void set_col(int col, const FLOATNAME(LVecBase4) &v); - INLINE void set_row(int row, const FLOATNAME(LVecBase3) &v); - INLINE void set_col(int col, const FLOATNAME(LVecBase3) &v); + INLINE_LINMATH void set_row(int row, const FLOATNAME(LVecBase3) &v); + INLINE_LINMATH void set_col(int col, const FLOATNAME(LVecBase3) &v); - INLINE FLOATNAME(LVecBase4) get_row(int row) const; - INLINE FLOATNAME(LVecBase4) get_col(int col) const; + INLINE_LINMATH FLOATNAME(LVecBase4) get_row(int row) const; + INLINE_LINMATH FLOATNAME(LVecBase4) get_col(int col) const; - INLINE FLOATNAME(LVecBase3) get_row3(int row) const; - INLINE FLOATNAME(LVecBase3) get_col3(int col) const; + INLINE_LINMATH FLOATNAME(LVecBase3) get_row3(int row) const; + INLINE_LINMATH FLOATNAME(LVecBase3) get_col3(int col) const; - INLINE FLOATTYPE &operator () (int row, int col); - INLINE FLOATTYPE operator () (int row, int col) const; + INLINE_LINMATH FLOATTYPE &operator () (int row, int col); + INLINE_LINMATH FLOATTYPE operator () (int row, int col) const; - INLINE bool is_nan() const; + INLINE_LINMATH bool is_nan() const; - INLINE FLOATTYPE get_cell(int row, int col) const; - INLINE void set_cell(int row, int col, FLOATTYPE value); + INLINE_LINMATH FLOATTYPE get_cell(int row, int col) const; + INLINE_LINMATH void set_cell(int row, int col, FLOATTYPE value); - INLINE const FLOATTYPE *get_data() const; - INLINE int get_num_components() const; + INLINE_LINMATH const FLOATTYPE *get_data() const; + INLINE_LINMATH int get_num_components() const; - INLINE iterator begin(); - INLINE iterator end(); + INLINE_LINMATH iterator begin(); + INLINE_LINMATH iterator end(); - INLINE const_iterator begin() const; - INLINE const_iterator end() const; + INLINE_LINMATH const_iterator begin() const; + INLINE_LINMATH const_iterator end() const; - INLINE bool operator < (const FLOATNAME(LMatrix4) &other) const; - INLINE bool operator == (const FLOATNAME(LMatrix4) &other) const; - INLINE bool operator != (const FLOATNAME(LMatrix4) &other) const; + INLINE_LINMATH bool operator < (const FLOATNAME(LMatrix4) &other) const; + INLINE_LINMATH bool operator == (const FLOATNAME(LMatrix4) &other) const; + INLINE_LINMATH bool operator != (const FLOATNAME(LMatrix4) &other) const; - INLINE int compare_to(const FLOATNAME(LMatrix4) &other) const; + INLINE_LINMATH int compare_to(const FLOATNAME(LMatrix4) &other) const; int compare_to(const FLOATNAME(LMatrix4) &other, FLOATTYPE threshold) const; - INLINE FLOATNAME(LVecBase4) + INLINE_LINMATH FLOATNAME(LVecBase4) xform(const FLOATNAME(LVecBase4) &v) const; - INLINE FLOATNAME(LVecBase3) + INLINE_LINMATH FLOATNAME(LVecBase3) xform_point(const FLOATNAME(LVecBase3) &v) const; - INLINE FLOATNAME(LVecBase3) + INLINE_LINMATH FLOATNAME(LVecBase3) xform_vec(const FLOATNAME(LVecBase3) &v) const; - INLINE FLOATNAME(LMatrix4) operator * (const FLOATNAME(LMatrix4) &other) const; - INLINE FLOATNAME(LMatrix4) operator * (FLOATTYPE scalar) const; - INLINE FLOATNAME(LMatrix4) operator / (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATNAME(LMatrix4) operator * (const FLOATNAME(LMatrix4) &other) const; + INLINE_LINMATH FLOATNAME(LMatrix4) operator * (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATNAME(LMatrix4) operator / (FLOATTYPE scalar) const; - INLINE FLOATNAME(LMatrix4) &operator += (const FLOATNAME(LMatrix4) &other); - INLINE FLOATNAME(LMatrix4) &operator -= (const FLOATNAME(LMatrix4) &other); + INLINE_LINMATH FLOATNAME(LMatrix4) &operator += (const FLOATNAME(LMatrix4) &other); + INLINE_LINMATH FLOATNAME(LMatrix4) &operator -= (const FLOATNAME(LMatrix4) &other); - INLINE FLOATNAME(LMatrix4) &operator *= (const FLOATNAME(LMatrix4) &other); + INLINE_LINMATH FLOATNAME(LMatrix4) &operator *= (const FLOATNAME(LMatrix4) &other); - INLINE FLOATNAME(LMatrix4) &operator *= (FLOATTYPE scalar); - INLINE FLOATNAME(LMatrix4) &operator /= (FLOATTYPE scalar); + INLINE_LINMATH FLOATNAME(LMatrix4) &operator *= (FLOATTYPE scalar); + INLINE_LINMATH FLOATNAME(LMatrix4) &operator /= (FLOATTYPE scalar); - INLINE void transpose_from(const FLOATNAME(LMatrix4) &other); - INLINE void transpose_in_place(); + INLINE_LINMATH void transpose_from(const FLOATNAME(LMatrix4) &other); + INLINE_LINMATH void transpose_in_place(); - INLINE bool invert_from(const FLOATNAME(LMatrix4) &other); - INLINE bool invert_affine_from(const FLOATNAME(LMatrix4) &other); - INLINE bool invert_in_place(); + INLINE_LINMATH bool invert_from(const FLOATNAME(LMatrix4) &other); + INLINE_LINMATH bool invert_affine_from(const FLOATNAME(LMatrix4) &other); + INLINE_LINMATH bool invert_in_place(); - INLINE static const FLOATNAME(LMatrix4) &ident_mat(); - INLINE static FLOATNAME(LMatrix4) translate_mat(const FLOATNAME(LVecBase3) &trans); - INLINE static FLOATNAME(LMatrix4) translate_mat(FLOATTYPE tx, FLOATTYPE ty, FLOATTYPE tz); - INLINE static FLOATNAME(LMatrix4) rotate_mat(FLOATTYPE angle, - FLOATNAME(LVecBase3) axis, + INLINE_LINMATH static const FLOATNAME(LMatrix4) &ident_mat(); + INLINE_LINMATH static FLOATNAME(LMatrix4) translate_mat(const FLOATNAME(LVecBase3) &trans); + INLINE_LINMATH static FLOATNAME(LMatrix4) translate_mat(FLOATTYPE tx, FLOATTYPE ty, FLOATTYPE tz); + INLINE_LINMATH static FLOATNAME(LMatrix4) rotate_mat(FLOATTYPE angle, + FLOATNAME(LVecBase3) &axis, CoordinateSystem cs = CS_default); - INLINE static FLOATNAME(LMatrix4) scale_mat(const FLOATNAME(LVecBase3) &scale); - INLINE static FLOATNAME(LMatrix4) scale_mat(FLOATTYPE sx, FLOATTYPE sy, FLOATTYPE sz); - INLINE static FLOATNAME(LMatrix4) scale_mat(FLOATTYPE scale); + INLINE_LINMATH static FLOATNAME(LMatrix4) scale_mat(const FLOATNAME(LVecBase3) &scale); + INLINE_LINMATH static FLOATNAME(LMatrix4) scale_mat(FLOATTYPE sx, FLOATTYPE sy, FLOATTYPE sz); + INLINE_LINMATH static FLOATNAME(LMatrix4) scale_mat(FLOATTYPE scale); - INLINE static const FLOATNAME(LMatrix4) &y_to_z_up_mat(); - INLINE static const FLOATNAME(LMatrix4) &z_to_y_up_mat(); + INLINE_LINMATH static const FLOATNAME(LMatrix4) &y_to_z_up_mat(); + INLINE_LINMATH static const FLOATNAME(LMatrix4) &z_to_y_up_mat(); static FLOATNAME(LMatrix4) convert_mat(CoordinateSystem from, CoordinateSystem to); bool almost_equal(const FLOATNAME(LMatrix4) &other, FLOATTYPE threshold) const; - INLINE bool almost_equal(const FLOATNAME(LMatrix4) &other) const; + INLINE_LINMATH bool almost_equal(const FLOATNAME(LMatrix4) &other) const; - INLINE void output(ostream &out) const; - INLINE void write(ostream &out, int indent_level = 0) const; + INLINE_LINMATH void output(ostream &out) const; + INLINE_LINMATH void write(ostream &out, int indent_level = 0) const; +public: + + union { + struct { + FLOATTYPE _00, _01, _02, _03; + FLOATTYPE _10, _11, _12, _13; + FLOATTYPE _20, _21, _22, _23; + FLOATTYPE _30, _31, _32, _33; + } m; + + FLOATTYPE data[4 * 4]; + } _m; + private: - INLINE FLOATTYPE mult_cel(const FLOATNAME(LMatrix4) &other, int x, int y) const; + INLINE_LINMATH FLOATTYPE mult_cel(const FLOATNAME(LMatrix4) &other, int x, int y) const; bool decompose_mat(int index[4]); bool back_sub_mat(int index[4], FLOATNAME(LMatrix4) &inv, int row) const; - FLOATTYPE _data[4 * 4]; static const FLOATNAME(LMatrix4) _ident_mat; static const FLOATNAME(LMatrix4) _y_to_z_up_mat; static const FLOATNAME(LMatrix4) _z_to_y_up_mat; @@ -150,12 +162,14 @@ private: static TypeHandle _type_handle; }; -INLINE ostream &operator << (ostream &out, const FLOATNAME(LMatrix4) &mat) { + +INLINE_LINMATH ostream &operator << (ostream &out, const FLOATNAME(LMatrix4) &mat) { mat.output(out); return out; } -INLINE FLOATNAME(LMatrix4) transpose(const FLOATNAME(LMatrix4) &a); -INLINE FLOATNAME(LMatrix4) invert(const FLOATNAME(LMatrix4) &a); + +INLINE_LINMATH FLOATNAME(LMatrix4) transpose(const FLOATNAME(LMatrix4) &a); +INLINE_LINMATH FLOATNAME(LMatrix4) invert(const FLOATNAME(LMatrix4) &a); #include "lmatrix4_src.I" diff --git a/panda/src/linmath/lorientation_src.I b/panda/src/linmath/lorientation_src.I index c52444a920..693b1df825 100644 --- a/panda/src/linmath/lorientation_src.I +++ b/panda/src/linmath/lorientation_src.I @@ -8,7 +8,7 @@ // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LOrientation):: +INLINE_LINMATH FLOATNAME(LOrientation):: FLOATNAME(LOrientation)() { } @@ -17,7 +17,7 @@ FLOATNAME(LOrientation)() { // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LOrientation):: +INLINE_LINMATH FLOATNAME(LOrientation):: FLOATNAME(LOrientation)(const FLOATNAME(LQuaternion)& c) : FLOATNAME(LQuaternion)(c) { } @@ -27,7 +27,7 @@ FLOATNAME(LOrientation)(const FLOATNAME(LQuaternion)& c) : // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LOrientation):: +INLINE_LINMATH FLOATNAME(LOrientation):: FLOATNAME(LOrientation)(FLOATTYPE r, FLOATTYPE i, FLOATTYPE j, FLOATTYPE k) : FLOATNAME(LQuaternion)(r, i, j, k) { } @@ -37,7 +37,7 @@ FLOATNAME(LOrientation)(FLOATTYPE r, FLOATTYPE i, FLOATTYPE j, FLOATTYPE k) : // Access: public // Description: vector + twist //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LOrientation):: +INLINE_LINMATH FLOATNAME(LOrientation):: FLOATNAME(LOrientation)(const FLOATNAME(LVector3) &point_at, float twist) { float radians = twist * ((float) MathNumbers::pi / 180.0f); float theta_over_2 = radians / 2.0f; @@ -54,7 +54,7 @@ FLOATNAME(LOrientation)(const FLOATNAME(LVector3) &point_at, float twist) { // Access: public // Description: matrix3 //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LOrientation):: +INLINE_LINMATH FLOATNAME(LOrientation):: FLOATNAME(LOrientation)(const FLOATNAME(LMatrix3) &m) { set_from_matrix(m); } @@ -64,7 +64,7 @@ FLOATNAME(LOrientation)(const FLOATNAME(LMatrix3) &m) { // Access: public // Description: matrix4 //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LOrientation):: +INLINE_LINMATH FLOATNAME(LOrientation):: FLOATNAME(LOrientation)(const FLOATNAME(LMatrix4) &m) { set_from_matrix(m); } @@ -75,7 +75,7 @@ FLOATNAME(LOrientation)(const FLOATNAME(LMatrix4) &m) { // Description: Orientation * rotation = Orientation // Applies an rotation to an orientation. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LOrientation) FLOATNAME(LOrientation):: +INLINE_LINMATH FLOATNAME(LOrientation) FLOATNAME(LOrientation):: operator *(const FLOATNAME(LQuaternion)& other) const { return multiply(other); } @@ -87,7 +87,7 @@ operator *(const FLOATNAME(LQuaternion)& other) const { // This is a meaningless operation, and will always // simply return the rhs. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LOrientation) FLOATNAME(LOrientation):: +INLINE_LINMATH FLOATNAME(LOrientation) FLOATNAME(LOrientation):: operator *(const FLOATNAME(LOrientation)& other) const { return other; } diff --git a/panda/src/linmath/lorientation_src.h b/panda/src/linmath/lorientation_src.h index 33ddabcddb..8a01feaddd 100644 --- a/panda/src/linmath/lorientation_src.h +++ b/panda/src/linmath/lorientation_src.h @@ -9,17 +9,17 @@ //////////////////////////////////////////////////////////////////////// class EXPCL_PANDA FLOATNAME(LOrientation) : public FLOATNAME(LQuaternion) { public: - INLINE FLOATNAME(LOrientation)(); - INLINE FLOATNAME(LOrientation)(const FLOATNAME(LQuaternion)&); - INLINE FLOATNAME(LOrientation)(FLOATTYPE, FLOATTYPE, FLOATTYPE, FLOATTYPE); - INLINE FLOATNAME(LOrientation)(const FLOATNAME(LVector3) &, float); - INLINE FLOATNAME(LOrientation)(const FLOATNAME(LMatrix3) &); - INLINE FLOATNAME(LOrientation)(const FLOATNAME(LMatrix4) &); + INLINE_LINMATH FLOATNAME(LOrientation)(); + INLINE_LINMATH FLOATNAME(LOrientation)(const FLOATNAME(LQuaternion)&); + INLINE_LINMATH FLOATNAME(LOrientation)(FLOATTYPE, FLOATTYPE, FLOATTYPE, FLOATTYPE); + INLINE_LINMATH FLOATNAME(LOrientation)(const FLOATNAME(LVector3) &, float); + INLINE_LINMATH FLOATNAME(LOrientation)(const FLOATNAME(LMatrix3) &); + INLINE_LINMATH FLOATNAME(LOrientation)(const FLOATNAME(LMatrix4) &); - INLINE FLOATNAME(LOrientation) + INLINE_LINMATH FLOATNAME(LOrientation) operator *(const FLOATNAME(LQuaternion)& other) const; - INLINE FLOATNAME(LOrientation) + INLINE_LINMATH FLOATNAME(LOrientation) operator *(const FLOATNAME(LOrientation)& other) const; public: diff --git a/panda/src/linmath/lpoint2_src.I b/panda/src/linmath/lpoint2_src.I index 9542ce2e5d..0419fbaaed 100644 --- a/panda/src/linmath/lpoint2_src.I +++ b/panda/src/linmath/lpoint2_src.I @@ -9,7 +9,7 @@ // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint2):: +INLINE_LINMATH FLOATNAME(LPoint2):: FLOATNAME(LPoint2)() { } @@ -18,7 +18,7 @@ FLOATNAME(LPoint2)() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint2):: +INLINE_LINMATH FLOATNAME(LPoint2):: FLOATNAME(LPoint2)(const FLOATNAME(LVecBase2) ©) : FLOATNAME(LVecBase2)(copy) { } @@ -27,7 +27,7 @@ FLOATNAME(LPoint2)(const FLOATNAME(LVecBase2) ©) : FLOATNAME(LVecBase2)(copy // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint2) &FLOATNAME(LPoint2):: +INLINE_LINMATH FLOATNAME(LPoint2) &FLOATNAME(LPoint2):: operator = (const FLOATNAME(LVecBase2) ©) { FLOATNAME(LVecBase2)::operator = (copy); return *this; @@ -38,7 +38,7 @@ operator = (const FLOATNAME(LVecBase2) ©) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint2) &FLOATNAME(LPoint2):: +INLINE_LINMATH FLOATNAME(LPoint2) &FLOATNAME(LPoint2):: operator = (FLOATTYPE fill_value) { FLOATNAME(LVecBase2)::operator = (fill_value); return *this; @@ -49,7 +49,7 @@ operator = (FLOATTYPE fill_value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint2):: +INLINE_LINMATH FLOATNAME(LPoint2):: FLOATNAME(LPoint2)(FLOATTYPE fill_value) : FLOATNAME(LVecBase2)(fill_value) { @@ -60,7 +60,7 @@ FLOATNAME(LPoint2)(FLOATTYPE fill_value) : // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint2):: +INLINE_LINMATH FLOATNAME(LPoint2):: FLOATNAME(LPoint2)(FLOATTYPE x, FLOATTYPE y) : FLOATNAME(LVecBase2)(x, y) { @@ -71,7 +71,7 @@ FLOATNAME(LPoint2)(FLOATTYPE x, FLOATTYPE y) : // Access: Public // Description: Returns a zero-length point. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LPoint2) &FLOATNAME(LPoint2):: +INLINE_LINMATH const FLOATNAME(LPoint2) &FLOATNAME(LPoint2):: zero() { return (const FLOATNAME(LPoint2) &)FLOATNAME(LVecBase2)::zero(); } @@ -81,7 +81,7 @@ zero() { // Access: Public // Description: Returns a unit X point. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LPoint2) &FLOATNAME(LPoint2):: +INLINE_LINMATH const FLOATNAME(LPoint2) &FLOATNAME(LPoint2):: unit_x() { return (const FLOATNAME(LPoint2) &)FLOATNAME(LVecBase2)::unit_x(); } @@ -91,7 +91,7 @@ unit_x() { // Access: Public // Description: Returns a unit Y point. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LPoint2) &FLOATNAME(LPoint2):: +INLINE_LINMATH const FLOATNAME(LPoint2) &FLOATNAME(LPoint2):: unit_y() { return (const FLOATNAME(LPoint2) &)FLOATNAME(LVecBase2)::unit_y(); } @@ -101,7 +101,7 @@ unit_y() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint2) FLOATNAME(LPoint2):: +INLINE_LINMATH FLOATNAME(LPoint2) FLOATNAME(LPoint2):: operator - () const { return FLOATNAME(LVecBase2)::operator - (); } @@ -111,7 +111,7 @@ operator - () const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2) FLOATNAME(LPoint2):: +INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LPoint2):: operator + (const FLOATNAME(LVecBase2) &other) const { return FLOATNAME(LVecBase2)::operator + (other); } @@ -121,7 +121,7 @@ operator + (const FLOATNAME(LVecBase2) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint2) FLOATNAME(LPoint2):: +INLINE_LINMATH FLOATNAME(LPoint2) FLOATNAME(LPoint2):: operator + (const FLOATNAME(LVector2) &other) const { return FLOATNAME(LVecBase2)::operator + (other); } @@ -131,7 +131,7 @@ operator + (const FLOATNAME(LVector2) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2) FLOATNAME(LPoint2):: +INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LPoint2):: operator - (const FLOATNAME(LVecBase2) &other) const { return FLOATNAME(LVecBase2)::operator - (other); } @@ -141,7 +141,7 @@ operator - (const FLOATNAME(LVecBase2) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector2) FLOATNAME(LPoint2):: +INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LPoint2):: operator - (const FLOATNAME(LPoint2) &other) const { return FLOATNAME(LVecBase2)::operator - (other); } @@ -151,7 +151,7 @@ operator - (const FLOATNAME(LPoint2) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint2) FLOATNAME(LPoint2):: +INLINE_LINMATH FLOATNAME(LPoint2) FLOATNAME(LPoint2):: operator - (const FLOATNAME(LVector2) &other) const { return FLOATNAME(LVecBase2)::operator - (other); } @@ -161,7 +161,7 @@ operator - (const FLOATNAME(LVector2) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint2) FLOATNAME(LPoint2):: +INLINE_LINMATH FLOATNAME(LPoint2) FLOATNAME(LPoint2):: operator * (FLOATTYPE scalar) const { return FLOATNAME(LPoint2)(FLOATNAME(LVecBase2)::operator * (scalar)); } @@ -171,7 +171,7 @@ operator * (FLOATTYPE scalar) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint2) FLOATNAME(LPoint2):: +INLINE_LINMATH FLOATNAME(LPoint2) FLOATNAME(LPoint2):: operator / (FLOATTYPE scalar) const { return FLOATNAME(LPoint2)(FLOATNAME(LVecBase2)::operator / (scalar)); } diff --git a/panda/src/linmath/lpoint2_src.h b/panda/src/linmath/lpoint2_src.h index 876082987b..01e8dc2a8e 100644 --- a/panda/src/linmath/lpoint2_src.h +++ b/panda/src/linmath/lpoint2_src.h @@ -10,33 +10,33 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA FLOATNAME(LPoint2) : public FLOATNAME(LVecBase2) { PUBLISHED: - INLINE FLOATNAME(LPoint2)(); - INLINE FLOATNAME(LPoint2)(const FLOATNAME(LVecBase2) ©); - INLINE FLOATNAME(LPoint2) &operator = (const FLOATNAME(LVecBase2) ©); - INLINE FLOATNAME(LPoint2) &operator = (FLOATTYPE fill_value); - INLINE FLOATNAME(LPoint2)(FLOATTYPE fill_value); - INLINE FLOATNAME(LPoint2)(FLOATTYPE x, FLOATTYPE y); + INLINE_LINMATH FLOATNAME(LPoint2)(); + INLINE_LINMATH FLOATNAME(LPoint2)(const FLOATNAME(LVecBase2) ©); + INLINE_LINMATH FLOATNAME(LPoint2) &operator = (const FLOATNAME(LVecBase2) ©); + INLINE_LINMATH FLOATNAME(LPoint2) &operator = (FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LPoint2)(FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LPoint2)(FLOATTYPE x, FLOATTYPE y); - INLINE static const FLOATNAME(LPoint2) &zero(); - INLINE static const FLOATNAME(LPoint2) &unit_x(); - INLINE static const FLOATNAME(LPoint2) &unit_y(); + INLINE_LINMATH static const FLOATNAME(LPoint2) &zero(); + INLINE_LINMATH static const FLOATNAME(LPoint2) &unit_x(); + INLINE_LINMATH static const FLOATNAME(LPoint2) &unit_y(); - INLINE FLOATNAME(LPoint2) operator - () const; + INLINE_LINMATH FLOATNAME(LPoint2) operator - () const; - INLINE FLOATNAME(LVecBase2) + INLINE_LINMATH FLOATNAME(LVecBase2) operator + (const FLOATNAME(LVecBase2) &other) const; - INLINE FLOATNAME(LPoint2) + INLINE_LINMATH FLOATNAME(LPoint2) operator + (const FLOATNAME(LVector2) &other) const; - INLINE FLOATNAME(LVecBase2) + INLINE_LINMATH FLOATNAME(LVecBase2) operator - (const FLOATNAME(LVecBase2) &other) const; - INLINE FLOATNAME(LVector2) + INLINE_LINMATH FLOATNAME(LVector2) operator - (const FLOATNAME(LPoint2) &other) const; - INLINE FLOATNAME(LPoint2) + INLINE_LINMATH FLOATNAME(LPoint2) operator - (const FLOATNAME(LVector2) &other) const; - INLINE FLOATNAME(LPoint2) operator * (FLOATTYPE scalar) const; - INLINE FLOATNAME(LPoint2) operator / (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATNAME(LPoint2) operator * (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATNAME(LPoint2) operator / (FLOATTYPE scalar) const; public: static TypeHandle get_class_type() { diff --git a/panda/src/linmath/lpoint3_src.I b/panda/src/linmath/lpoint3_src.I index 22ae1fbf2f..c6d90a7cef 100644 --- a/panda/src/linmath/lpoint3_src.I +++ b/panda/src/linmath/lpoint3_src.I @@ -9,7 +9,7 @@ // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint3):: +INLINE_LINMATH FLOATNAME(LPoint3):: FLOATNAME(LPoint3)() { } @@ -18,7 +18,7 @@ FLOATNAME(LPoint3)() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint3):: +INLINE_LINMATH FLOATNAME(LPoint3):: FLOATNAME(LPoint3)(const FLOATNAME(LVecBase3) ©) : FLOATNAME(LVecBase3)(copy) { } @@ -27,7 +27,7 @@ FLOATNAME(LPoint3)(const FLOATNAME(LVecBase3) ©) : FLOATNAME(LVecBase3)(copy // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint3) &FLOATNAME(LPoint3):: +INLINE_LINMATH FLOATNAME(LPoint3) &FLOATNAME(LPoint3):: operator = (const FLOATNAME(LVecBase3) ©) { FLOATNAME(LVecBase3)::operator = (copy); return *this; @@ -38,7 +38,7 @@ operator = (const FLOATNAME(LVecBase3) ©) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint3) &FLOATNAME(LPoint3):: +INLINE_LINMATH FLOATNAME(LPoint3) &FLOATNAME(LPoint3):: operator = (FLOATTYPE fill_value) { FLOATNAME(LVecBase3)::operator = (fill_value); return *this; @@ -49,7 +49,7 @@ operator = (FLOATTYPE fill_value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint3):: +INLINE_LINMATH FLOATNAME(LPoint3):: FLOATNAME(LPoint3)(FLOATTYPE fill_value) : FLOATNAME(LVecBase3)(fill_value) { @@ -60,7 +60,7 @@ FLOATNAME(LPoint3)(FLOATTYPE fill_value) : // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint3):: +INLINE_LINMATH FLOATNAME(LPoint3):: FLOATNAME(LPoint3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) : FLOATNAME(LVecBase3)(x, y, z) { @@ -71,7 +71,7 @@ FLOATNAME(LPoint3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) : // Access: Public // Description: Returns a zero-length point. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LPoint3) &FLOATNAME(LPoint3):: +INLINE_LINMATH const FLOATNAME(LPoint3) &FLOATNAME(LPoint3):: zero() { return (const FLOATNAME(LPoint3) &)FLOATNAME(LVecBase3)::zero(); } @@ -81,7 +81,7 @@ zero() { // Access: Public // Description: Returns a unit X point. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LPoint3) &FLOATNAME(LPoint3):: +INLINE_LINMATH const FLOATNAME(LPoint3) &FLOATNAME(LPoint3):: unit_x() { return (const FLOATNAME(LPoint3) &)FLOATNAME(LVecBase3)::unit_x(); } @@ -91,7 +91,7 @@ unit_x() { // Access: Public // Description: Returns a unit Y point. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LPoint3) &FLOATNAME(LPoint3):: +INLINE_LINMATH const FLOATNAME(LPoint3) &FLOATNAME(LPoint3):: unit_y() { return (const FLOATNAME(LPoint3) &)FLOATNAME(LVecBase3)::unit_y(); } @@ -101,7 +101,7 @@ unit_y() { // Access: Public // Description: Returns a unit Z point. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LPoint3) &FLOATNAME(LPoint3):: +INLINE_LINMATH const FLOATNAME(LPoint3) &FLOATNAME(LPoint3):: unit_z() { return (const FLOATNAME(LPoint3) &)FLOATNAME(LVecBase3)::unit_z(); } @@ -111,7 +111,7 @@ unit_z() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint3) FLOATNAME(LPoint3):: +INLINE_LINMATH FLOATNAME(LPoint3) FLOATNAME(LPoint3):: operator - () const { return FLOATNAME(LVecBase3)::operator - (); } @@ -121,7 +121,7 @@ operator - () const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) FLOATNAME(LPoint3):: +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LPoint3):: operator + (const FLOATNAME(LVecBase3) &other) const { return FLOATNAME(LVecBase3)::operator + (other); } @@ -131,7 +131,7 @@ operator + (const FLOATNAME(LVecBase3) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint3) FLOATNAME(LPoint3):: +INLINE_LINMATH FLOATNAME(LPoint3) FLOATNAME(LPoint3):: operator + (const FLOATNAME(LVector3) &other) const { return FLOATNAME(LVecBase3)::operator + (other); } @@ -141,7 +141,7 @@ operator + (const FLOATNAME(LVector3) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) FLOATNAME(LPoint3):: +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LPoint3):: operator - (const FLOATNAME(LVecBase3) &other) const { return FLOATNAME(LVecBase3)::operator - (other); } @@ -151,7 +151,7 @@ operator - (const FLOATNAME(LVecBase3) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) FLOATNAME(LPoint3):: +INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LPoint3):: operator - (const FLOATNAME(LPoint3) &other) const { return FLOATNAME(LVecBase3)::operator - (other); } @@ -161,7 +161,7 @@ operator - (const FLOATNAME(LPoint3) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint3) FLOATNAME(LPoint3):: +INLINE_LINMATH FLOATNAME(LPoint3) FLOATNAME(LPoint3):: operator - (const FLOATNAME(LVector3) &other) const { return FLOATNAME(LVecBase3)::operator - (other); } @@ -171,7 +171,7 @@ operator - (const FLOATNAME(LVector3) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint3) FLOATNAME(LPoint3):: +INLINE_LINMATH FLOATNAME(LPoint3) FLOATNAME(LPoint3):: cross(const FLOATNAME(LVecBase3) &other) const { return FLOATNAME(LVecBase3)::cross(other); } @@ -181,7 +181,7 @@ cross(const FLOATNAME(LVecBase3) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint3) FLOATNAME(LPoint3):: +INLINE_LINMATH FLOATNAME(LPoint3) FLOATNAME(LPoint3):: operator * (FLOATTYPE scalar) const { return FLOATNAME(LPoint3)(FLOATNAME(LVecBase3)::operator * (scalar)); } @@ -191,7 +191,7 @@ operator * (FLOATTYPE scalar) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint3) FLOATNAME(LPoint3):: +INLINE_LINMATH FLOATNAME(LPoint3) FLOATNAME(LPoint3):: operator / (FLOATTYPE scalar) const { return FLOATNAME(LPoint3)(FLOATNAME(LVecBase3)::operator / (scalar)); } @@ -204,7 +204,7 @@ operator / (FLOATTYPE scalar) const { // existing coordinate systems; it's hard to imagine it // ever being different. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint3) FLOATNAME(LPoint3):: +INLINE_LINMATH FLOATNAME(LPoint3) FLOATNAME(LPoint3):: origin(CoordinateSystem) { return FLOATNAME(LPoint3)(0.0, 0.0, 0.0); } @@ -216,9 +216,10 @@ origin(CoordinateSystem) { // displacements from the origin, wherever that maps to // in the given coordinate system. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint3) FLOATNAME(LPoint3):: +INLINE_LINMATH FLOATNAME(LPoint3) FLOATNAME(LPoint3):: rfu(FLOATTYPE right_v, FLOATTYPE fwd_v, FLOATTYPE up_v, CoordinateSystem cs) { return origin(cs) + FLOATNAME(LVector3)::rfu(right_v, fwd_v, up_v, cs); } + diff --git a/panda/src/linmath/lpoint3_src.h b/panda/src/linmath/lpoint3_src.h index 74e24f9483..0b17938546 100644 --- a/panda/src/linmath/lpoint3_src.h +++ b/panda/src/linmath/lpoint3_src.h @@ -15,40 +15,40 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA FLOATNAME(LPoint3) : public FLOATNAME(LVecBase3) { PUBLISHED: - INLINE FLOATNAME(LPoint3)(); - INLINE FLOATNAME(LPoint3)(const FLOATNAME(LVecBase3) ©); - INLINE FLOATNAME(LPoint3) &operator = (const FLOATNAME(LVecBase3) ©); - INLINE FLOATNAME(LPoint3) &operator = (FLOATTYPE fill_value); - INLINE FLOATNAME(LPoint3)(FLOATTYPE fill_value); - INLINE FLOATNAME(LPoint3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z); + INLINE_LINMATH FLOATNAME(LPoint3)(); + INLINE_LINMATH FLOATNAME(LPoint3)(const FLOATNAME(LVecBase3) ©); + INLINE_LINMATH FLOATNAME(LPoint3) &operator = (const FLOATNAME(LVecBase3) ©); + INLINE_LINMATH FLOATNAME(LPoint3) &operator = (FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LPoint3)(FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LPoint3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z); - INLINE static const FLOATNAME(LPoint3) &zero(); - INLINE static const FLOATNAME(LPoint3) &unit_x(); - INLINE static const FLOATNAME(LPoint3) &unit_y(); - INLINE static const FLOATNAME(LPoint3) &unit_z(); + INLINE_LINMATH static const FLOATNAME(LPoint3) &zero(); + INLINE_LINMATH static const FLOATNAME(LPoint3) &unit_x(); + INLINE_LINMATH static const FLOATNAME(LPoint3) &unit_y(); + INLINE_LINMATH static const FLOATNAME(LPoint3) &unit_z(); - INLINE FLOATNAME(LPoint3) operator - () const; + INLINE_LINMATH FLOATNAME(LPoint3) operator - () const; - INLINE FLOATNAME(LVecBase3) + INLINE_LINMATH FLOATNAME(LVecBase3) operator + (const FLOATNAME(LVecBase3) &other) const; - INLINE FLOATNAME(LPoint3) + INLINE_LINMATH FLOATNAME(LPoint3) operator + (const FLOATNAME(LVector3) &other) const; - INLINE FLOATNAME(LVecBase3) + INLINE_LINMATH FLOATNAME(LVecBase3) operator - (const FLOATNAME(LVecBase3) &other) const; - INLINE FLOATNAME(LVector3) + INLINE_LINMATH FLOATNAME(LVector3) operator - (const FLOATNAME(LPoint3) &other) const; - INLINE FLOATNAME(LPoint3) + INLINE_LINMATH FLOATNAME(LPoint3) operator - (const FLOATNAME(LVector3) &other) const; - INLINE FLOATNAME(LPoint3) cross(const FLOATNAME(LVecBase3) &other) const; - INLINE FLOATNAME(LPoint3) operator * (FLOATTYPE scalar) const; - INLINE FLOATNAME(LPoint3) operator / (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATNAME(LPoint3) cross(const FLOATNAME(LVecBase3) &other) const; + INLINE_LINMATH FLOATNAME(LPoint3) operator * (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATNAME(LPoint3) operator / (FLOATTYPE scalar) const; // Some special named constructors for LPoint3. - INLINE static FLOATNAME(LPoint3) origin(CoordinateSystem cs = CS_default); - INLINE static FLOATNAME(LPoint3) rfu(FLOATTYPE right, + INLINE_LINMATH static FLOATNAME(LPoint3) origin(CoordinateSystem cs = CS_default); + INLINE_LINMATH static FLOATNAME(LPoint3) rfu(FLOATTYPE right, FLOATTYPE fwd, FLOATTYPE up, CoordinateSystem cs = CS_default); diff --git a/panda/src/linmath/lpoint4_src.I b/panda/src/linmath/lpoint4_src.I index 690a450365..74dbc8c06a 100644 --- a/panda/src/linmath/lpoint4_src.I +++ b/panda/src/linmath/lpoint4_src.I @@ -9,7 +9,7 @@ // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint4):: +INLINE_LINMATH FLOATNAME(LPoint4):: FLOATNAME(LPoint4)() { } @@ -18,7 +18,7 @@ FLOATNAME(LPoint4)() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint4):: +INLINE_LINMATH FLOATNAME(LPoint4):: FLOATNAME(LPoint4)(const FLOATNAME(LVecBase4) ©) : FLOATNAME(LVecBase4)(copy) { } @@ -27,7 +27,7 @@ FLOATNAME(LPoint4)(const FLOATNAME(LVecBase4) ©) : FLOATNAME(LVecBase4)(copy // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint4) &FLOATNAME(LPoint4):: +INLINE_LINMATH FLOATNAME(LPoint4) &FLOATNAME(LPoint4):: operator = (const FLOATNAME(LVecBase4) ©) { FLOATNAME(LVecBase4)::operator = (copy); return *this; @@ -38,7 +38,7 @@ operator = (const FLOATNAME(LVecBase4) ©) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint4) &FLOATNAME(LPoint4):: +INLINE_LINMATH FLOATNAME(LPoint4) &FLOATNAME(LPoint4):: operator = (FLOATTYPE fill_value) { FLOATNAME(LVecBase4)::operator = (fill_value); return *this; @@ -49,7 +49,7 @@ operator = (FLOATTYPE fill_value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint4):: +INLINE_LINMATH FLOATNAME(LPoint4):: FLOATNAME(LPoint4)(FLOATTYPE fill_value) : FLOATNAME(LVecBase4)(fill_value) { @@ -60,7 +60,7 @@ FLOATNAME(LPoint4)(FLOATTYPE fill_value) : // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint4):: +INLINE_LINMATH FLOATNAME(LPoint4):: FLOATNAME(LPoint4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w) : FLOATNAME(LVecBase4)(x, y, z, w) { @@ -71,7 +71,7 @@ FLOATNAME(LPoint4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w) : // Access: Public // Description: Returns a zero-length point. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LPoint4) &FLOATNAME(LPoint4):: +INLINE_LINMATH const FLOATNAME(LPoint4) &FLOATNAME(LPoint4):: zero() { return (const FLOATNAME(LPoint4) &)FLOATNAME(LVecBase4)::zero(); } @@ -81,7 +81,7 @@ zero() { // Access: Public // Description: Returns a unit X point. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LPoint4) &FLOATNAME(LPoint4):: +INLINE_LINMATH const FLOATNAME(LPoint4) &FLOATNAME(LPoint4):: unit_x() { return (const FLOATNAME(LPoint4) &)FLOATNAME(LVecBase4)::unit_x(); } @@ -91,7 +91,7 @@ unit_x() { // Access: Public // Description: Returns a unit Y point. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LPoint4) &FLOATNAME(LPoint4):: +INLINE_LINMATH const FLOATNAME(LPoint4) &FLOATNAME(LPoint4):: unit_y() { return (const FLOATNAME(LPoint4) &)FLOATNAME(LVecBase4)::unit_y(); } @@ -101,7 +101,7 @@ unit_y() { // Access: Public // Description: Returns a unit Z point. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LPoint4) &FLOATNAME(LPoint4):: +INLINE_LINMATH const FLOATNAME(LPoint4) &FLOATNAME(LPoint4):: unit_z() { return (const FLOATNAME(LPoint4) &)FLOATNAME(LVecBase4)::unit_z(); } @@ -111,7 +111,7 @@ unit_z() { // Access: Public // Description: Returns a unit W point. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LPoint4) &FLOATNAME(LPoint4):: +INLINE_LINMATH const FLOATNAME(LPoint4) &FLOATNAME(LPoint4):: unit_w() { return (const FLOATNAME(LPoint4) &)FLOATNAME(LVecBase4)::unit_w(); } @@ -121,7 +121,7 @@ unit_w() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint4) FLOATNAME(LPoint4):: +INLINE_LINMATH FLOATNAME(LPoint4) FLOATNAME(LPoint4):: operator - () const { return FLOATNAME(LVecBase4)::operator - (); } @@ -131,7 +131,7 @@ operator - () const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4) FLOATNAME(LPoint4):: +INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LPoint4):: operator + (const FLOATNAME(LVecBase4) &other) const { return FLOATNAME(LVecBase4)::operator + (other); } @@ -141,7 +141,7 @@ operator + (const FLOATNAME(LVecBase4) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint4) FLOATNAME(LPoint4):: +INLINE_LINMATH FLOATNAME(LPoint4) FLOATNAME(LPoint4):: operator + (const FLOATNAME(LVector4) &other) const { return FLOATNAME(LVecBase4)::operator + (other); } @@ -151,7 +151,7 @@ operator + (const FLOATNAME(LVector4) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4) FLOATNAME(LPoint4):: +INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LPoint4):: operator - (const FLOATNAME(LVecBase4) &other) const { return FLOATNAME(LVecBase4)::operator - (other); } @@ -161,7 +161,7 @@ operator - (const FLOATNAME(LVecBase4) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector4) FLOATNAME(LPoint4):: +INLINE_LINMATH FLOATNAME(LVector4) FLOATNAME(LPoint4):: operator - (const FLOATNAME(LPoint4) &other) const { return FLOATNAME(LVecBase4)::operator - (other); } @@ -171,7 +171,7 @@ operator - (const FLOATNAME(LPoint4) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint4) FLOATNAME(LPoint4):: +INLINE_LINMATH FLOATNAME(LPoint4) FLOATNAME(LPoint4):: operator - (const FLOATNAME(LVector4) &other) const { return FLOATNAME(LVecBase4)::operator - (other); } @@ -181,7 +181,7 @@ operator - (const FLOATNAME(LVector4) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint4) FLOATNAME(LPoint4):: +INLINE_LINMATH FLOATNAME(LPoint4) FLOATNAME(LPoint4):: operator * (FLOATTYPE scalar) const { return FLOATNAME(LPoint4)(FLOATNAME(LVecBase4)::operator * (scalar)); } @@ -191,7 +191,7 @@ operator * (FLOATTYPE scalar) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint4) FLOATNAME(LPoint4):: +INLINE_LINMATH FLOATNAME(LPoint4) FLOATNAME(LPoint4):: operator / (FLOATTYPE scalar) const { return FLOATNAME(LPoint4)(FLOATNAME(LVecBase4)::operator / (scalar)); } diff --git a/panda/src/linmath/lpoint4_src.h b/panda/src/linmath/lpoint4_src.h index 46c71db230..00de0ee02d 100644 --- a/panda/src/linmath/lpoint4_src.h +++ b/panda/src/linmath/lpoint4_src.h @@ -9,35 +9,35 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA FLOATNAME(LPoint4) : public FLOATNAME(LVecBase4) { PUBLISHED: - INLINE FLOATNAME(LPoint4)(); - INLINE FLOATNAME(LPoint4)(const FLOATNAME(LVecBase4) ©); - INLINE FLOATNAME(LPoint4) &operator = (const FLOATNAME(LVecBase4) ©); - INLINE FLOATNAME(LPoint4) &operator = (FLOATTYPE fill_value); - INLINE FLOATNAME(LPoint4)(FLOATTYPE fill_value); - INLINE FLOATNAME(LPoint4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); + INLINE_LINMATH FLOATNAME(LPoint4)(); + INLINE_LINMATH FLOATNAME(LPoint4)(const FLOATNAME(LVecBase4) ©); + INLINE_LINMATH FLOATNAME(LPoint4) &operator = (const FLOATNAME(LVecBase4) ©); + INLINE_LINMATH FLOATNAME(LPoint4) &operator = (FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LPoint4)(FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LPoint4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); - INLINE static const FLOATNAME(LPoint4) &zero(); - INLINE static const FLOATNAME(LPoint4) &unit_x(); - INLINE static const FLOATNAME(LPoint4) &unit_y(); - INLINE static const FLOATNAME(LPoint4) &unit_z(); - INLINE static const FLOATNAME(LPoint4) &unit_w(); + INLINE_LINMATH static const FLOATNAME(LPoint4) &zero(); + INLINE_LINMATH static const FLOATNAME(LPoint4) &unit_x(); + INLINE_LINMATH static const FLOATNAME(LPoint4) &unit_y(); + INLINE_LINMATH static const FLOATNAME(LPoint4) &unit_z(); + INLINE_LINMATH static const FLOATNAME(LPoint4) &unit_w(); - INLINE FLOATNAME(LPoint4) operator - () const; + INLINE_LINMATH FLOATNAME(LPoint4) operator - () const; - INLINE FLOATNAME(LVecBase4) + INLINE_LINMATH FLOATNAME(LVecBase4) operator + (const FLOATNAME(LVecBase4) &other) const; - INLINE FLOATNAME(LPoint4) + INLINE_LINMATH FLOATNAME(LPoint4) operator + (const FLOATNAME(LVector4) &other) const; - INLINE FLOATNAME(LVecBase4) + INLINE_LINMATH FLOATNAME(LVecBase4) operator - (const FLOATNAME(LVecBase4) &other) const; - INLINE FLOATNAME(LVector4) + INLINE_LINMATH FLOATNAME(LVector4) operator - (const FLOATNAME(LPoint4) &other) const; - INLINE FLOATNAME(LPoint4) + INLINE_LINMATH FLOATNAME(LPoint4) operator - (const FLOATNAME(LVector4) &other) const; - INLINE FLOATNAME(LPoint4) operator * (FLOATTYPE scalar) const; - INLINE FLOATNAME(LPoint4) operator / (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATNAME(LPoint4) operator * (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATNAME(LPoint4) operator / (FLOATTYPE scalar) const; public: static TypeHandle get_class_type() { diff --git a/panda/src/linmath/lquaternion_src.I b/panda/src/linmath/lquaternion_src.I index 50f73ce2dc..14e391461b 100644 --- a/panda/src/linmath/lquaternion_src.I +++ b/panda/src/linmath/lquaternion_src.I @@ -8,7 +8,7 @@ // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LQuaternion):: +INLINE_LINMATH FLOATNAME(LQuaternion):: FLOATNAME(LQuaternion)() { } @@ -17,7 +17,7 @@ FLOATNAME(LQuaternion)() { // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LQuaternion):: +INLINE_LINMATH FLOATNAME(LQuaternion):: FLOATNAME(LQuaternion)(const FLOATNAME(LQuaternion) &c) : FLOATNAME(LVecBase4)(c) { @@ -28,7 +28,7 @@ FLOATNAME(LQuaternion)(const FLOATNAME(LQuaternion) &c) : // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LQuaternion):: +INLINE_LINMATH FLOATNAME(LQuaternion):: FLOATNAME(LQuaternion)(FLOATTYPE r, FLOATTYPE i, FLOATTYPE j, FLOATTYPE k) { set(r, i, j, k); } @@ -38,12 +38,12 @@ FLOATNAME(LQuaternion)(FLOATTYPE r, FLOATTYPE i, FLOATTYPE j, FLOATTYPE k) { // Access: protected // Description: actual multiply call (non virtual) //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LQuaternion) FLOATNAME(LQuaternion):: +INLINE_LINMATH FLOATNAME(LQuaternion) FLOATNAME(LQuaternion):: multiply(const FLOATNAME(LQuaternion)& rhs) const { - FLOATTYPE r = (_data[0] * rhs._data[0]) - (_data[1] * rhs._data[1]) - (_data[2] * rhs._data[2]) - (_data[3] * rhs._data[3]); - FLOATTYPE i = (_data[1] * rhs._data[0]) + (_data[0] * rhs._data[1]) - (_data[3] * rhs._data[2]) + (_data[2] * rhs._data[3]); - FLOATTYPE j = (_data[2] * rhs._data[0]) + (_data[3] * rhs._data[1]) + (_data[0] * rhs._data[2]) - (_data[1] * rhs._data[3]); - FLOATTYPE k = (_data[3] * rhs._data[0]) - (_data[2] * rhs._data[1]) + (_data[1] * rhs._data[2]) + (_data[0] * rhs._data[3]); + FLOATTYPE r = (_v.data[0] * rhs._v.data[0]) - (_v.data[1] * rhs._v.data[1]) - (_v.data[2] * rhs._v.data[2]) - (_v.data[3] * rhs._v.data[3]); + FLOATTYPE i = (_v.data[1] * rhs._v.data[0]) + (_v.data[0] * rhs._v.data[1]) - (_v.data[3] * rhs._v.data[2]) + (_v.data[2] * rhs._v.data[3]); + FLOATTYPE j = (_v.data[2] * rhs._v.data[0]) + (_v.data[3] * rhs._v.data[1]) + (_v.data[0] * rhs._v.data[2]) - (_v.data[1] * rhs._v.data[3]); + FLOATTYPE k = (_v.data[3] * rhs._v.data[0]) - (_v.data[2] * rhs._v.data[1]) + (_v.data[1] * rhs._v.data[2]) + (_v.data[0] * rhs._v.data[3]); return FLOATNAME(LQuaternion)(r, i , j, k); } @@ -53,7 +53,7 @@ multiply(const FLOATNAME(LQuaternion)& rhs) const { // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LQuaternion) FLOATNAME(LQuaternion):: +INLINE_LINMATH FLOATNAME(LQuaternion) FLOATNAME(LQuaternion):: operator *(const FLOATNAME(LQuaternion)& c) { return multiply(c); } @@ -63,7 +63,7 @@ operator *(const FLOATNAME(LQuaternion)& c) { // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LQuaternion)& FLOATNAME(LQuaternion):: +INLINE_LINMATH FLOATNAME(LQuaternion)& FLOATNAME(LQuaternion):: operator *=(const FLOATNAME(LQuaternion)& c) { (*this) = operator*(c); return *this; @@ -74,7 +74,7 @@ operator *=(const FLOATNAME(LQuaternion)& c) { // Access: public // Description: Quat * Matrix = matrix //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) FLOATNAME(LQuaternion):: +INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LQuaternion):: operator *(const FLOATNAME(LMatrix3) &m) { FLOATNAME(LMatrix3) result; extract_to_matrix(result); @@ -86,7 +86,7 @@ operator *(const FLOATNAME(LMatrix3) &m) { // Access: public // Description: Quat * Matrix = matrix //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) FLOATNAME(LQuaternion):: +INLINE_LINMATH FLOATNAME(LMatrix4) FLOATNAME(LQuaternion):: operator *(const FLOATNAME(LMatrix4) &m) { FLOATNAME(LMatrix3) m_upper_3 = m.get_upper_3(); FLOATNAME(LMatrix3) this_quat; @@ -106,12 +106,12 @@ operator *(const FLOATNAME(LMatrix4) &m) { // Description: Returns true if two quaternions are memberwise equal // within a specified tolerance. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LQuaternion):: +INLINE_LINMATH bool FLOATNAME(LQuaternion):: almost_equal(const FLOATNAME(LQuaternion)& c, FLOATTYPE threshold) const { - return (IS_THRESHOLD_EQUAL(_data[0], c._data[0], threshold) && - IS_THRESHOLD_EQUAL(_data[1], c._data[1], threshold) && - IS_THRESHOLD_EQUAL(_data[2], c._data[2], threshold) && - IS_THRESHOLD_EQUAL(_data[3], c._data[3], threshold)); + return (IS_THRESHOLD_EQUAL(_v.data[0], c._v.data[0], threshold) && + IS_THRESHOLD_EQUAL(_v.data[1], c._v.data[1], threshold) && + IS_THRESHOLD_EQUAL(_v.data[2], c._v.data[2], threshold) && + IS_THRESHOLD_EQUAL(_v.data[3], c._v.data[3], threshold)); } //////////////////////////////////////////////////////////////////// @@ -120,7 +120,7 @@ almost_equal(const FLOATNAME(LQuaternion)& c, FLOATTYPE threshold) const { // Description: Returns true if two quaternions are memberwise equal // within a default tolerance based on the numeric type. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LQuaternion):: +INLINE_LINMATH bool FLOATNAME(LQuaternion):: almost_equal(const FLOATNAME(LQuaternion)& c) const { return almost_equal(c, NEARLY_ZERO(FLOATTYPE)); } @@ -130,12 +130,12 @@ almost_equal(const FLOATNAME(LQuaternion)& c) const { // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LQuaternion):: +INLINE_LINMATH void FLOATNAME(LQuaternion):: output(ostream& os) const { - os << MAYBE_ZERO(_data[0]) << " + " - << MAYBE_ZERO(_data[1]) << "i + " - << MAYBE_ZERO(_data[2]) << "j + " - << MAYBE_ZERO(_data[3]) << "k"; + os << MAYBE_ZERO(_v.data[0]) << " + " + << MAYBE_ZERO(_v.data[1]) << "i + " + << MAYBE_ZERO(_v.data[2]) << "j + " + << MAYBE_ZERO(_v.data[3]) << "k"; } //////////////////////////////////////////////////////////////////// @@ -143,9 +143,9 @@ output(ostream& os) const { // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LQuaternion):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LQuaternion):: get_r() const { - return _data[0]; + return _v.data[0]; } //////////////////////////////////////////////////////////////////// @@ -153,9 +153,9 @@ get_r() const { // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LQuaternion):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LQuaternion):: get_i() const { - return _data[1]; + return _v.data[1]; } //////////////////////////////////////////////////////////////////// @@ -163,9 +163,9 @@ get_i() const { // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LQuaternion):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LQuaternion):: get_j() const { - return _data[2]; + return _v.data[2]; } //////////////////////////////////////////////////////////////////// @@ -173,9 +173,9 @@ get_j() const { // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LQuaternion):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LQuaternion):: get_k() const { - return _data[3]; + return _v.data[3]; } //////////////////////////////////////////////////////////////////// @@ -183,9 +183,9 @@ get_k() const { // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LQuaternion):: +INLINE_LINMATH void FLOATNAME(LQuaternion):: set_r(FLOATTYPE r) { - _data[0] = r; + _v.data[0] = r; } //////////////////////////////////////////////////////////////////// @@ -193,9 +193,9 @@ set_r(FLOATTYPE r) { // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LQuaternion):: +INLINE_LINMATH void FLOATNAME(LQuaternion):: set_i(FLOATTYPE i) { - _data[1] = i; + _v.data[1] = i; } //////////////////////////////////////////////////////////////////// @@ -203,9 +203,9 @@ set_i(FLOATTYPE i) { // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LQuaternion):: +INLINE_LINMATH void FLOATNAME(LQuaternion):: set_j(FLOATTYPE j) { - _data[2] = j; + _v.data[2] = j; } //////////////////////////////////////////////////////////////////// @@ -213,9 +213,9 @@ set_j(FLOATTYPE j) { // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LQuaternion):: +INLINE_LINMATH void FLOATNAME(LQuaternion):: set_k(FLOATTYPE k) { - _data[3] = k; + _v.data[3] = k; } //////////////////////////////////////////////////////////////////// @@ -223,7 +223,7 @@ set_k(FLOATTYPE k) { // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LQuaternion):: +INLINE_LINMATH bool FLOATNAME(LQuaternion):: normalize() { FLOATTYPE l2 = (*this).dot(*this); if (l2 == (FLOATTYPE)0.0) { @@ -242,7 +242,7 @@ normalize() { // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LQuaternion):: +INLINE_LINMATH void FLOATNAME(LQuaternion):: set_from_matrix(const FLOATNAME(LMatrix4) &m) { set_from_matrix(m.get_upper_3()); } @@ -252,7 +252,7 @@ set_from_matrix(const FLOATNAME(LMatrix4) &m) { // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) operator *(const FLOATNAME(LMatrix3) &m, +INLINE_LINMATH FLOATNAME(LMatrix3) operator *(const FLOATNAME(LMatrix3) &m, const FLOATNAME(LQuaternion) &q) { FLOATNAME(LMatrix3) q_matrix; q.extract_to_matrix(q_matrix); @@ -265,7 +265,7 @@ INLINE FLOATNAME(LMatrix3) operator *(const FLOATNAME(LMatrix3) &m, // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) operator *(const FLOATNAME(LMatrix4) &m, +INLINE_LINMATH FLOATNAME(LMatrix4) operator *(const FLOATNAME(LMatrix4) &m, const FLOATNAME(LQuaternion) &q) { FLOATNAME(LMatrix4) q_matrix; q.extract_to_matrix(q_matrix); @@ -287,7 +287,7 @@ INLINE FLOATNAME(LMatrix4) operator *(const FLOATNAME(LMatrix4) &m, // Access: Public, Static // Description: Returns an identity quaternion. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LQuaternion) &FLOATNAME(LQuaternion):: +INLINE_LINMATH const FLOATNAME(LQuaternion) &FLOATNAME(LQuaternion):: ident_quat() { return _ident_quat; } diff --git a/panda/src/linmath/lquaternion_src.cxx b/panda/src/linmath/lquaternion_src.cxx index bddcef84e6..519a8391df 100644 --- a/panda/src/linmath/lquaternion_src.cxx +++ b/panda/src/linmath/lquaternion_src.cxx @@ -21,14 +21,14 @@ pure_imaginary(const FLOATNAME(LVector3) &v) { //////////////////////////////////////////////////////////////////// void FLOATNAME(LQuaternion):: extract_to_matrix(FLOATNAME(LMatrix3) &m) const { - FLOATTYPE N = (_data[0] * _data[0]) + (_data[1] * _data[1]) + (_data[2] * _data[2]) + (_data[3] * _data[3]); + FLOATTYPE N = (_v.data[0] * _v.data[0]) + (_v.data[1] * _v.data[1]) + (_v.data[2] * _v.data[2]) + (_v.data[3] * _v.data[3]); FLOATTYPE s = (N == 0.) ? 0. : (2. / N); FLOATTYPE xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz; - xs = _data[1] * s; ys = _data[2] * s; zs = _data[3] * s; - wx = _data[0] * xs; wy = _data[0] * ys; wz = _data[0] * zs; - xx = _data[1] * xs; xy = _data[1] * ys; xz = _data[1] * zs; - yy = _data[2] * ys; yz = _data[2] * zs; zz = _data[3] * zs; + xs = _v.data[1] * s; ys = _v.data[2] * s; zs = _v.data[3] * s; + wx = _v.data[0] * xs; wy = _v.data[0] * ys; wz = _v.data[0] * zs; + xx = _v.data[1] * xs; xy = _v.data[1] * ys; xz = _v.data[1] * zs; + yy = _v.data[2] * ys; yz = _v.data[2] * zs; zz = _v.data[3] * zs; m = FLOATNAME(LMatrix3)((1. - (yy + zz)), (xy - wz), (xz + wy), (xy + wz), (1. - (xx + zz)), (yz - wx), @@ -42,14 +42,14 @@ extract_to_matrix(FLOATNAME(LMatrix3) &m) const { //////////////////////////////////////////////////////////////////// void FLOATNAME(LQuaternion):: extract_to_matrix(FLOATNAME(LMatrix4) &m) const { - FLOATTYPE N = (_data[0] * _data[0]) + (_data[1] * _data[1]) + (_data[2] * _data[2]) + (_data[3] * _data[3]); + FLOATTYPE N = (_v.data[0] * _v.data[0]) + (_v.data[1] * _v.data[1]) + (_v.data[2] * _v.data[2]) + (_v.data[3] * _v.data[3]); FLOATTYPE s = (N == 0.) ? 0. : (2. / N); FLOATTYPE xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz; - xs = _data[1] * s; ys = _data[2] * s; zs = _data[3] * s; - wx = _data[0] * xs; wy = _data[0] * ys; wz = _data[0] * zs; - xx = _data[1] * xs; xy = _data[1] * ys; xz = _data[1] * zs; - yy = _data[2] * ys; yz = _data[2] * zs; zz = _data[3] * zs; + xs = _v.data[1] * s; ys = _v.data[2] * s; zs = _v.data[3] * s; + wx = _v.data[0] * xs; wy = _v.data[0] * ys; wz = _v.data[0] * zs; + xx = _v.data[1] * xs; xy = _v.data[1] * ys; xz = _v.data[1] * zs; + yy = _v.data[2] * ys; yz = _v.data[2] * zs; zz = _v.data[3] * zs; m = FLOATNAME(LMatrix4)((1. - (yy + zz)), (xy - wz), (xz + wy), 0., (xy + wz), (1. - (xx + zz)), (yz - wx), 0., @@ -96,15 +96,15 @@ set_hpr(const FLOATNAME(LVecBase3) &hpr) { FLOATNAME(LVecBase3) FLOATNAME(LQuaternion):: get_hpr() const { FLOATTYPE heading, pitch, roll; - FLOATTYPE N = (_data[0] * _data[0]) + (_data[1] * _data[1]) + (_data[2] * _data[2]) + (_data[3] * _data[3]); + FLOATTYPE N = (_v.data[0] * _v.data[0]) + (_v.data[1] * _v.data[1]) + (_v.data[2] * _v.data[2]) + (_v.data[3] * _v.data[3]); FLOATTYPE s = (N == 0.) ? 0. : (2. / N); FLOATTYPE xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz, c1, c2, c3, c4; FLOATTYPE cr, sr, cp, sp, ch, sh; - xs = _data[1] * s; ys = _data[2] * s; zs = _data[3] * s; - wx = _data[0] * xs; wy = _data[0] * ys; wz = _data[0] * zs; - xx = _data[1] * xs; xy = _data[1] * ys; xz = _data[1] * zs; - yy = _data[2] * ys; yz = _data[2] * zs; zz = _data[3] * zs; + xs = _v.data[1] * s; ys = _v.data[2] * s; zs = _v.data[3] * s; + wx = _v.data[0] * xs; wy = _v.data[0] * ys; wz = _v.data[0] * zs; + xx = _v.data[1] * xs; xy = _v.data[1] * ys; xz = _v.data[1] * zs; + yy = _v.data[2] * ys; yz = _v.data[2] * zs; zz = _v.data[3] * zs; c1 = xz - wy; c2 = 1. - (xx + yy); c3 = 1. - (yy + zz); @@ -160,10 +160,10 @@ set_from_matrix(const FLOATNAME(LMatrix3) &m) { if (T > 0.) { // the easy case FLOATTYPE S = 0.5 / csqrt(T); - _data[0] = 0.25 / S; - _data[1] = (m21 - m12) * S; - _data[2] = (m02 - m20) * S; - _data[3] = (m10 - m01) * S; + _v.data[0] = 0.25 / S; + _v.data[1] = (m21 - m12) * S; + _v.data[2] = (m02 - m20) * S; + _v.data[3] = (m10 - m01) * S; } else { // figure out which column to take as root int c = 0; @@ -182,24 +182,24 @@ set_from_matrix(const FLOATNAME(LMatrix3) &m) { switch (c) { case 0: S = csqrt(1. + m00 - m11 - m22) * 2.; - _data[0] = (m12 + m21) / S; - _data[1] = 0.5 / S; - _data[2] = (m01 + m10) / S; - _data[3] = (m02 + m20) / S; + _v.data[0] = (m12 + m21) / S; + _v.data[1] = 0.5 / S; + _v.data[2] = (m01 + m10) / S; + _v.data[3] = (m02 + m20) / S; break; case 1: S = csqrt(1. + m11 - m00 - m22) * 2.; - _data[0] = (m02 + m20) / S; - _data[1] = (m01 + m10) / S; - _data[2] = 0.5 / S; - _data[3] = (m12 + m21) / S; + _v.data[0] = (m02 + m20) / S; + _v.data[1] = (m01 + m10) / S; + _v.data[2] = 0.5 / S; + _v.data[3] = (m12 + m21) / S; break; case 2: S = csqrt(1. + m22 - m00 - m11) * 2.; - _data[0] = (m01 + m10) / S; - _data[1] = (m02 + m20) / S; - _data[2] = (m12 + m21) / S; - _data[3] = 0.5 / S; + _v.data[0] = (m01 + m10) / S; + _v.data[1] = (m02 + m20) / S; + _v.data[2] = (m12 + m21) / S; + _v.data[3] = 0.5 / S; break; } } diff --git a/panda/src/linmath/lquaternion_src.h b/panda/src/linmath/lquaternion_src.h index bd9785f524..53df4dd3ff 100644 --- a/panda/src/linmath/lquaternion_src.h +++ b/panda/src/linmath/lquaternion_src.h @@ -9,48 +9,48 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA FLOATNAME(LQuaternion) : public FLOATNAME(LVecBase4) { protected: - INLINE FLOATNAME(LQuaternion) + INLINE_LINMATH FLOATNAME(LQuaternion) multiply(const FLOATNAME(LQuaternion)&) const; PUBLISHED: - INLINE FLOATNAME(LQuaternion)(); - INLINE FLOATNAME(LQuaternion)(const FLOATNAME(LQuaternion) &); - INLINE FLOATNAME(LQuaternion)(FLOATTYPE, FLOATTYPE, FLOATTYPE, FLOATTYPE); + INLINE_LINMATH FLOATNAME(LQuaternion)(); + INLINE_LINMATH FLOATNAME(LQuaternion)(const FLOATNAME(LQuaternion) &); + INLINE_LINMATH FLOATNAME(LQuaternion)(FLOATTYPE, FLOATTYPE, FLOATTYPE, FLOATTYPE); static FLOATNAME(LQuaternion) pure_imaginary(const FLOATNAME(LVector3) &); - INLINE FLOATNAME(LQuaternion) operator *(const FLOATNAME(LQuaternion) &); - INLINE FLOATNAME(LQuaternion)& operator *=(const FLOATNAME(LQuaternion) &); + INLINE_LINMATH FLOATNAME(LQuaternion) operator *(const FLOATNAME(LQuaternion) &); + INLINE_LINMATH FLOATNAME(LQuaternion)& operator *=(const FLOATNAME(LQuaternion) &); - INLINE FLOATNAME(LMatrix3) operator *(const FLOATNAME(LMatrix3) &); - INLINE FLOATNAME(LMatrix4) operator *(const FLOATNAME(LMatrix4) &); + INLINE_LINMATH FLOATNAME(LMatrix3) operator *(const FLOATNAME(LMatrix3) &); + INLINE_LINMATH FLOATNAME(LMatrix4) operator *(const FLOATNAME(LMatrix4) &); - INLINE bool almost_equal(const FLOATNAME(LQuaternion) &, FLOATTYPE) const; - INLINE bool almost_equal(const FLOATNAME(LQuaternion) &) const; + INLINE_LINMATH bool almost_equal(const FLOATNAME(LQuaternion) &, FLOATTYPE) const; + INLINE_LINMATH bool almost_equal(const FLOATNAME(LQuaternion) &) const; - INLINE void output(ostream&) const; + INLINE_LINMATH void output(ostream&) const; void extract_to_matrix(FLOATNAME(LMatrix3) &m) const; void extract_to_matrix(FLOATNAME(LMatrix4) &m) const; void set_from_matrix(const FLOATNAME(LMatrix3) &m); - INLINE void set_from_matrix(const FLOATNAME(LMatrix4) &m); + INLINE_LINMATH void set_from_matrix(const FLOATNAME(LMatrix4) &m); void set_hpr(const FLOATNAME(LVecBase3) &hpr); FLOATNAME(LVecBase3) get_hpr() const; - INLINE FLOATTYPE get_r() const; - INLINE FLOATTYPE get_i() const; - INLINE FLOATTYPE get_j() const; - INLINE FLOATTYPE get_k() const; + INLINE_LINMATH FLOATTYPE get_r() const; + INLINE_LINMATH FLOATTYPE get_i() const; + INLINE_LINMATH FLOATTYPE get_j() const; + INLINE_LINMATH FLOATTYPE get_k() const; - INLINE void set_r(FLOATTYPE r); - INLINE void set_i(FLOATTYPE i); - INLINE void set_j(FLOATTYPE j); - INLINE void set_k(FLOATTYPE k); + INLINE_LINMATH void set_r(FLOATTYPE r); + INLINE_LINMATH void set_i(FLOATTYPE i); + INLINE_LINMATH void set_j(FLOATTYPE j); + INLINE_LINMATH void set_k(FLOATTYPE k); - INLINE bool normalize(); + INLINE_LINMATH bool normalize(); - INLINE static const FLOATNAME(LQuaternion) &ident_quat(); + INLINE_LINMATH static const FLOATNAME(LQuaternion) &ident_quat(); private: static const FLOATNAME(LQuaternion) _ident_quat; @@ -65,15 +65,15 @@ private: }; -INLINE ostream& operator<<(ostream& os, const FLOATNAME(LQuaternion)& q) { +INLINE_LINMATH ostream& operator<<(ostream& os, const FLOATNAME(LQuaternion)& q) { q.output(os); return os; } BEGIN_PUBLISH -INLINE FLOATNAME(LMatrix3) +INLINE_LINMATH FLOATNAME(LMatrix3) operator * (const FLOATNAME(LMatrix3) &m, const FLOATNAME(LQuaternion) &q); -INLINE FLOATNAME(LMatrix4) +INLINE_LINMATH FLOATNAME(LMatrix4) operator * (const FLOATNAME(LMatrix4) &m, const FLOATNAME(LQuaternion) &q); END_PUBLISH diff --git a/panda/src/linmath/lrotation_src.I b/panda/src/linmath/lrotation_src.I index 138924bea0..246e59da8a 100644 --- a/panda/src/linmath/lrotation_src.I +++ b/panda/src/linmath/lrotation_src.I @@ -8,7 +8,7 @@ // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LRotation):: +INLINE_LINMATH FLOATNAME(LRotation):: FLOATNAME(LRotation)() { } @@ -17,7 +17,7 @@ FLOATNAME(LRotation)() { // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LRotation):: +INLINE_LINMATH FLOATNAME(LRotation):: FLOATNAME(LRotation)(const FLOATNAME(LQuaternion)& c) : FLOATNAME(LQuaternion)(c) { } @@ -27,7 +27,7 @@ FLOATNAME(LRotation)(const FLOATNAME(LQuaternion)& c) : // Access: public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LRotation):: +INLINE_LINMATH FLOATNAME(LRotation):: FLOATNAME(LRotation)(FLOATTYPE r, FLOATTYPE i, FLOATTYPE j, FLOATTYPE k) : FLOATNAME(LQuaternion)(r, i, j, k) { } @@ -37,7 +37,7 @@ FLOATNAME(LRotation)(FLOATTYPE r, FLOATTYPE i, FLOATTYPE j, FLOATTYPE k) : // Access: public // Description: lmatrix3 //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LRotation):: +INLINE_LINMATH FLOATNAME(LRotation):: FLOATNAME(LRotation)(const FLOATNAME(LMatrix3) &m) { set_from_matrix(m); } @@ -47,7 +47,7 @@ FLOATNAME(LRotation)(const FLOATNAME(LMatrix3) &m) { // Access: public // Description: lmatrix4 //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LRotation):: +INLINE_LINMATH FLOATNAME(LRotation):: FLOATNAME(LRotation)(const FLOATNAME(LMatrix4) &m) { set_from_matrix(m); } @@ -57,7 +57,7 @@ FLOATNAME(LRotation)(const FLOATNAME(LMatrix4) &m) { // Access: public // Description: axis + angle (in degrees) //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LRotation):: +INLINE_LINMATH FLOATNAME(LRotation):: FLOATNAME(LRotation)(const FLOATNAME(LVector3) &axis, FLOATTYPE angle) { FLOATTYPE radians = angle * ((FLOATTYPE) MathNumbers::pi / (FLOATTYPE)180.0); FLOATTYPE theta_over_2 = radians / (FLOATTYPE)2.0; @@ -74,7 +74,7 @@ FLOATNAME(LRotation)(const FLOATNAME(LVector3) &axis, FLOATTYPE angle) { // Access: public // Description: Sets the rotation from the given Euler angles. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LRotation):: +INLINE_LINMATH FLOATNAME(LRotation):: FLOATNAME(LRotation)(FLOATTYPE h, FLOATTYPE p, FLOATTYPE r) { set_hpr(FLOATNAME(LVecBase3)(h, p, r)); } @@ -84,7 +84,7 @@ FLOATNAME(LRotation)(FLOATTYPE h, FLOATTYPE p, FLOATTYPE r) { // Access: public // Description: Rotation * Rotation = Rotation //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LRotation) FLOATNAME(LRotation):: +INLINE_LINMATH FLOATNAME(LRotation) FLOATNAME(LRotation):: operator*(const FLOATNAME(LRotation)& other) const { return multiply(other); } @@ -97,7 +97,7 @@ operator*(const FLOATNAME(LRotation)& other) const { // to apply an orientation to a rotation. It simply // returns the rhs. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LQuaternion) FLOATNAME(LRotation):: +INLINE_LINMATH FLOATNAME(LQuaternion) FLOATNAME(LRotation):: operator*(const FLOATNAME(LQuaternion)& other) const { return other; } diff --git a/panda/src/linmath/lrotation_src.h b/panda/src/linmath/lrotation_src.h index e7243fda0f..96eef5e8fb 100644 --- a/panda/src/linmath/lrotation_src.h +++ b/panda/src/linmath/lrotation_src.h @@ -9,18 +9,18 @@ //////////////////////////////////////////////////////////////////////// class EXPCL_PANDA FLOATNAME(LRotation) : public FLOATNAME(LQuaternion) { PUBLISHED: - INLINE FLOATNAME(LRotation)(); - INLINE FLOATNAME(LRotation)(const FLOATNAME(LQuaternion)&); - INLINE FLOATNAME(LRotation)(FLOATTYPE, FLOATTYPE, FLOATTYPE, FLOATTYPE); - INLINE FLOATNAME(LRotation)(const FLOATNAME(LVector3) &, FLOATTYPE); - INLINE FLOATNAME(LRotation)(const FLOATNAME(LMatrix3) &); - INLINE FLOATNAME(LRotation)(const FLOATNAME(LMatrix4) &); - INLINE FLOATNAME(LRotation)(FLOATTYPE, FLOATTYPE, FLOATTYPE); + INLINE_LINMATH FLOATNAME(LRotation)(); + INLINE_LINMATH FLOATNAME(LRotation)(const FLOATNAME(LQuaternion)&); + INLINE_LINMATH FLOATNAME(LRotation)(FLOATTYPE, FLOATTYPE, FLOATTYPE, FLOATTYPE); + INLINE_LINMATH FLOATNAME(LRotation)(const FLOATNAME(LVector3) &, FLOATTYPE); + INLINE_LINMATH FLOATNAME(LRotation)(const FLOATNAME(LMatrix3) &); + INLINE_LINMATH FLOATNAME(LRotation)(const FLOATNAME(LMatrix4) &); + INLINE_LINMATH FLOATNAME(LRotation)(FLOATTYPE, FLOATTYPE, FLOATTYPE); - INLINE FLOATNAME(LRotation) + INLINE_LINMATH FLOATNAME(LRotation) operator*(const FLOATNAME(LRotation)& other) const; - INLINE FLOATNAME(LQuaternion) + INLINE_LINMATH FLOATNAME(LQuaternion) operator*(const FLOATNAME(LQuaternion)& other) const; public: diff --git a/panda/src/linmath/lvec2_ops_src.I b/panda/src/linmath/lvec2_ops_src.I index a487d0d55d..032c20fff7 100644 --- a/panda/src/linmath/lvec2_ops_src.I +++ b/panda/src/linmath/lvec2_ops_src.I @@ -7,7 +7,7 @@ // Function: scalar * LVecBase2 // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2) +INLINE_LINMATH FLOATNAME(LVecBase2) operator * (FLOATTYPE scalar, const FLOATNAME(LVecBase2) &a) { return a * scalar; } @@ -16,7 +16,7 @@ operator * (FLOATTYPE scalar, const FLOATNAME(LVecBase2) &a) { // Function: scalar * LPoint2 // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint2) +INLINE_LINMATH FLOATNAME(LPoint2) operator * (FLOATTYPE scalar, const FLOATNAME(LPoint2) &a) { return a * scalar; } @@ -25,7 +25,7 @@ operator * (FLOATTYPE scalar, const FLOATNAME(LPoint2) &a) { // Function: scalar * LVector2 // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector2) +INLINE_LINMATH FLOATNAME(LVector2) operator * (FLOATTYPE scalar, const FLOATNAME(LVector2) &a) { return a * scalar; } @@ -34,7 +34,7 @@ operator * (FLOATTYPE scalar, const FLOATNAME(LVector2) &a) { // Function: dot product of LVecBase2 // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE +INLINE_LINMATH FLOATTYPE dot(const FLOATNAME(LVecBase2) &a, const FLOATNAME(LVecBase2) &b) { return a.dot(b); } @@ -43,7 +43,7 @@ dot(const FLOATNAME(LVecBase2) &a, const FLOATNAME(LVecBase2) &b) { // Function: length of a vector // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE +INLINE_LINMATH FLOATTYPE length(const FLOATNAME(LVector2) &a) { return a.length(); } @@ -52,7 +52,7 @@ length(const FLOATNAME(LVector2) &a) { // Function: normalize // Description: Returns a normalized vector from the given vector. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector2) +INLINE_LINMATH FLOATNAME(LVector2) normalize(const FLOATNAME(LVector2) &v) { FLOATNAME(LVector2) v1 = v; v1.normalize(); diff --git a/panda/src/linmath/lvec2_ops_src.h b/panda/src/linmath/lvec2_ops_src.h index 1ab59d8a77..fbfeb9c5ce 100644 --- a/panda/src/linmath/lvec2_ops_src.h +++ b/panda/src/linmath/lvec2_ops_src.h @@ -10,27 +10,27 @@ // scalar * vec (vec * scalar is defined in class) -INLINE FLOATNAME(LVecBase2) +INLINE_LINMATH FLOATNAME(LVecBase2) operator * (FLOATTYPE scalar, const FLOATNAME(LVecBase2) &a); -INLINE FLOATNAME(LPoint2) +INLINE_LINMATH FLOATNAME(LPoint2) operator * (FLOATTYPE scalar, const FLOATNAME(LPoint2) &a); -INLINE FLOATNAME(LVector2) +INLINE_LINMATH FLOATNAME(LVector2) operator * (FLOATTYPE scalar, const FLOATNAME(LVector2) &a); // dot product -INLINE FLOATTYPE +INLINE_LINMATH FLOATTYPE dot(const FLOATNAME(LVecBase2) &a, const FLOATNAME(LVecBase2) &b); // Length of a vector. -INLINE FLOATTYPE +INLINE_LINMATH FLOATTYPE length(const FLOATNAME(LVector2) &a); // A normalized vector. -INLINE FLOATNAME(LVector2) +INLINE_LINMATH FLOATNAME(LVector2) normalize(const FLOATNAME(LVector2) &v); diff --git a/panda/src/linmath/lvec3_ops_src.I b/panda/src/linmath/lvec3_ops_src.I index 7afc6ca9df..80574a8c27 100644 --- a/panda/src/linmath/lvec3_ops_src.I +++ b/panda/src/linmath/lvec3_ops_src.I @@ -8,7 +8,7 @@ // Function: scalar * LVecBase3 // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) +INLINE_LINMATH FLOATNAME(LVecBase3) operator * (FLOATTYPE scalar, const FLOATNAME(LVecBase3) &a) { return a * scalar; } @@ -17,7 +17,7 @@ operator * (FLOATTYPE scalar, const FLOATNAME(LVecBase3) &a) { // Function: scalar * LPoint3 // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint3) +INLINE_LINMATH FLOATNAME(LPoint3) operator * (FLOATTYPE scalar, const FLOATNAME(LPoint3) &a) { return a * scalar; } @@ -26,7 +26,7 @@ operator * (FLOATTYPE scalar, const FLOATNAME(LPoint3) &a) { // Function: scalar * LVector3 // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) +INLINE_LINMATH FLOATNAME(LVector3) operator * (FLOATTYPE scalar, const FLOATNAME(LVector3) &a) { return a * scalar; } @@ -36,7 +36,7 @@ operator * (FLOATTYPE scalar, const FLOATNAME(LVector3) &a) { // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE +INLINE_LINMATH FLOATTYPE dot(const FLOATNAME(LVecBase3) &a, const FLOATNAME(LVecBase3) &b) { return a.dot(b); } @@ -46,7 +46,7 @@ dot(const FLOATNAME(LVecBase3) &a, const FLOATNAME(LVecBase3) &b) { // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) +INLINE_LINMATH FLOATNAME(LVecBase3) cross(const FLOATNAME(LVecBase3) &a, const FLOATNAME(LVecBase3) &b) { return a.cross(b); } @@ -56,7 +56,7 @@ cross(const FLOATNAME(LVecBase3) &a, const FLOATNAME(LVecBase3) &b) { // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) +INLINE_LINMATH FLOATNAME(LVector3) cross(const FLOATNAME(LVector3) &a, const FLOATNAME(LVector3) &b) { return FLOATNAME(LVector3)(a.cross(b)); } @@ -67,7 +67,7 @@ cross(const FLOATNAME(LVector3) &a, const FLOATNAME(LVector3) &b) { // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE +INLINE_LINMATH FLOATTYPE length(const FLOATNAME(LVector3) &a) { return a.length(); } @@ -78,7 +78,7 @@ length(const FLOATNAME(LVector3) &a) { // Description: Returns a normalized vector from the given vector. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) +INLINE_LINMATH FLOATNAME(LVector3) normalize(const FLOATNAME(LVector3) &v) { FLOATNAME(LVector3) v1 = v; v1.normalize(); diff --git a/panda/src/linmath/lvec3_ops_src.h b/panda/src/linmath/lvec3_ops_src.h index 4cbe427c02..4938e7e621 100644 --- a/panda/src/linmath/lvec3_ops_src.h +++ b/panda/src/linmath/lvec3_ops_src.h @@ -10,35 +10,35 @@ // scalar * vec (vec * scalar is defined in class) -INLINE FLOATNAME(LVecBase3) +INLINE_LINMATH FLOATNAME(LVecBase3) operator * (FLOATTYPE scalar, const FLOATNAME(LVecBase3) &a); -INLINE FLOATNAME(LPoint3) +INLINE_LINMATH FLOATNAME(LPoint3) operator * (FLOATTYPE scalar, const FLOATNAME(LPoint3) &a); -INLINE FLOATNAME(LVector3) +INLINE_LINMATH FLOATNAME(LVector3) operator * (FLOATTYPE scalar, const FLOATNAME(LVector3) &a); // dot product -INLINE FLOATTYPE +INLINE_LINMATH FLOATTYPE dot(const FLOATNAME(LVecBase3) &a, const FLOATNAME(LVecBase3) &b); // cross product -INLINE FLOATNAME(LVecBase3) +INLINE_LINMATH FLOATNAME(LVecBase3) cross(const FLOATNAME(LVecBase3) &a, const FLOATNAME(LVecBase3) &b); -INLINE FLOATNAME(LVector3) +INLINE_LINMATH FLOATNAME(LVector3) cross(const FLOATNAME(LVector3) &a, const FLOATNAME(LVector3) &b); // Length of a vector. -INLINE FLOATTYPE +INLINE_LINMATH FLOATTYPE length(const FLOATNAME(LVector3) &a); // A normalized vector. -INLINE FLOATNAME(LVector3) +INLINE_LINMATH FLOATNAME(LVector3) normalize(const FLOATNAME(LVector3) &v); #include "lvec3_ops_src.I" diff --git a/panda/src/linmath/lvec4_ops_src.I b/panda/src/linmath/lvec4_ops_src.I index 91033ecba9..9bd2bdfe1e 100644 --- a/panda/src/linmath/lvec4_ops_src.I +++ b/panda/src/linmath/lvec4_ops_src.I @@ -7,7 +7,7 @@ // Function: scalar * LVecBase4 // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4) +INLINE_LINMATH FLOATNAME(LVecBase4) operator * (FLOATTYPE scalar, const FLOATNAME(LVecBase4) &a) { return a * scalar; } @@ -16,7 +16,7 @@ operator * (FLOATTYPE scalar, const FLOATNAME(LVecBase4) &a) { // Function: scalar * LPoint4 // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LPoint4) +INLINE_LINMATH FLOATNAME(LPoint4) operator * (FLOATTYPE scalar, const FLOATNAME(LPoint4) &a) { return a * scalar; } @@ -25,7 +25,7 @@ operator * (FLOATTYPE scalar, const FLOATNAME(LPoint4) &a) { // Function: scalar * LVector4 // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector4) +INLINE_LINMATH FLOATNAME(LVector4) operator * (FLOATTYPE scalar, const FLOATNAME(LVector4) &a) { return a * scalar; } @@ -35,7 +35,7 @@ operator * (FLOATTYPE scalar, const FLOATNAME(LVector4) &a) { // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE +INLINE_LINMATH FLOATTYPE dot(const FLOATNAME(LVecBase4) &a, const FLOATNAME(LVecBase4) &b) { return a.dot(b); } @@ -45,7 +45,7 @@ dot(const FLOATNAME(LVecBase4) &a, const FLOATNAME(LVecBase4) &b) { // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE +INLINE_LINMATH FLOATTYPE length(const FLOATNAME(LVector4) &a) { return a.length(); } @@ -56,7 +56,7 @@ length(const FLOATNAME(LVector4) &a) { // Description: Returns a normalized vector from the given vector. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector4) +INLINE_LINMATH FLOATNAME(LVector4) normalize(const FLOATNAME(LVector4) &v) { FLOATNAME(LVector4) v1 = v; v1.normalize(); diff --git a/panda/src/linmath/lvec4_ops_src.h b/panda/src/linmath/lvec4_ops_src.h index e4a1fe918d..21b124baee 100644 --- a/panda/src/linmath/lvec4_ops_src.h +++ b/panda/src/linmath/lvec4_ops_src.h @@ -10,28 +10,28 @@ // scalar * vec (vec * scalar is defined in class) -INLINE FLOATNAME(LVecBase4) +INLINE_LINMATH FLOATNAME(LVecBase4) operator * (FLOATTYPE scalar, const FLOATNAME(LVecBase4) &a); -INLINE FLOATNAME(LPoint4) +INLINE_LINMATH FLOATNAME(LPoint4) operator * (FLOATTYPE scalar, const FLOATNAME(LPoint4) &a); -INLINE FLOATNAME(LVector4) +INLINE_LINMATH FLOATNAME(LVector4) operator * (FLOATTYPE scalar, const FLOATNAME(LVector4) &a); // dot product -INLINE FLOATTYPE +INLINE_LINMATH FLOATTYPE dot(const FLOATNAME(LVecBase4) &a, const FLOATNAME(LVecBase4) &b); // Length of a vector. -INLINE FLOATTYPE +INLINE_LINMATH FLOATTYPE length(const FLOATNAME(LVector4) &a); // A normalized vector. -INLINE FLOATNAME(LVector4) +INLINE_LINMATH FLOATNAME(LVector4) normalize(const FLOATNAME(LVector4) &v); diff --git a/panda/src/linmath/lvecBase2_src.I b/panda/src/linmath/lvecBase2_src.I index 7c4c6e6ff0..a29dfd2111 100644 --- a/panda/src/linmath/lvecBase2_src.I +++ b/panda/src/linmath/lvecBase2_src.I @@ -9,7 +9,7 @@ // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATNAME(LVecBase2):: FLOATNAME(LVecBase2)() { } @@ -18,9 +18,11 @@ FLOATNAME(LVecBase2)() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATNAME(LVecBase2):: FLOATNAME(LVecBase2)(const FLOATNAME(LVecBase2) ©) { - (*this) = copy; + _v.v._0 = copy._v.v._0; + _v.v._1 = copy._v.v._1; +// (*this) = copy; } //////////////////////////////////////////////////////////////////// @@ -28,9 +30,11 @@ FLOATNAME(LVecBase2)(const FLOATNAME(LVecBase2) ©) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2) &FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATNAME(LVecBase2) &FLOATNAME(LVecBase2):: operator = (const FLOATNAME(LVecBase2) ©) { - set(copy[0], copy[1]); + _v.v._0 = copy._v.v._0; + _v.v._1 = copy._v.v._1; +// set(copy[0], copy[1]); return *this; } @@ -39,7 +43,7 @@ operator = (const FLOATNAME(LVecBase2) ©) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2) &FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATNAME(LVecBase2) &FLOATNAME(LVecBase2):: operator = (FLOATTYPE fill_value) { fill(fill_value); return *this; @@ -50,7 +54,7 @@ operator = (FLOATTYPE fill_value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATNAME(LVecBase2):: FLOATNAME(LVecBase2)(FLOATTYPE fill_value) { fill(fill_value); } @@ -60,9 +64,11 @@ FLOATNAME(LVecBase2)(FLOATTYPE fill_value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATNAME(LVecBase2):: FLOATNAME(LVecBase2)(FLOATTYPE x, FLOATTYPE y) { - set(x, y); + _v.v._0 = x; + _v.v._1 = y; +// set(x, y); } //////////////////////////////////////////////////////////////////// @@ -70,7 +76,7 @@ FLOATNAME(LVecBase2)(FLOATTYPE x, FLOATTYPE y) { // Access: Public // Description: Returns a zero-length vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVecBase2) &FLOATNAME(LVecBase2):: +INLINE_LINMATH const FLOATNAME(LVecBase2) &FLOATNAME(LVecBase2):: zero() { return _zero; } @@ -80,7 +86,7 @@ zero() { // Access: Public // Description: Returns a unit X vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVecBase2) &FLOATNAME(LVecBase2):: +INLINE_LINMATH const FLOATNAME(LVecBase2) &FLOATNAME(LVecBase2):: unit_x() { return _unit_x; } @@ -90,7 +96,7 @@ unit_x() { // Access: Public // Description: Returns a unit Y vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVecBase2) &FLOATNAME(LVecBase2):: +INLINE_LINMATH const FLOATNAME(LVecBase2) &FLOATNAME(LVecBase2):: unit_y() { return _unit_y; } @@ -100,7 +106,7 @@ unit_y() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATNAME(LVecBase2):: ~FLOATNAME(LVecBase2)() { } @@ -109,10 +115,10 @@ INLINE FLOATNAME(LVecBase2):: // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase2):: operator [](int i) const { // nassertr(i >= 0 && i < 2, 0); - return _data[i]; + return _v.data[i]; } //////////////////////////////////////////////////////////////////// @@ -120,10 +126,10 @@ operator [](int i) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE &FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATTYPE &FLOATNAME(LVecBase2):: operator [](int i) { - // nassertr(i >= 0 && i < 2, _data[0]); - return _data[i]; + // nassertr(i >= 0 && i < 2, _v.v._0); + return _v.data[i]; } //////////////////////////////////////////////////////////////////// @@ -132,9 +138,9 @@ operator [](int i) { // Description: Returns true if any component of the vector is // not-a-number, false otherwise. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVecBase2):: +INLINE_LINMATH bool FLOATNAME(LVecBase2):: is_nan() const { - return cnan(_data[0]) || cnan(_data[1]); + return cnan(_v.v._0) || cnan(_v.v._1); } //////////////////////////////////////////////////////////////////// @@ -142,10 +148,10 @@ is_nan() const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase2):: get_cell(int i) const { // nassertr(i >= 0 && i < 2, 0); - return _data[i]; + return _v.data[i]; } //////////////////////////////////////////////////////////////////// @@ -153,9 +159,9 @@ get_cell(int i) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase2):: get_x() const { - return _data[0]; + return _v.v._0; } //////////////////////////////////////////////////////////////////// @@ -163,9 +169,9 @@ get_x() const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase2):: get_y() const { - return _data[1]; + return _v.v._1; } //////////////////////////////////////////////////////////////////// @@ -173,10 +179,10 @@ get_y() const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase2):: +INLINE_LINMATH void FLOATNAME(LVecBase2):: set_cell(int i, FLOATTYPE value) { // nassertv(i >= 0 && i < 2); - _data[i] = value; + _v.data[i] = value; } //////////////////////////////////////////////////////////////////// @@ -184,9 +190,9 @@ set_cell(int i, FLOATTYPE value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase2):: +INLINE_LINMATH void FLOATNAME(LVecBase2):: set_x(FLOATTYPE value) { - _data[0] = value; + _v.v._0 = value; } //////////////////////////////////////////////////////////////////// @@ -194,9 +200,9 @@ set_x(FLOATTYPE value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase2):: +INLINE_LINMATH void FLOATNAME(LVecBase2):: set_y(FLOATTYPE value) { - _data[1] = value; + _v.v._1 = value; } //////////////////////////////////////////////////////////////////// @@ -206,9 +212,9 @@ set_y(FLOATTYPE value) { // elements in the vector. The next element // occupies the next position consecutively in memory. //////////////////////////////////////////////////////////////////// -INLINE const FLOATTYPE *FLOATNAME(LVecBase2):: +INLINE_LINMATH const FLOATTYPE *FLOATNAME(LVecBase2):: get_data() const { - return _data; + return _v.data; } //////////////////////////////////////////////////////////////////// @@ -216,7 +222,7 @@ get_data() const { // Access: Public // Description: Returns the number of elements in the vector, two. //////////////////////////////////////////////////////////////////// -INLINE int FLOATNAME(LVecBase2):: +INLINE_LINMATH int FLOATNAME(LVecBase2):: get_num_components() const { return 2; } @@ -227,9 +233,9 @@ get_num_components() const { // Description: Returns an iterator that may be used to traverse the // elements of the matrix, STL-style. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2)::iterator FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATNAME(LVecBase2)::iterator FLOATNAME(LVecBase2):: begin() { - return _data; + return _v.data; } //////////////////////////////////////////////////////////////////// @@ -238,7 +244,7 @@ begin() { // Description: Returns an iterator that may be used to traverse the // elements of the matrix, STL-style. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2)::iterator FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATNAME(LVecBase2)::iterator FLOATNAME(LVecBase2):: end() { return begin() + get_num_components(); } @@ -249,9 +255,9 @@ end() { // Description: Returns an iterator that may be used to traverse the // elements of the matrix, STL-style. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2)::const_iterator FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATNAME(LVecBase2)::const_iterator FLOATNAME(LVecBase2):: begin() const { - return _data; + return _v.data; } //////////////////////////////////////////////////////////////////// @@ -260,7 +266,7 @@ begin() const { // Description: Returns an iterator that may be used to traverse the // elements of the matrix, STL-style. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2)::const_iterator FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATNAME(LVecBase2)::const_iterator FLOATNAME(LVecBase2):: end() const { return begin() + get_num_components(); } @@ -272,10 +278,10 @@ end() const { // fill_value. This is particularly useful for // initializing to zero. //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase2):: +INLINE_LINMATH void FLOATNAME(LVecBase2):: fill(FLOATTYPE fill_value) { - _data[0] = fill_value; - _data[1] = fill_value; + _v.v._0 = fill_value; + _v.v._1 = fill_value; } //////////////////////////////////////////////////////////////////// @@ -283,10 +289,10 @@ fill(FLOATTYPE fill_value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase2):: +INLINE_LINMATH void FLOATNAME(LVecBase2):: set(FLOATTYPE x, FLOATTYPE y) { - _data[0] = x; - _data[1] = y; + _v.v._0 = x; + _v.v._1 = y; } //////////////////////////////////////////////////////////////////// @@ -294,9 +300,9 @@ set(FLOATTYPE x, FLOATTYPE y) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase2):: dot(const FLOATNAME(LVecBase2) &other) const { - return _data[0] * other[0] + _data[1] * other[1]; + return _v.v._0 * other._v.v._0 + _v.v._1 * other._v.v._1; } //////////////////////////////////////////////////////////////////// @@ -308,7 +314,7 @@ dot(const FLOATNAME(LVecBase2) &other) const { // especially in an STL container. Also see // compare_to(). //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVecBase2):: +INLINE_LINMATH bool FLOATNAME(LVecBase2):: operator < (const FLOATNAME(LVecBase2) &other) const { return (compare_to(other) < 0); } @@ -318,10 +324,10 @@ operator < (const FLOATNAME(LVecBase2) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVecBase2):: +INLINE_LINMATH bool FLOATNAME(LVecBase2):: operator == (const FLOATNAME(LVecBase2) &other) const { - return (_data[0] == other[0] && - _data[1] == other[1]); + return (_v.v._0 == other._v.v._0 && + _v.v._1 == other._v.v._1); } //////////////////////////////////////////////////////////////////// @@ -329,7 +335,7 @@ operator == (const FLOATNAME(LVecBase2) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVecBase2):: +INLINE_LINMATH bool FLOATNAME(LVecBase2):: operator != (const FLOATNAME(LVecBase2) &other) const { return !operator == (other); } @@ -340,7 +346,7 @@ operator != (const FLOATNAME(LVecBase2) &other) const { // Description: This flavor of compare_to uses a default threshold // value based on the numeric type. //////////////////////////////////////////////////////////////////// -INLINE int FLOATNAME(LVecBase2):: +INLINE_LINMATH int FLOATNAME(LVecBase2):: compare_to(const FLOATNAME(LVecBase2) &other) const { return compare_to(other, NEARLY_ZERO(FLOATTYPE)); } @@ -354,13 +360,13 @@ compare_to(const FLOATNAME(LVecBase2) &other) const { // after, 0 if they are equivalent (within the indicated // tolerance). //////////////////////////////////////////////////////////////////// -INLINE int FLOATNAME(LVecBase2):: +INLINE_LINMATH int FLOATNAME(LVecBase2):: compare_to(const FLOATNAME(LVecBase2) &other, FLOATTYPE threshold) const { - if (!IS_THRESHOLD_EQUAL(_data[0], other[0], threshold)) { - return (_data[0] < other[0]) ? -1 : 1; + if (!IS_THRESHOLD_EQUAL(_v.v._0, other._v.v._0, threshold)) { + return (_v.v._0 < other._v.v._0) ? -1 : 1; } - if (!IS_THRESHOLD_EQUAL(_data[1], other[1], threshold)) { - return (_data[1] < other[1]) ? -1 : 1; + if (!IS_THRESHOLD_EQUAL(_v.v._1, other._v.v._1, threshold)) { + return (_v.v._1 < other._v.v._1) ? -1 : 1; } return 0; } @@ -370,9 +376,9 @@ compare_to(const FLOATNAME(LVecBase2) &other, FLOATTYPE threshold) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2) FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVecBase2):: operator - () const { - return FLOATNAME(LVecBase2)(-_data[0], -_data[1]); + return FLOATNAME(LVecBase2)(-_v.v._0, -_v.v._1); } //////////////////////////////////////////////////////////////////// @@ -380,10 +386,10 @@ operator - () const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2) FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVecBase2):: operator + (const FLOATNAME(LVecBase2) &other) const { - return FLOATNAME(LVecBase2)(_data[0] + other[0], - _data[1] + other[1]); + return FLOATNAME(LVecBase2)(_v.v._0 + other._v.v._0, + _v.v._1 + other._v.v._1); } //////////////////////////////////////////////////////////////////// @@ -391,10 +397,10 @@ operator + (const FLOATNAME(LVecBase2) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2) FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVecBase2):: operator - (const FLOATNAME(LVecBase2) &other) const { - return FLOATNAME(LVecBase2)(_data[0] - other[0], - _data[1] - other[1]); + return FLOATNAME(LVecBase2)(_v.v._0 - other._v.v._0, + _v.v._1 - other._v.v._1); } //////////////////////////////////////////////////////////////////// @@ -402,10 +408,10 @@ operator - (const FLOATNAME(LVecBase2) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2) FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVecBase2):: operator * (FLOATTYPE scalar) const { - return FLOATNAME(LVecBase2)(_data[0] * scalar, - _data[1] * scalar); + return FLOATNAME(LVecBase2)(_v.v._0 * scalar, + _v.v._1 * scalar); } //////////////////////////////////////////////////////////////////// @@ -413,10 +419,11 @@ operator * (FLOATTYPE scalar) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2) FLOATNAME(LVecBase2):: +INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVecBase2):: operator / (FLOATTYPE scalar) const { - return FLOATNAME(LVecBase2)(_data[0] / scalar, - _data[1] / scalar); + FLOATTYPE recip_scalar = 1.0/scalar; + return FLOATNAME(LVecBase2)(_v.v._0 * recip_scalar, + _v.v._1 * recip_scalar); } //////////////////////////////////////////////////////////////////// @@ -424,10 +431,10 @@ operator / (FLOATTYPE scalar) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase2):: +INLINE_LINMATH void FLOATNAME(LVecBase2):: operator += (const FLOATNAME(LVecBase2) &other) { - _data[0] += other[0]; - _data[1] += other[1]; + _v.v._0 += other._v.v._0; + _v.v._1 += other._v.v._1; } //////////////////////////////////////////////////////////////////// @@ -435,10 +442,10 @@ operator += (const FLOATNAME(LVecBase2) &other) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase2):: +INLINE_LINMATH void FLOATNAME(LVecBase2):: operator -= (const FLOATNAME(LVecBase2) &other) { - _data[0] -= other[0]; - _data[1] -= other[1]; + _v.v._0 -= other._v.v._0; + _v.v._1 -= other._v.v._1; } //////////////////////////////////////////////////////////////////// @@ -446,10 +453,10 @@ operator -= (const FLOATNAME(LVecBase2) &other) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase2):: +INLINE_LINMATH void FLOATNAME(LVecBase2):: operator *= (FLOATTYPE scalar) { - _data[0] *= scalar; - _data[1] *= scalar; + _v.v._0 *= scalar; + _v.v._1 *= scalar; } //////////////////////////////////////////////////////////////////// @@ -457,10 +464,11 @@ operator *= (FLOATTYPE scalar) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase2):: +INLINE_LINMATH void FLOATNAME(LVecBase2):: operator /= (FLOATTYPE scalar) { - _data[0] /= scalar; - _data[1] /= scalar; + FLOATTYPE recip_scalar = 1.0/scalar; + _v.v._0 *= recip_scalar; + _v.v._1 *= recip_scalar; } //////////////////////////////////////////////////////////////////// @@ -469,10 +477,10 @@ operator /= (FLOATTYPE scalar) { // Description: Returns true if two vectors are memberwise equal // within a specified tolerance. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVecBase2):: +INLINE_LINMATH bool FLOATNAME(LVecBase2):: almost_equal(const FLOATNAME(LVecBase2) &other, FLOATTYPE threshold) const { - return (IS_THRESHOLD_EQUAL(_data[0], other[0], threshold) && - IS_THRESHOLD_EQUAL(_data[1], other[1], threshold)); + return (IS_THRESHOLD_EQUAL(_v.v._0, other._v.v._0, threshold) && + IS_THRESHOLD_EQUAL(_v.v._1, other._v.v._1, threshold)); } //////////////////////////////////////////////////////////////////// @@ -481,7 +489,7 @@ almost_equal(const FLOATNAME(LVecBase2) &other, FLOATTYPE threshold) const { // Description: Returns true if two vectors are memberwise equal // within a default tolerance based on the numeric type. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVecBase2):: +INLINE_LINMATH bool FLOATNAME(LVecBase2):: almost_equal(const FLOATNAME(LVecBase2) &other) const { return almost_equal(other, NEARLY_ZERO(FLOATTYPE)); } @@ -491,10 +499,10 @@ almost_equal(const FLOATNAME(LVecBase2) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase2):: +INLINE_LINMATH void FLOATNAME(LVecBase2):: output(ostream &out) const { - out << MAYBE_ZERO(_data[0]) << " " - << MAYBE_ZERO(_data[1]); + out << MAYBE_ZERO(_v.v._0) << " " + << MAYBE_ZERO(_v.v._1); } //////////////////////////////////////////////////////////////////// @@ -502,10 +510,10 @@ output(ostream &out) const { // Access: Public // Description: Function to write itself into a datagram //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase2):: +INLINE_LINMATH void FLOATNAME(LVecBase2):: write_datagram(Datagram &destination) const { - destination.add_float32(_data[0]); - destination.add_float32(_data[1]); + destination.add_float32(_v.v._0); + destination.add_float32(_v.v._1); } //////////////////////////////////////////////////////////////////// @@ -513,9 +521,9 @@ write_datagram(Datagram &destination) const { // Access: Public // Description: Function to read itself from a datagramIterator //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase2):: +INLINE_LINMATH void FLOATNAME(LVecBase2):: read_datagram(DatagramIterator &source) { - _data[0] = source.get_float32(); - _data[1] = source.get_float32(); + _v.v._0 = source.get_float32(); + _v.v._1 = source.get_float32(); } diff --git a/panda/src/linmath/lvecBase2_src.h b/panda/src/linmath/lvecBase2_src.h index 42e5b56184..26f8857360 100644 --- a/panda/src/linmath/lvecBase2_src.h +++ b/panda/src/linmath/lvecBase2_src.h @@ -3,6 +3,9 @@ // //////////////////////////////////////////////////////////////////// +//typedef struct {FLOATTYPE _0, _1} FLOATNAME(data); + + //////////////////////////////////////////////////////////////////// // Class : LVecBase2 // Description : This is the base class for all two-component @@ -13,79 +16,82 @@ PUBLISHED: typedef const FLOATTYPE *iterator; typedef const FLOATTYPE *const_iterator; - INLINE FLOATNAME(LVecBase2)(); - INLINE FLOATNAME(LVecBase2)(const FLOATNAME(LVecBase2) ©); - INLINE FLOATNAME(LVecBase2) &operator = (const FLOATNAME(LVecBase2) ©); - INLINE FLOATNAME(LVecBase2) &operator = (FLOATTYPE fill_value); - INLINE FLOATNAME(LVecBase2)(FLOATTYPE fill_value); - INLINE FLOATNAME(LVecBase2)(FLOATTYPE x, FLOATTYPE y); + INLINE_LINMATH FLOATNAME(LVecBase2)(); + INLINE_LINMATH FLOATNAME(LVecBase2)(const FLOATNAME(LVecBase2) ©); + INLINE_LINMATH FLOATNAME(LVecBase2) &operator = (const FLOATNAME(LVecBase2) ©); + INLINE_LINMATH FLOATNAME(LVecBase2) &operator = (FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LVecBase2)(FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LVecBase2)(FLOATTYPE x, FLOATTYPE y); - INLINE static const FLOATNAME(LVecBase2) &zero(); - INLINE static const FLOATNAME(LVecBase2) &unit_x(); - INLINE static const FLOATNAME(LVecBase2) &unit_y(); + INLINE_LINMATH static const FLOATNAME(LVecBase2) &zero(); + INLINE_LINMATH static const FLOATNAME(LVecBase2) &unit_x(); + INLINE_LINMATH static const FLOATNAME(LVecBase2) &unit_y(); - INLINE ~FLOATNAME(LVecBase2)(); + INLINE_LINMATH ~FLOATNAME(LVecBase2)(); - INLINE FLOATTYPE operator [](int i) const; - INLINE FLOATTYPE &operator [](int i); + INLINE_LINMATH FLOATTYPE operator [](int i) const; + INLINE_LINMATH FLOATTYPE &operator [](int i); - INLINE bool is_nan() const; + INLINE_LINMATH bool is_nan() const; - INLINE FLOATTYPE get_cell(int i) const; - INLINE FLOATTYPE get_x() const; - INLINE FLOATTYPE get_y() const; - INLINE void set_cell(int i, FLOATTYPE value); - INLINE void set_x(FLOATTYPE value); - INLINE void set_y(FLOATTYPE value); + INLINE_LINMATH FLOATTYPE get_cell(int i) const; + INLINE_LINMATH FLOATTYPE get_x() const; + INLINE_LINMATH FLOATTYPE get_y() const; + INLINE_LINMATH void set_cell(int i, FLOATTYPE value); + INLINE_LINMATH void set_x(FLOATTYPE value); + INLINE_LINMATH void set_y(FLOATTYPE value); - INLINE const FLOATTYPE *get_data() const; - INLINE int get_num_components() const; + INLINE_LINMATH const FLOATTYPE *get_data() const; + INLINE_LINMATH int get_num_components() const; public: - INLINE iterator begin(); - INLINE iterator end(); + INLINE_LINMATH iterator begin(); + INLINE_LINMATH iterator end(); - INLINE const_iterator begin() const; - INLINE const_iterator end() const; + INLINE_LINMATH const_iterator begin() const; + INLINE_LINMATH const_iterator end() const; PUBLISHED: - INLINE void fill(FLOATTYPE fill_value); - INLINE void set(FLOATTYPE x, FLOATTYPE y); + INLINE_LINMATH void fill(FLOATTYPE fill_value); + INLINE_LINMATH void set(FLOATTYPE x, FLOATTYPE y); - INLINE FLOATTYPE dot(const FLOATNAME(LVecBase2) &other) const; + INLINE_LINMATH FLOATTYPE dot(const FLOATNAME(LVecBase2) &other) const; - INLINE bool operator < (const FLOATNAME(LVecBase2) &other) const; - INLINE bool operator == (const FLOATNAME(LVecBase2) &other) const; - INLINE bool operator != (const FLOATNAME(LVecBase2) &other) const; + INLINE_LINMATH bool operator < (const FLOATNAME(LVecBase2) &other) const; + INLINE_LINMATH bool operator == (const FLOATNAME(LVecBase2) &other) const; + INLINE_LINMATH bool operator != (const FLOATNAME(LVecBase2) &other) const; - INLINE int compare_to(const FLOATNAME(LVecBase2) &other) const; - INLINE int compare_to(const FLOATNAME(LVecBase2) &other, + INLINE_LINMATH int compare_to(const FLOATNAME(LVecBase2) &other) const; + INLINE_LINMATH int compare_to(const FLOATNAME(LVecBase2) &other, FLOATTYPE threshold) const; - INLINE FLOATNAME(LVecBase2) operator - () const; + INLINE_LINMATH FLOATNAME(LVecBase2) operator - () const; - INLINE FLOATNAME(LVecBase2) + INLINE_LINMATH FLOATNAME(LVecBase2) operator + (const FLOATNAME(LVecBase2) &other) const; - INLINE FLOATNAME(LVecBase2) + INLINE_LINMATH FLOATNAME(LVecBase2) operator - (const FLOATNAME(LVecBase2) &other) const; - INLINE FLOATNAME(LVecBase2) operator * (FLOATTYPE scalar) const; - INLINE FLOATNAME(LVecBase2) operator / (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATNAME(LVecBase2) operator * (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATNAME(LVecBase2) operator / (FLOATTYPE scalar) const; - INLINE void operator += (const FLOATNAME(LVecBase2) &other); - INLINE void operator -= (const FLOATNAME(LVecBase2) &other); + INLINE_LINMATH void operator += (const FLOATNAME(LVecBase2) &other); + INLINE_LINMATH void operator -= (const FLOATNAME(LVecBase2) &other); - INLINE void operator *= (FLOATTYPE scalar); - INLINE void operator /= (FLOATTYPE scalar); + INLINE_LINMATH void operator *= (FLOATTYPE scalar); + INLINE_LINMATH void operator /= (FLOATTYPE scalar); - INLINE bool almost_equal(const FLOATNAME(LVecBase2) &other, + INLINE_LINMATH bool almost_equal(const FLOATNAME(LVecBase2) &other, FLOATTYPE threshold) const; - INLINE bool almost_equal(const FLOATNAME(LVecBase2) &other) const; + INLINE_LINMATH bool almost_equal(const FLOATNAME(LVecBase2) &other) const; - INLINE void output(ostream &out) const; + INLINE_LINMATH void output(ostream &out) const; -protected: - FLOATTYPE _data[2]; +public: + union { + FLOATTYPE data[2]; + struct {FLOATTYPE _0, _1;} v; + } _v; private: static const FLOATNAME(LVecBase2) _zero; @@ -93,8 +99,8 @@ private: static const FLOATNAME(LVecBase2) _unit_y; public: - INLINE void write_datagram(Datagram &destination) const; - INLINE void read_datagram(DatagramIterator &source); + INLINE_LINMATH void write_datagram(Datagram &destination) const; + INLINE_LINMATH void read_datagram(DatagramIterator &source); public: static TypeHandle get_class_type() { @@ -107,7 +113,7 @@ private: }; -INLINE ostream &operator << (ostream &out, const FLOATNAME(LVecBase2) &vec) { +INLINE_LINMATH ostream &operator << (ostream &out, const FLOATNAME(LVecBase2) &vec) { vec.output(out); return out; } diff --git a/panda/src/linmath/lvecBase3_src.I b/panda/src/linmath/lvecBase3_src.I index accbd6bd98..99ceb91e0f 100644 --- a/panda/src/linmath/lvecBase3_src.I +++ b/panda/src/linmath/lvecBase3_src.I @@ -8,7 +8,7 @@ // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATNAME(LVecBase3):: FLOATNAME(LVecBase3)() { } @@ -17,9 +17,12 @@ FLOATNAME(LVecBase3)() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATNAME(LVecBase3):: FLOATNAME(LVecBase3)(const FLOATNAME(LVecBase3) ©) { - (*this) = copy; + _v.v._0 = copy._v.v._0; + _v.v._1 = copy._v.v._1; + _v.v._2 = copy._v.v._2; +// (*this) = copy; } //////////////////////////////////////////////////////////////////// @@ -27,9 +30,12 @@ FLOATNAME(LVecBase3)(const FLOATNAME(LVecBase3) ©) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3):: operator = (const FLOATNAME(LVecBase3) ©) { - set(copy[0], copy[1], copy[2]); + _v.v._0 = copy._v.v._0; + _v.v._1 = copy._v.v._1; + _v.v._2 = copy._v.v._2; +// set(copy[0], copy[1], copy[2]); return *this; } @@ -38,7 +44,7 @@ operator = (const FLOATNAME(LVecBase3) ©) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3):: operator = (FLOATTYPE fill_value) { fill(fill_value); return *this; @@ -49,7 +55,7 @@ operator = (FLOATTYPE fill_value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATNAME(LVecBase3):: FLOATNAME(LVecBase3)(FLOATTYPE fill_value) { fill(fill_value); } @@ -59,9 +65,12 @@ FLOATNAME(LVecBase3)(FLOATTYPE fill_value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATNAME(LVecBase3):: FLOATNAME(LVecBase3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) { - set(x, y, z); + _v.v._0 = x; + _v.v._1 = y; + _v.v._2 = z; +// set(x, y, z); } //////////////////////////////////////////////////////////////////// @@ -69,7 +78,7 @@ FLOATNAME(LVecBase3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) { // Access: Public // Description: Returns a zero-length vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3):: +INLINE_LINMATH const FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3):: zero() { return _zero; } @@ -79,7 +88,7 @@ zero() { // Access: Public // Description: Returns a unit X vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3):: +INLINE_LINMATH const FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3):: unit_x() { return _unit_x; } @@ -89,7 +98,7 @@ unit_x() { // Access: Public // Description: Returns a unit Y vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3):: +INLINE_LINMATH const FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3):: unit_y() { return _unit_y; } @@ -99,7 +108,7 @@ unit_y() { // Access: Public // Description: Returns a unit Z vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3):: +INLINE_LINMATH const FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3):: unit_z() { return _unit_z; } @@ -109,7 +118,7 @@ unit_z() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATNAME(LVecBase3):: ~FLOATNAME(LVecBase3)() { } @@ -118,10 +127,10 @@ INLINE FLOATNAME(LVecBase3):: // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase3):: operator [](int i) const { //nassertr(i >= 0 && i < 3, 0); - return _data[i]; + return _v.data[i]; } //////////////////////////////////////////////////////////////////// @@ -129,10 +138,10 @@ operator [](int i) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE &FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATTYPE &FLOATNAME(LVecBase3):: operator [](int i) { - //nassertr(i >= 0 && i < 3, _data[0]); - return _data[i]; + //nassertr(i >= 0 && i < 3, _v.v._0); + return _v.data[i]; } //////////////////////////////////////////////////////////////////// @@ -141,9 +150,9 @@ operator [](int i) { // Description: Returns true if any component of the vector is // not-a-number, false otherwise. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVecBase3):: +INLINE_LINMATH bool FLOATNAME(LVecBase3):: is_nan() const { - return cnan(_data[0]) || cnan(_data[1]) || cnan(_data[2]); + return cnan(_v.v._0) || cnan(_v.v._1) || cnan(_v.v._2); } //////////////////////////////////////////////////////////////////// @@ -151,10 +160,10 @@ is_nan() const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase3):: get_cell(int i) const { // nassertr(i >= 0 && i < 3, 0); - return _data[i]; + return _v.data[i]; } //////////////////////////////////////////////////////////////////// @@ -162,9 +171,9 @@ get_cell(int i) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase3):: get_x() const { - return _data[0]; + return _v.v._0; } //////////////////////////////////////////////////////////////////// @@ -172,9 +181,9 @@ get_x() const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase3):: get_y() const { - return _data[1]; + return _v.v._1; } //////////////////////////////////////////////////////////////////// @@ -182,9 +191,9 @@ get_y() const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase3):: get_z() const { - return _data[2]; + return _v.v._2; } //////////////////////////////////////////////////////////////////// @@ -192,10 +201,10 @@ get_z() const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase3):: +INLINE_LINMATH void FLOATNAME(LVecBase3):: set_cell(int i, FLOATTYPE value) { // nassertv(i >= 0 && i < 3); - _data[i] = value; + _v.data[i] = value; } //////////////////////////////////////////////////////////////////// @@ -203,9 +212,9 @@ set_cell(int i, FLOATTYPE value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase3):: +INLINE_LINMATH void FLOATNAME(LVecBase3):: set_x(FLOATTYPE value) { - _data[0] = value; + _v.v._0 = value; } //////////////////////////////////////////////////////////////////// @@ -213,9 +222,9 @@ set_x(FLOATTYPE value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase3):: +INLINE_LINMATH void FLOATNAME(LVecBase3):: set_y(FLOATTYPE value) { - _data[1] = value; + _v.v._1 = value; } //////////////////////////////////////////////////////////////////// @@ -223,9 +232,9 @@ set_y(FLOATTYPE value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase3):: +INLINE_LINMATH void FLOATNAME(LVecBase3):: set_z(FLOATTYPE value) { - _data[2] = value; + _v.v._2 = value; } //////////////////////////////////////////////////////////////////// @@ -235,9 +244,9 @@ set_z(FLOATTYPE value) { // elements in the vector. The remaining elements // occupy the next positions consecutively in memory. //////////////////////////////////////////////////////////////////// -INLINE const FLOATTYPE *FLOATNAME(LVecBase3):: +INLINE_LINMATH const FLOATTYPE *FLOATNAME(LVecBase3):: get_data() const { - return _data; + return _v.data; } //////////////////////////////////////////////////////////////////// @@ -245,7 +254,7 @@ get_data() const { // Access: Public // Description: Returns the number of elements in the vector, three. //////////////////////////////////////////////////////////////////// -INLINE int FLOATNAME(LVecBase3):: +INLINE_LINMATH int FLOATNAME(LVecBase3):: get_num_components() const { return 3; } @@ -256,9 +265,9 @@ get_num_components() const { // Description: Returns an iterator that may be used to traverse the // elements of the matrix, STL-style. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3)::iterator FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATNAME(LVecBase3)::iterator FLOATNAME(LVecBase3):: begin() { - return _data; + return _v.data; } //////////////////////////////////////////////////////////////////// @@ -267,7 +276,7 @@ begin() { // Description: Returns an iterator that may be used to traverse the // elements of the matrix, STL-style. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3)::iterator FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATNAME(LVecBase3)::iterator FLOATNAME(LVecBase3):: end() { return begin() + get_num_components(); } @@ -278,9 +287,9 @@ end() { // Description: Returns an iterator that may be used to traverse the // elements of the matrix, STL-style. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3)::const_iterator FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATNAME(LVecBase3)::const_iterator FLOATNAME(LVecBase3):: begin() const { - return _data; + return _v.data; } //////////////////////////////////////////////////////////////////// @@ -289,7 +298,7 @@ begin() const { // Description: Returns an iterator that may be used to traverse the // elements of the matrix, STL-style. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3)::const_iterator FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATNAME(LVecBase3)::const_iterator FLOATNAME(LVecBase3):: end() const { return begin() + get_num_components(); } @@ -301,11 +310,11 @@ end() const { // fill_value. This is particularly useful for // initializing to zero. //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase3):: +INLINE_LINMATH void FLOATNAME(LVecBase3):: fill(FLOATTYPE fill_value) { - _data[0] = fill_value; - _data[1] = fill_value; - _data[2] = fill_value; + _v.v._0 = fill_value; + _v.v._1 = fill_value; + _v.v._2 = fill_value; } //////////////////////////////////////////////////////////////////// @@ -313,11 +322,11 @@ fill(FLOATTYPE fill_value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase3):: +INLINE_LINMATH void FLOATNAME(LVecBase3):: set(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) { - _data[0] = x; - _data[1] = y; - _data[2] = z; + _v.v._0 = x; + _v.v._1 = y; + _v.v._2 = z; } //////////////////////////////////////////////////////////////////// @@ -325,9 +334,9 @@ set(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase3):: dot(const FLOATNAME(LVecBase3) &other) const { - return _data[0] * other[0] + _data[1] * other[1] + _data[2] * other[2]; + return _v.v._0 * other._v.v._0 + _v.v._1 * other._v.v._1 + _v.v._2 * other._v.v._2; } //////////////////////////////////////////////////////////////////// @@ -335,11 +344,11 @@ dot(const FLOATNAME(LVecBase3) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: cross(const FLOATNAME(LVecBase3) &other) const { - return FLOATNAME(LVecBase3)(_data[1] * other[2] - other[1] * _data[2], - other[0] * _data[2] - _data[0] * other[2], - _data[0] * other[1] - other[0] * _data[1]); + return FLOATNAME(LVecBase3)(_v.v._1 * other._v.v._2 - other._v.v._1 * _v.v._2, + other._v.v._0 * _v.v._2 - _v.v._0 * other._v.v._2, + _v.v._0 * other._v.v._1 - other._v.v._0 * _v.v._1); } //////////////////////////////////////////////////////////////////// @@ -351,7 +360,7 @@ cross(const FLOATNAME(LVecBase3) &other) const { // especially in an STL container. Also see // compare_to(). //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVecBase3):: +INLINE_LINMATH bool FLOATNAME(LVecBase3):: operator < (const FLOATNAME(LVecBase3) &other) const { return (compare_to(other) < 0); } @@ -361,11 +370,11 @@ operator < (const FLOATNAME(LVecBase3) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVecBase3):: +INLINE_LINMATH bool FLOATNAME(LVecBase3):: operator == (const FLOATNAME(LVecBase3) &other) const { - return (_data[0] == other[0] && - _data[1] == other[1] && - _data[2] == other[2]); + return (_v.v._0 == other._v.v._0 && + _v.v._1 == other._v.v._1 && + _v.v._2 == other._v.v._2); } //////////////////////////////////////////////////////////////////// @@ -373,7 +382,7 @@ operator == (const FLOATNAME(LVecBase3) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVecBase3):: +INLINE_LINMATH bool FLOATNAME(LVecBase3):: operator != (const FLOATNAME(LVecBase3) &other) const { return !operator == (other); } @@ -384,7 +393,7 @@ operator != (const FLOATNAME(LVecBase3) &other) const { // Description: This flavor of compare_to uses a default threshold // value based on the numeric type. //////////////////////////////////////////////////////////////////// -INLINE int FLOATNAME(LVecBase3):: +INLINE_LINMATH int FLOATNAME(LVecBase3):: compare_to(const FLOATNAME(LVecBase3) &other) const { return compare_to(other, NEARLY_ZERO(FLOATTYPE)); } @@ -398,16 +407,16 @@ compare_to(const FLOATNAME(LVecBase3) &other) const { // after, 0 if they are equivalent (within the indicated // tolerance). //////////////////////////////////////////////////////////////////// -INLINE int FLOATNAME(LVecBase3):: +INLINE_LINMATH int FLOATNAME(LVecBase3):: compare_to(const FLOATNAME(LVecBase3) &other, FLOATTYPE threshold) const { - if (!IS_THRESHOLD_EQUAL(_data[0], other[0], threshold)) { - return (_data[0] < other[0]) ? -1 : 1; + if (!IS_THRESHOLD_EQUAL(_v.v._0, other._v.v._0, threshold)) { + return (_v.v._0 < other._v.v._0) ? -1 : 1; } - if (!IS_THRESHOLD_EQUAL(_data[1], other[1], threshold)) { - return (_data[1] < other[1]) ? -1 : 1; + if (!IS_THRESHOLD_EQUAL(_v.v._1, other._v.v._1, threshold)) { + return (_v.v._1 < other._v.v._1) ? -1 : 1; } - if (!IS_THRESHOLD_EQUAL(_data[2], other[2], threshold)) { - return (_data[2] < other[2]) ? -1 : 1; + if (!IS_THRESHOLD_EQUAL(_v.v._2, other._v.v._2, threshold)) { + return (_v.v._2 < other._v.v._2) ? -1 : 1; } return 0; } @@ -417,9 +426,9 @@ compare_to(const FLOATNAME(LVecBase3) &other, FLOATTYPE threshold) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: operator - () const { - return FLOATNAME(LVecBase3)(-_data[0], -_data[1], -_data[2]); + return FLOATNAME(LVecBase3)(-_v.v._0, -_v.v._1, -_v.v._2); } //////////////////////////////////////////////////////////////////// @@ -427,11 +436,11 @@ operator - () const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: operator + (const FLOATNAME(LVecBase3) &other) const { - return FLOATNAME(LVecBase3)(_data[0] + other[0], - _data[1] + other[1], - _data[2] + other[2]); + return FLOATNAME(LVecBase3)(_v.v._0 + other._v.v._0, + _v.v._1 + other._v.v._1, + _v.v._2 + other._v.v._2); } //////////////////////////////////////////////////////////////////// @@ -439,11 +448,11 @@ operator + (const FLOATNAME(LVecBase3) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: operator - (const FLOATNAME(LVecBase3) &other) const { - return FLOATNAME(LVecBase3)(_data[0] - other[0], - _data[1] - other[1], - _data[2] - other[2]); + return FLOATNAME(LVecBase3)(_v.v._0 - other._v.v._0, + _v.v._1 - other._v.v._1, + _v.v._2 - other._v.v._2); } //////////////////////////////////////////////////////////////////// @@ -451,11 +460,11 @@ operator - (const FLOATNAME(LVecBase3) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: operator * (FLOATTYPE scalar) const { - return FLOATNAME(LVecBase3)(_data[0] * scalar, - _data[1] * scalar, - _data[2] * scalar); + return FLOATNAME(LVecBase3)(_v.v._0 * scalar, + _v.v._1 * scalar, + _v.v._2 * scalar); } //////////////////////////////////////////////////////////////////// @@ -463,11 +472,11 @@ operator * (FLOATTYPE scalar) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: operator / (FLOATTYPE scalar) const { - return FLOATNAME(LVecBase3)(_data[0] / scalar, - _data[1] / scalar, - _data[2] / scalar); + return FLOATNAME(LVecBase3)(_v.v._0 / scalar, + _v.v._1 / scalar, + _v.v._2 / scalar); } //////////////////////////////////////////////////////////////////// @@ -475,11 +484,11 @@ operator / (FLOATTYPE scalar) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase3):: +INLINE_LINMATH void FLOATNAME(LVecBase3):: operator += (const FLOATNAME(LVecBase3) &other) { - _data[0] += other[0]; - _data[1] += other[1]; - _data[2] += other[2]; + _v.v._0 += other._v.v._0; + _v.v._1 += other._v.v._1; + _v.v._2 += other._v.v._2; } //////////////////////////////////////////////////////////////////// @@ -487,11 +496,11 @@ operator += (const FLOATNAME(LVecBase3) &other) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase3):: +INLINE_LINMATH void FLOATNAME(LVecBase3):: operator -= (const FLOATNAME(LVecBase3) &other) { - _data[0] -= other[0]; - _data[1] -= other[1]; - _data[2] -= other[2]; + _v.v._0 -= other._v.v._0; + _v.v._1 -= other._v.v._1; + _v.v._2 -= other._v.v._2; } //////////////////////////////////////////////////////////////////// @@ -499,11 +508,11 @@ operator -= (const FLOATNAME(LVecBase3) &other) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase3):: +INLINE_LINMATH void FLOATNAME(LVecBase3):: operator *= (FLOATTYPE scalar) { - _data[0] *= scalar; - _data[1] *= scalar; - _data[2] *= scalar; + _v.v._0 *= scalar; + _v.v._1 *= scalar; + _v.v._2 *= scalar; } //////////////////////////////////////////////////////////////////// @@ -511,11 +520,12 @@ operator *= (FLOATTYPE scalar) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase3):: +INLINE_LINMATH void FLOATNAME(LVecBase3):: operator /= (FLOATTYPE scalar) { - _data[0] /= scalar; - _data[1] /= scalar; - _data[2] /= scalar; + FLOATTYPE recip_scalar = 1.0/scalar; + _v.v._0 *= recip_scalar; + _v.v._1 *= recip_scalar; + _v.v._2 *= recip_scalar; } //////////////////////////////////////////////////////////////////// @@ -523,7 +533,7 @@ operator /= (FLOATTYPE scalar) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase3):: +INLINE_LINMATH void FLOATNAME(LVecBase3):: cross_into(const FLOATNAME(LVecBase3) &other) { (*this) = cross(other); } @@ -534,11 +544,11 @@ cross_into(const FLOATNAME(LVecBase3) &other) { // Description: Returns true if two vectors are memberwise equal // within a specified tolerance. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVecBase3):: +INLINE_LINMATH bool FLOATNAME(LVecBase3):: almost_equal(const FLOATNAME(LVecBase3) &other, FLOATTYPE threshold) const { - return (IS_THRESHOLD_EQUAL(_data[0], other[0], threshold) && - IS_THRESHOLD_EQUAL(_data[1], other[1], threshold) && - IS_THRESHOLD_EQUAL(_data[2], other[2], threshold)); + return (IS_THRESHOLD_EQUAL(_v.v._0, other._v.v._0, threshold) && + IS_THRESHOLD_EQUAL(_v.v._1, other._v.v._1, threshold) && + IS_THRESHOLD_EQUAL(_v.v._2, other._v.v._2, threshold)); } //////////////////////////////////////////////////////////////////// @@ -547,7 +557,7 @@ almost_equal(const FLOATNAME(LVecBase3) &other, FLOATTYPE threshold) const { // Description: Returns true if two vectors are memberwise equal // within a default tolerance based on the numeric type. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVecBase3):: +INLINE_LINMATH bool FLOATNAME(LVecBase3):: almost_equal(const FLOATNAME(LVecBase3) &other) const { return almost_equal(other, NEARLY_ZERO(FLOATTYPE)); } @@ -557,11 +567,11 @@ almost_equal(const FLOATNAME(LVecBase3) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase3):: +INLINE_LINMATH void FLOATNAME(LVecBase3):: output(ostream &out) const { - out << MAYBE_ZERO(_data[0]) << " " - << MAYBE_ZERO(_data[1]) << " " - << MAYBE_ZERO(_data[2]); + out << MAYBE_ZERO(_v.v._0) << " " + << MAYBE_ZERO(_v.v._1) << " " + << MAYBE_ZERO(_v.v._2); } @@ -570,11 +580,11 @@ output(ostream &out) const { // Access: Public // Description: Function to write itself into a datagram //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase3):: +INLINE_LINMATH void FLOATNAME(LVecBase3):: write_datagram(Datagram &destination) const { - destination.add_float32(_data[0]); - destination.add_float32(_data[1]); - destination.add_float32(_data[2]); + destination.add_float32(_v.v._0); + destination.add_float32(_v.v._1); + destination.add_float32(_v.v._2); } //////////////////////////////////////////////////////////////////// @@ -582,9 +592,9 @@ write_datagram(Datagram &destination) const { // Access: Public // Description: Function to read itself from a datagramIterator //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase3):: +INLINE_LINMATH void FLOATNAME(LVecBase3):: read_datagram(DatagramIterator &source) { - _data[0] = source.get_float32(); - _data[1] = source.get_float32(); - _data[2] = source.get_float32(); + _v.v._0 = source.get_float32(); + _v.v._1 = source.get_float32(); + _v.v._2 = source.get_float32(); } diff --git a/panda/src/linmath/lvecBase3_src.h b/panda/src/linmath/lvecBase3_src.h index 67dfc31866..f58081b72c 100644 --- a/panda/src/linmath/lvecBase3_src.h +++ b/panda/src/linmath/lvecBase3_src.h @@ -13,85 +13,88 @@ PUBLISHED: typedef const FLOATTYPE *iterator; typedef const FLOATTYPE *const_iterator; - INLINE FLOATNAME(LVecBase3)(); - INLINE FLOATNAME(LVecBase3)(const FLOATNAME(LVecBase3) ©); - INLINE FLOATNAME(LVecBase3) &operator = (const FLOATNAME(LVecBase3) ©); - INLINE FLOATNAME(LVecBase3) &operator = (FLOATTYPE fill_value); - INLINE FLOATNAME(LVecBase3)(FLOATTYPE fill_value); - INLINE FLOATNAME(LVecBase3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z); + INLINE_LINMATH FLOATNAME(LVecBase3)(); + INLINE_LINMATH FLOATNAME(LVecBase3)(const FLOATNAME(LVecBase3) ©); + INLINE_LINMATH FLOATNAME(LVecBase3) &operator = (const FLOATNAME(LVecBase3) ©); + INLINE_LINMATH FLOATNAME(LVecBase3) &operator = (FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LVecBase3)(FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LVecBase3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z); - INLINE static const FLOATNAME(LVecBase3) &zero(); - INLINE static const FLOATNAME(LVecBase3) &unit_x(); - INLINE static const FLOATNAME(LVecBase3) &unit_y(); - INLINE static const FLOATNAME(LVecBase3) &unit_z(); + INLINE_LINMATH static const FLOATNAME(LVecBase3) &zero(); + INLINE_LINMATH static const FLOATNAME(LVecBase3) &unit_x(); + INLINE_LINMATH static const FLOATNAME(LVecBase3) &unit_y(); + INLINE_LINMATH static const FLOATNAME(LVecBase3) &unit_z(); - INLINE ~FLOATNAME(LVecBase3)(); + INLINE_LINMATH ~FLOATNAME(LVecBase3)(); - INLINE FLOATTYPE operator [](int i) const; - INLINE FLOATTYPE &operator [](int i); + INLINE_LINMATH FLOATTYPE operator [](int i) const; + INLINE_LINMATH FLOATTYPE &operator [](int i); - INLINE bool is_nan() const; + INLINE_LINMATH bool is_nan() const; - INLINE FLOATTYPE get_cell(int i) const; - INLINE FLOATTYPE get_x() const; - INLINE FLOATTYPE get_y() const; - INLINE FLOATTYPE get_z() const; - INLINE void set_cell(int i, FLOATTYPE value); - INLINE void set_x(FLOATTYPE value); - INLINE void set_y(FLOATTYPE value); - INLINE void set_z(FLOATTYPE value); + INLINE_LINMATH FLOATTYPE get_cell(int i) const; + INLINE_LINMATH FLOATTYPE get_x() const; + INLINE_LINMATH FLOATTYPE get_y() const; + INLINE_LINMATH FLOATTYPE get_z() const; + INLINE_LINMATH void set_cell(int i, FLOATTYPE value); + INLINE_LINMATH void set_x(FLOATTYPE value); + INLINE_LINMATH void set_y(FLOATTYPE value); + INLINE_LINMATH void set_z(FLOATTYPE value); - INLINE const FLOATTYPE *get_data() const; - INLINE int get_num_components() const; + INLINE_LINMATH const FLOATTYPE *get_data() const; + INLINE_LINMATH int get_num_components() const; public: - INLINE iterator begin(); - INLINE iterator end(); + INLINE_LINMATH iterator begin(); + INLINE_LINMATH iterator end(); - INLINE const_iterator begin() const; - INLINE const_iterator end() const; + INLINE_LINMATH const_iterator begin() const; + INLINE_LINMATH const_iterator end() const; PUBLISHED: - INLINE void fill(FLOATTYPE fill_value); - INLINE void set(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z); + INLINE_LINMATH void fill(FLOATTYPE fill_value); + INLINE_LINMATH void set(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z); - INLINE FLOATTYPE dot(const FLOATNAME(LVecBase3) &other) const; - INLINE FLOATNAME(LVecBase3) cross(const FLOATNAME(LVecBase3) &other) const; + INLINE_LINMATH FLOATTYPE dot(const FLOATNAME(LVecBase3) &other) const; + INLINE_LINMATH FLOATNAME(LVecBase3) cross(const FLOATNAME(LVecBase3) &other) const; - INLINE bool operator < (const FLOATNAME(LVecBase3) &other) const; - INLINE bool operator == (const FLOATNAME(LVecBase3) &other) const; - INLINE bool operator != (const FLOATNAME(LVecBase3) &other) const; + INLINE_LINMATH bool operator < (const FLOATNAME(LVecBase3) &other) const; + INLINE_LINMATH bool operator == (const FLOATNAME(LVecBase3) &other) const; + INLINE_LINMATH bool operator != (const FLOATNAME(LVecBase3) &other) const; - INLINE int compare_to(const FLOATNAME(LVecBase3) &other) const; - INLINE int compare_to(const FLOATNAME(LVecBase3) &other, + INLINE_LINMATH int compare_to(const FLOATNAME(LVecBase3) &other) const; + INLINE_LINMATH int compare_to(const FLOATNAME(LVecBase3) &other, FLOATTYPE threshold) const; - INLINE FLOATNAME(LVecBase3) operator - () const; + INLINE_LINMATH FLOATNAME(LVecBase3) operator - () const; - INLINE FLOATNAME(LVecBase3) + INLINE_LINMATH FLOATNAME(LVecBase3) operator + (const FLOATNAME(LVecBase3) &other) const; - INLINE FLOATNAME(LVecBase3) + INLINE_LINMATH FLOATNAME(LVecBase3) operator - (const FLOATNAME(LVecBase3) &other) const; - INLINE FLOATNAME(LVecBase3) operator * (FLOATTYPE scalar) const; - INLINE FLOATNAME(LVecBase3) operator / (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATNAME(LVecBase3) operator * (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATNAME(LVecBase3) operator / (FLOATTYPE scalar) const; - INLINE void operator += (const FLOATNAME(LVecBase3) &other); - INLINE void operator -= (const FLOATNAME(LVecBase3) &other); + INLINE_LINMATH void operator += (const FLOATNAME(LVecBase3) &other); + INLINE_LINMATH void operator -= (const FLOATNAME(LVecBase3) &other); - INLINE void operator *= (FLOATTYPE scalar); - INLINE void operator /= (FLOATTYPE scalar); + INLINE_LINMATH void operator *= (FLOATTYPE scalar); + INLINE_LINMATH void operator /= (FLOATTYPE scalar); - INLINE void cross_into(const FLOATNAME(LVecBase3) &other); + INLINE_LINMATH void cross_into(const FLOATNAME(LVecBase3) &other); - INLINE bool almost_equal(const FLOATNAME(LVecBase3) &other, + INLINE_LINMATH bool almost_equal(const FLOATNAME(LVecBase3) &other, FLOATTYPE threshold) const; - INLINE bool almost_equal(const FLOATNAME(LVecBase3) &other) const; + INLINE_LINMATH bool almost_equal(const FLOATNAME(LVecBase3) &other) const; - INLINE void output(ostream &out) const; + INLINE_LINMATH void output(ostream &out) const; -protected: - FLOATTYPE _data[3]; +public: + union { + FLOATTYPE data[3]; + struct {FLOATTYPE _0, _1, _2;} v; + } _v; private: static const FLOATNAME(LVecBase3) _zero; @@ -100,8 +103,8 @@ private: static const FLOATNAME(LVecBase3) _unit_z; public: - INLINE void write_datagram(Datagram &destination) const; - INLINE void read_datagram(DatagramIterator &source); + INLINE_LINMATH void write_datagram(Datagram &destination) const; + INLINE_LINMATH void read_datagram(DatagramIterator &source); public: static TypeHandle get_class_type() { @@ -114,7 +117,7 @@ private: }; -INLINE ostream &operator << (ostream &out, const FLOATNAME(LVecBase3) &vec) { +INLINE_LINMATH ostream &operator << (ostream &out, const FLOATNAME(LVecBase3) &vec) { vec.output(out); return out; }; diff --git a/panda/src/linmath/lvecBase4_src.I b/panda/src/linmath/lvecBase4_src.I index 2586211923..9a621de8f6 100644 --- a/panda/src/linmath/lvecBase4_src.I +++ b/panda/src/linmath/lvecBase4_src.I @@ -9,7 +9,7 @@ // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATNAME(LVecBase4):: FLOATNAME(LVecBase4)() { } @@ -18,9 +18,13 @@ FLOATNAME(LVecBase4)() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATNAME(LVecBase4):: FLOATNAME(LVecBase4)(const FLOATNAME(LVecBase4) ©) { - (*this) = copy; + _v.v._0 = copy._v.v._0; + _v.v._1 = copy._v.v._1; + _v.v._2 = copy._v.v._2; + _v.v._3 = copy._v.v._3; +// (*this) = copy; } //////////////////////////////////////////////////////////////////// @@ -28,9 +32,13 @@ FLOATNAME(LVecBase4)(const FLOATNAME(LVecBase4) ©) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4):: operator = (const FLOATNAME(LVecBase4) ©) { - set(copy[0], copy[1], copy[2], copy[3]); + _v.v._0 = copy._v.v._0; + _v.v._1 = copy._v.v._1; + _v.v._2 = copy._v.v._2; + _v.v._3 = copy._v.v._3; +// set(copy[0], copy[1], copy[2], copy[3]); return *this; } @@ -39,7 +47,7 @@ operator = (const FLOATNAME(LVecBase4) ©) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4):: operator = (FLOATTYPE fill_value) { fill(fill_value); return *this; @@ -50,7 +58,7 @@ operator = (FLOATTYPE fill_value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATNAME(LVecBase4):: FLOATNAME(LVecBase4)(FLOATTYPE fill_value) { fill(fill_value); } @@ -60,9 +68,13 @@ FLOATNAME(LVecBase4)(FLOATTYPE fill_value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATNAME(LVecBase4):: FLOATNAME(LVecBase4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w) { - set(x, y, z, w); + _v.v._0 = x; + _v.v._1 = y; + _v.v._2 = z; + _v.v._3 = w; +// set(x, y, z, w); } //////////////////////////////////////////////////////////////////// @@ -70,7 +82,7 @@ FLOATNAME(LVecBase4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATNAME(LVecBase4):: ~FLOATNAME(LVecBase4)() { } @@ -79,7 +91,7 @@ INLINE FLOATNAME(LVecBase4):: // Access: Public // Description: Returns a zero-length vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4):: +INLINE_LINMATH const FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4):: zero() { return _zero; } @@ -89,7 +101,7 @@ zero() { // Access: Public // Description: Returns a unit X vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4):: +INLINE_LINMATH const FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4):: unit_x() { return _unit_x; } @@ -99,7 +111,7 @@ unit_x() { // Access: Public // Description: Returns a unit Y vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4):: +INLINE_LINMATH const FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4):: unit_y() { return _unit_y; } @@ -109,7 +121,7 @@ unit_y() { // Access: Public // Description: Returns a unit Z vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4):: +INLINE_LINMATH const FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4):: unit_z() { return _unit_z; } @@ -119,7 +131,7 @@ unit_z() { // Access: Public // Description: Returns a unit W vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4):: +INLINE_LINMATH const FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4):: unit_w() { return _unit_w; } @@ -129,10 +141,10 @@ unit_w() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase4):: operator [](int i) const { // nassertr(i >= 0 && i < 4, 0); - return _data[i]; + return _v.data[i]; } //////////////////////////////////////////////////////////////////// @@ -140,10 +152,10 @@ operator [](int i) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE &FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATTYPE &FLOATNAME(LVecBase4):: operator [](int i) { - // nassertr(i >= 0 && i < 4, _data[0]); - return _data[i]; + // nassertr(i >= 0 && i < 4, _v.v._0); + return _v.data[i]; } //////////////////////////////////////////////////////////////////// @@ -152,9 +164,9 @@ operator [](int i) { // Description: Returns true if any component of the vector is // not-a-number, false otherwise. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVecBase4):: +INLINE_LINMATH bool FLOATNAME(LVecBase4):: is_nan() const { - return cnan(_data[0]) || cnan(_data[1]) || cnan(_data[2]) || cnan(_data[3]); + return cnan(_v.v._0) || cnan(_v.v._1) || cnan(_v.v._2) || cnan(_v.v._3); } //////////////////////////////////////////////////////////////////// @@ -162,10 +174,10 @@ is_nan() const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase4):: get_cell(int i) const { // nassertr(i >= 0 && i < 4, 0); - return _data[i]; + return _v.data[i]; } //////////////////////////////////////////////////////////////////// @@ -173,9 +185,9 @@ get_cell(int i) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase4):: get_x() const { - return _data[0]; + return _v.v._0; } //////////////////////////////////////////////////////////////////// @@ -183,9 +195,9 @@ get_x() const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase4):: get_y() const { - return _data[1]; + return _v.v._1; } //////////////////////////////////////////////////////////////////// @@ -193,9 +205,9 @@ get_y() const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase4):: get_z() const { - return _data[2]; + return _v.v._2; } //////////////////////////////////////////////////////////////////// @@ -203,9 +215,9 @@ get_z() const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase4):: get_w() const { - return _data[3]; + return _v.v._3; } //////////////////////////////////////////////////////////////////// @@ -213,10 +225,10 @@ get_w() const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase4):: +INLINE_LINMATH void FLOATNAME(LVecBase4):: set_cell(int i, FLOATTYPE value) { // nassertv(i >= 0 && i < 4); - _data[i] = value; + _v.data[i] = value; } //////////////////////////////////////////////////////////////////// @@ -224,9 +236,9 @@ set_cell(int i, FLOATTYPE value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase4):: +INLINE_LINMATH void FLOATNAME(LVecBase4):: set_x(FLOATTYPE value) { - _data[0] = value; + _v.v._0 = value; } //////////////////////////////////////////////////////////////////// @@ -234,9 +246,9 @@ set_x(FLOATTYPE value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase4):: +INLINE_LINMATH void FLOATNAME(LVecBase4):: set_y(FLOATTYPE value) { - _data[1] = value; + _v.v._1 = value; } //////////////////////////////////////////////////////////////////// @@ -244,9 +256,9 @@ set_y(FLOATTYPE value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase4):: +INLINE_LINMATH void FLOATNAME(LVecBase4):: set_z(FLOATTYPE value) { - _data[2] = value; + _v.v._2 = value; } //////////////////////////////////////////////////////////////////// @@ -254,9 +266,9 @@ set_z(FLOATTYPE value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase4):: +INLINE_LINMATH void FLOATNAME(LVecBase4):: set_w(FLOATTYPE value) { - _data[3] = value; + _v.v._3 = value; } //////////////////////////////////////////////////////////////////// @@ -266,9 +278,9 @@ set_w(FLOATTYPE value) { // elements in the vector. The remaining elements // occupy the next positions consecutively in memory. //////////////////////////////////////////////////////////////////// -INLINE const FLOATTYPE *FLOATNAME(LVecBase4):: +INLINE_LINMATH const FLOATTYPE *FLOATNAME(LVecBase4):: get_data() const { - return _data; + return _v.data; } //////////////////////////////////////////////////////////////////// @@ -276,7 +288,7 @@ get_data() const { // Access: Public // Description: Returns the number of elements in the vector, four. //////////////////////////////////////////////////////////////////// -INLINE int FLOATNAME(LVecBase4):: +INLINE_LINMATH int FLOATNAME(LVecBase4):: get_num_components() const { return 4; } @@ -287,9 +299,9 @@ get_num_components() const { // Description: Returns an iterator that may be used to traverse the // elements of the matrix, STL-style. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4)::iterator FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATNAME(LVecBase4)::iterator FLOATNAME(LVecBase4):: begin() { - return _data; + return _v.data; } //////////////////////////////////////////////////////////////////// @@ -298,7 +310,7 @@ begin() { // Description: Returns an iterator that may be used to traverse the // elements of the matrix, STL-style. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4)::iterator FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATNAME(LVecBase4)::iterator FLOATNAME(LVecBase4):: end() { return begin() + get_num_components(); } @@ -309,9 +321,9 @@ end() { // Description: Returns an iterator that may be used to traverse the // elements of the matrix, STL-style. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4)::const_iterator FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATNAME(LVecBase4)::const_iterator FLOATNAME(LVecBase4):: begin() const { - return _data; + return _v.data; } //////////////////////////////////////////////////////////////////// @@ -320,7 +332,7 @@ begin() const { // Description: Returns an iterator that may be used to traverse the // elements of the matrix, STL-style. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4)::const_iterator FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATNAME(LVecBase4)::const_iterator FLOATNAME(LVecBase4):: end() const { return begin() + get_num_components(); } @@ -332,12 +344,12 @@ end() const { // fill_value. This is particularly useful for // initializing to zero. //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase4):: +INLINE_LINMATH void FLOATNAME(LVecBase4):: fill(FLOATTYPE fill_value) { - _data[0] = fill_value; - _data[1] = fill_value; - _data[2] = fill_value; - _data[3] = fill_value; + _v.v._0 = fill_value; + _v.v._1 = fill_value; + _v.v._2 = fill_value; + _v.v._3 = fill_value; } //////////////////////////////////////////////////////////////////// @@ -345,12 +357,12 @@ fill(FLOATTYPE fill_value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase4):: +INLINE_LINMATH void FLOATNAME(LVecBase4):: set(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w) { - _data[0] = x; - _data[1] = y; - _data[2] = z; - _data[3] = w; + _v.v._0 = x; + _v.v._1 = y; + _v.v._2 = z; + _v.v._3 = w; } //////////////////////////////////////////////////////////////////// @@ -358,11 +370,11 @@ set(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase4):: dot(const FLOATNAME(LVecBase4) &other) const { return - _data[0] * other[0] + _data[1] * other[1] + - _data[2] * other[2] + _data[3] * other[3]; + _v.v._0 * other._v.v._0 + _v.v._1 * other._v.v._1 + + _v.v._2 * other._v.v._2 + _v.v._3 * other._v.v._3; } //////////////////////////////////////////////////////////////////// @@ -374,7 +386,7 @@ dot(const FLOATNAME(LVecBase4) &other) const { // especially in an STL container. Also see // compare_to(). //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVecBase4):: +INLINE_LINMATH bool FLOATNAME(LVecBase4):: operator < (const FLOATNAME(LVecBase4) &other) const { return (compare_to(other) < 0); } @@ -384,12 +396,12 @@ operator < (const FLOATNAME(LVecBase4) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVecBase4):: +INLINE_LINMATH bool FLOATNAME(LVecBase4):: operator == (const FLOATNAME(LVecBase4) &other) const { - return (_data[0] == other[0] && - _data[1] == other[1] && - _data[2] == other[2] && - _data[3] == other[3]); + return (_v.v._0 == other._v.v._0 && + _v.v._1 == other._v.v._1 && + _v.v._2 == other._v.v._2 && + _v.v._3 == other._v.v._3); } //////////////////////////////////////////////////////////////////// @@ -397,7 +409,7 @@ operator == (const FLOATNAME(LVecBase4) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVecBase4):: +INLINE_LINMATH bool FLOATNAME(LVecBase4):: operator != (const FLOATNAME(LVecBase4) &other) const { return !operator == (other); } @@ -408,7 +420,7 @@ operator != (const FLOATNAME(LVecBase4) &other) const { // Description: This flavor of compare_to uses a default threshold // value based on the numeric type. //////////////////////////////////////////////////////////////////// -INLINE int FLOATNAME(LVecBase4):: +INLINE_LINMATH int FLOATNAME(LVecBase4):: compare_to(const FLOATNAME(LVecBase4) &other) const { return compare_to(other, NEARLY_ZERO(FLOATTYPE)); } @@ -422,19 +434,19 @@ compare_to(const FLOATNAME(LVecBase4) &other) const { // after, 0 if they are equivalent (within the indicated // tolerance). //////////////////////////////////////////////////////////////////// -INLINE int FLOATNAME(LVecBase4):: +INLINE_LINMATH int FLOATNAME(LVecBase4):: compare_to(const FLOATNAME(LVecBase4) &other, FLOATTYPE threshold) const { - if (!IS_THRESHOLD_EQUAL(_data[0], other[0], threshold)) { - return (_data[0] < other[0]) ? -1 : 1; + if (!IS_THRESHOLD_EQUAL(_v.v._0, other._v.v._0, threshold)) { + return (_v.v._0 < other._v.v._0) ? -1 : 1; } - if (!IS_THRESHOLD_EQUAL(_data[1], other[1], threshold)) { - return (_data[1] < other[1]) ? -1 : 1; + if (!IS_THRESHOLD_EQUAL(_v.v._1, other._v.v._1, threshold)) { + return (_v.v._1 < other._v.v._1) ? -1 : 1; } - if (!IS_THRESHOLD_EQUAL(_data[2], other[2], threshold)) { - return (_data[2] < other[2]) ? -1 : 1; + if (!IS_THRESHOLD_EQUAL(_v.v._2, other._v.v._2, threshold)) { + return (_v.v._2 < other._v.v._2) ? -1 : 1; } - if (!IS_THRESHOLD_EQUAL(_data[3], other[3], threshold)) { - return (_data[3] < other[3]) ? -1 : 1; + if (!IS_THRESHOLD_EQUAL(_v.v._3, other._v.v._3, threshold)) { + return (_v.v._3 < other._v.v._3) ? -1 : 1; } return 0; } @@ -444,9 +456,9 @@ compare_to(const FLOATNAME(LVecBase4) &other, FLOATTYPE threshold) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4) FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVecBase4):: operator - () const { - return FLOATNAME(LVecBase4)(-_data[0], -_data[1], -_data[2], -_data[3]); + return FLOATNAME(LVecBase4)(-_v.v._0, -_v.v._1, -_v.v._2, -_v.v._3); } //////////////////////////////////////////////////////////////////// @@ -454,12 +466,12 @@ operator - () const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4) FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVecBase4):: operator + (const FLOATNAME(LVecBase4) &other) const { - return FLOATNAME(LVecBase4)(_data[0] + other[0], - _data[1] + other[1], - _data[2] + other[2], - _data[3] + other[3]); + return FLOATNAME(LVecBase4)(_v.v._0 + other._v.v._0, + _v.v._1 + other._v.v._1, + _v.v._2 + other._v.v._2, + _v.v._3 + other._v.v._3); } //////////////////////////////////////////////////////////////////// @@ -467,12 +479,12 @@ operator + (const FLOATNAME(LVecBase4) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4) FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVecBase4):: operator - (const FLOATNAME(LVecBase4) &other) const { - return FLOATNAME(LVecBase4)(_data[0] - other[0], - _data[1] - other[1], - _data[2] - other[2], - _data[3] - other[3]); + return FLOATNAME(LVecBase4)(_v.v._0 - other._v.v._0, + _v.v._1 - other._v.v._1, + _v.v._2 - other._v.v._2, + _v.v._3 - other._v.v._3); } //////////////////////////////////////////////////////////////////// @@ -480,12 +492,12 @@ operator - (const FLOATNAME(LVecBase4) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4) FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVecBase4):: operator * (FLOATTYPE scalar) const { - return FLOATNAME(LVecBase4)(_data[0] * scalar, - _data[1] * scalar, - _data[2] * scalar, - _data[3] * scalar); + return FLOATNAME(LVecBase4)(_v.v._0 * scalar, + _v.v._1 * scalar, + _v.v._2 * scalar, + _v.v._3 * scalar); } //////////////////////////////////////////////////////////////////// @@ -493,12 +505,13 @@ operator * (FLOATTYPE scalar) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4) FLOATNAME(LVecBase4):: +INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVecBase4):: operator / (FLOATTYPE scalar) const { - return FLOATNAME(LVecBase4)(_data[0] / scalar, - _data[1] / scalar, - _data[2] / scalar, - _data[3] / scalar); + FLOATTYPE recip_scalar = 1.0/scalar; + return FLOATNAME(LVecBase4)(_v.v._0 * recip_scalar, + _v.v._1 * recip_scalar, + _v.v._2 * recip_scalar, + _v.v._3 * recip_scalar); } //////////////////////////////////////////////////////////////////// @@ -506,12 +519,12 @@ operator / (FLOATTYPE scalar) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase4):: +INLINE_LINMATH void FLOATNAME(LVecBase4):: operator += (const FLOATNAME(LVecBase4) &other) { - _data[0] += other[0]; - _data[1] += other[1]; - _data[2] += other[2]; - _data[3] += other[3]; + _v.v._0 += other._v.v._0; + _v.v._1 += other._v.v._1; + _v.v._2 += other._v.v._2; + _v.v._3 += other._v.v._3; } //////////////////////////////////////////////////////////////////// @@ -519,12 +532,12 @@ operator += (const FLOATNAME(LVecBase4) &other) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase4):: +INLINE_LINMATH void FLOATNAME(LVecBase4):: operator -= (const FLOATNAME(LVecBase4) &other) { - _data[0] -= other[0]; - _data[1] -= other[1]; - _data[2] -= other[2]; - _data[3] -= other[3]; + _v.v._0 -= other._v.v._0; + _v.v._1 -= other._v.v._1; + _v.v._2 -= other._v.v._2; + _v.v._3 -= other._v.v._3; } //////////////////////////////////////////////////////////////////// @@ -532,12 +545,12 @@ operator -= (const FLOATNAME(LVecBase4) &other) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase4):: +INLINE_LINMATH void FLOATNAME(LVecBase4):: operator *= (FLOATTYPE scalar) { - _data[0] *= scalar; - _data[1] *= scalar; - _data[2] *= scalar; - _data[3] *= scalar; + _v.v._0 *= scalar; + _v.v._1 *= scalar; + _v.v._2 *= scalar; + _v.v._3 *= scalar; } //////////////////////////////////////////////////////////////////// @@ -545,12 +558,13 @@ operator *= (FLOATTYPE scalar) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase4):: +INLINE_LINMATH void FLOATNAME(LVecBase4):: operator /= (FLOATTYPE scalar) { - _data[0] /= scalar; - _data[1] /= scalar; - _data[2] /= scalar; - _data[3] /= scalar; + FLOATTYPE recip_scalar = 1.0/scalar; + _v.v._0 *= recip_scalar; + _v.v._1 *= recip_scalar; + _v.v._2 *= recip_scalar; + _v.v._3 *= recip_scalar; } //////////////////////////////////////////////////////////////////// @@ -559,12 +573,12 @@ operator /= (FLOATTYPE scalar) { // Description: Returns true if two vectors are memberwise equal // within a specified tolerance. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVecBase4):: +INLINE_LINMATH bool FLOATNAME(LVecBase4):: almost_equal(const FLOATNAME(LVecBase4) &other, FLOATTYPE threshold) const { - return (IS_THRESHOLD_EQUAL(_data[0], other[0], threshold) && - IS_THRESHOLD_EQUAL(_data[1], other[1], threshold) && - IS_THRESHOLD_EQUAL(_data[2], other[2], threshold) && - IS_THRESHOLD_EQUAL(_data[3], other[3], threshold)); + return (IS_THRESHOLD_EQUAL(_v.v._0, other._v.v._0, threshold) && + IS_THRESHOLD_EQUAL(_v.v._1, other._v.v._1, threshold) && + IS_THRESHOLD_EQUAL(_v.v._2, other._v.v._2, threshold) && + IS_THRESHOLD_EQUAL(_v.v._3, other._v.v._3, threshold)); } //////////////////////////////////////////////////////////////////// @@ -573,7 +587,7 @@ almost_equal(const FLOATNAME(LVecBase4) &other, FLOATTYPE threshold) const { // Description: Returns true if two vectors are memberwise equal // within a default tolerance based on the numeric type. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVecBase4):: +INLINE_LINMATH bool FLOATNAME(LVecBase4):: almost_equal(const FLOATNAME(LVecBase4) &other) const { return almost_equal(other, NEARLY_ZERO(FLOATTYPE)); } @@ -583,12 +597,12 @@ almost_equal(const FLOATNAME(LVecBase4) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase4):: +INLINE_LINMATH void FLOATNAME(LVecBase4):: output(ostream &out) const { - out << MAYBE_ZERO(_data[0]) << " " - << MAYBE_ZERO(_data[1]) << " " - << MAYBE_ZERO(_data[2]) << " " - << MAYBE_ZERO(_data[3]); + out << MAYBE_ZERO(_v.v._0) << " " + << MAYBE_ZERO(_v.v._1) << " " + << MAYBE_ZERO(_v.v._2) << " " + << MAYBE_ZERO(_v.v._3); } //////////////////////////////////////////////////////////////////// @@ -596,12 +610,12 @@ output(ostream &out) const { // Access: Public // Description: Function to write itself into a datagram //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase4):: +INLINE_LINMATH void FLOATNAME(LVecBase4):: write_datagram(Datagram &destination) const { - destination.add_float32(_data[0]); - destination.add_float32(_data[1]); - destination.add_float32(_data[2]); - destination.add_float32(_data[3]); + destination.add_float32(_v.v._0); + destination.add_float32(_v.v._1); + destination.add_float32(_v.v._2); + destination.add_float32(_v.v._3); } //////////////////////////////////////////////////////////////////// @@ -609,10 +623,10 @@ write_datagram(Datagram &destination) const { // Access: Public // Description: Function to read itself from a datagramIterator //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(LVecBase4):: +INLINE_LINMATH void FLOATNAME(LVecBase4):: read_datagram(DatagramIterator &source) { - _data[0] = source.get_float32(); - _data[1] = source.get_float32(); - _data[2] = source.get_float32(); - _data[3] = source.get_float32(); + _v.v._0 = source.get_float32(); + _v.v._1 = source.get_float32(); + _v.v._2 = source.get_float32(); + _v.v._3 = source.get_float32(); } diff --git a/panda/src/linmath/lvecBase4_src.h b/panda/src/linmath/lvecBase4_src.h index a60a736d18..eb65822127 100644 --- a/panda/src/linmath/lvecBase4_src.h +++ b/panda/src/linmath/lvecBase4_src.h @@ -13,85 +13,89 @@ PUBLISHED: typedef const FLOATTYPE *iterator; typedef const FLOATTYPE *const_iterator; - INLINE FLOATNAME(LVecBase4)(); - INLINE FLOATNAME(LVecBase4)(const FLOATNAME(LVecBase4) ©); - INLINE FLOATNAME(LVecBase4) &operator = (const FLOATNAME(LVecBase4) ©); - INLINE FLOATNAME(LVecBase4) &operator = (FLOATTYPE fill_value); - INLINE FLOATNAME(LVecBase4)(FLOATTYPE fill_value); - INLINE FLOATNAME(LVecBase4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); + INLINE_LINMATH FLOATNAME(LVecBase4)(); + INLINE_LINMATH FLOATNAME(LVecBase4)(const FLOATNAME(LVecBase4) ©); + INLINE_LINMATH FLOATNAME(LVecBase4) &operator = (const FLOATNAME(LVecBase4) ©); + INLINE_LINMATH FLOATNAME(LVecBase4) &operator = (FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LVecBase4)(FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LVecBase4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); - INLINE static const FLOATNAME(LVecBase4) &zero(); - INLINE static const FLOATNAME(LVecBase4) &unit_x(); - INLINE static const FLOATNAME(LVecBase4) &unit_y(); - INLINE static const FLOATNAME(LVecBase4) &unit_z(); - INLINE static const FLOATNAME(LVecBase4) &unit_w(); + INLINE_LINMATH static const FLOATNAME(LVecBase4) &zero(); + INLINE_LINMATH static const FLOATNAME(LVecBase4) &unit_x(); + INLINE_LINMATH static const FLOATNAME(LVecBase4) &unit_y(); + INLINE_LINMATH static const FLOATNAME(LVecBase4) &unit_z(); + INLINE_LINMATH static const FLOATNAME(LVecBase4) &unit_w(); - INLINE ~FLOATNAME(LVecBase4)(); + INLINE_LINMATH ~FLOATNAME(LVecBase4)(); - INLINE FLOATTYPE operator [](int i) const; - INLINE FLOATTYPE &operator [](int i); + INLINE_LINMATH FLOATTYPE operator [](int i) const; + INLINE_LINMATH FLOATTYPE &operator [](int i); - INLINE bool is_nan() const; + INLINE_LINMATH bool is_nan() const; - INLINE FLOATTYPE get_cell(int i) const; - INLINE FLOATTYPE get_x() const; - INLINE FLOATTYPE get_y() const; - INLINE FLOATTYPE get_z() const; - INLINE FLOATTYPE get_w() const; - INLINE void set_cell(int i, FLOATTYPE value); - INLINE void set_x(FLOATTYPE value); - INLINE void set_y(FLOATTYPE value); - INLINE void set_z(FLOATTYPE value); - INLINE void set_w(FLOATTYPE value); + INLINE_LINMATH FLOATTYPE get_cell(int i) const; + INLINE_LINMATH FLOATTYPE get_x() const; + INLINE_LINMATH FLOATTYPE get_y() const; + INLINE_LINMATH FLOATTYPE get_z() const; + INLINE_LINMATH FLOATTYPE get_w() const; + INLINE_LINMATH void set_cell(int i, FLOATTYPE value); + INLINE_LINMATH void set_x(FLOATTYPE value); + INLINE_LINMATH void set_y(FLOATTYPE value); + INLINE_LINMATH void set_z(FLOATTYPE value); + INLINE_LINMATH void set_w(FLOATTYPE value); - INLINE const FLOATTYPE *get_data() const; - INLINE int get_num_components() const; + INLINE_LINMATH const FLOATTYPE *get_data() const; + INLINE_LINMATH int get_num_components() const; public: - INLINE iterator begin(); - INLINE iterator end(); + INLINE_LINMATH iterator begin(); + INLINE_LINMATH iterator end(); - INLINE const_iterator begin() const; - INLINE const_iterator end() const; + INLINE_LINMATH const_iterator begin() const; + INLINE_LINMATH const_iterator end() const; PUBLISHED: - INLINE void fill(FLOATTYPE fill_value); - INLINE void set(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); + INLINE_LINMATH void fill(FLOATTYPE fill_value); + INLINE_LINMATH void set(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); - INLINE FLOATTYPE dot(const FLOATNAME(LVecBase4) &other) const; + INLINE_LINMATH FLOATTYPE dot(const FLOATNAME(LVecBase4) &other) const; - INLINE bool operator < (const FLOATNAME(LVecBase4) &other) const; - INLINE bool operator == (const FLOATNAME(LVecBase4) &other) const; - INLINE bool operator != (const FLOATNAME(LVecBase4) &other) const; + INLINE_LINMATH bool operator < (const FLOATNAME(LVecBase4) &other) const; + INLINE_LINMATH bool operator == (const FLOATNAME(LVecBase4) &other) const; + INLINE_LINMATH bool operator != (const FLOATNAME(LVecBase4) &other) const; - INLINE int compare_to(const FLOATNAME(LVecBase4) &other) const; - INLINE int compare_to(const FLOATNAME(LVecBase4) &other, + INLINE_LINMATH int compare_to(const FLOATNAME(LVecBase4) &other) const; + INLINE_LINMATH int compare_to(const FLOATNAME(LVecBase4) &other, FLOATTYPE threshold) const; - INLINE FLOATNAME(LVecBase4) operator - () const; + INLINE_LINMATH FLOATNAME(LVecBase4) operator - () const; - INLINE FLOATNAME(LVecBase4) + INLINE_LINMATH FLOATNAME(LVecBase4) operator + (const FLOATNAME(LVecBase4) &other) const; - INLINE FLOATNAME(LVecBase4) + INLINE_LINMATH FLOATNAME(LVecBase4) operator - (const FLOATNAME(LVecBase4) &other) const; - INLINE FLOATNAME(LVecBase4) operator * (FLOATTYPE scalar) const; - INLINE FLOATNAME(LVecBase4) operator / (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATNAME(LVecBase4) operator * (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATNAME(LVecBase4) operator / (FLOATTYPE scalar) const; - INLINE void operator += (const FLOATNAME(LVecBase4) &other); - INLINE void operator -= (const FLOATNAME(LVecBase4) &other); + INLINE_LINMATH void operator += (const FLOATNAME(LVecBase4) &other); + INLINE_LINMATH void operator -= (const FLOATNAME(LVecBase4) &other); - INLINE void operator *= (FLOATTYPE scalar); - INLINE void operator /= (FLOATTYPE scalar); + INLINE_LINMATH void operator *= (FLOATTYPE scalar); + INLINE_LINMATH void operator /= (FLOATTYPE scalar); - INLINE bool almost_equal(const FLOATNAME(LVecBase4) &other, + INLINE_LINMATH bool almost_equal(const FLOATNAME(LVecBase4) &other, FLOATTYPE threshold) const; - INLINE bool almost_equal(const FLOATNAME(LVecBase4) &other) const; + INLINE_LINMATH bool almost_equal(const FLOATNAME(LVecBase4) &other) const; - INLINE void output(ostream &out) const; + INLINE_LINMATH void output(ostream &out) const; -protected: - FLOATTYPE _data[4]; +public: + + union { + FLOATTYPE data[4]; + struct {FLOATTYPE _0, _1, _2, _3;} v; + } _v; private: static const FLOATNAME(LVecBase4) _zero; @@ -101,8 +105,8 @@ private: static const FLOATNAME(LVecBase4) _unit_w; public: - INLINE void write_datagram(Datagram &destination) const; - INLINE void read_datagram(DatagramIterator &source); + INLINE_LINMATH void write_datagram(Datagram &destination) const; + INLINE_LINMATH void read_datagram(DatagramIterator &source); public: static TypeHandle get_class_type() { @@ -114,7 +118,7 @@ private: static TypeHandle _type_handle; }; -INLINE ostream &operator << (ostream &out, const FLOATNAME(LVecBase4) &vec) { +INLINE_LINMATH ostream &operator << (ostream &out, const FLOATNAME(LVecBase4) &vec) { vec.output(out); return out; } diff --git a/panda/src/linmath/lvector2_src.I b/panda/src/linmath/lvector2_src.I index 844b089b2e..1f0cdf32dd 100644 --- a/panda/src/linmath/lvector2_src.I +++ b/panda/src/linmath/lvector2_src.I @@ -8,7 +8,7 @@ // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector2):: +INLINE_LINMATH FLOATNAME(LVector2):: FLOATNAME(LVector2)() { } @@ -17,7 +17,7 @@ FLOATNAME(LVector2)() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector2):: +INLINE_LINMATH FLOATNAME(LVector2):: FLOATNAME(LVector2)(const FLOATNAME(LVecBase2) ©) : FLOATNAME(LVecBase2)(copy) { } @@ -26,7 +26,7 @@ FLOATNAME(LVector2)(const FLOATNAME(LVecBase2) ©) : FLOATNAME(LVecBase2)(cop // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector2) &FLOATNAME(LVector2):: +INLINE_LINMATH FLOATNAME(LVector2) &FLOATNAME(LVector2):: operator = (const FLOATNAME(LVecBase2) ©) { FLOATNAME(LVecBase2)::operator = (copy); return *this; @@ -37,7 +37,7 @@ operator = (const FLOATNAME(LVecBase2) ©) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector2) &FLOATNAME(LVector2):: +INLINE_LINMATH FLOATNAME(LVector2) &FLOATNAME(LVector2):: operator = (FLOATTYPE fill_value) { FLOATNAME(LVecBase2)::operator = (fill_value); return *this; @@ -48,7 +48,7 @@ operator = (FLOATTYPE fill_value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector2):: +INLINE_LINMATH FLOATNAME(LVector2):: FLOATNAME(LVector2)(FLOATTYPE fill_value) : FLOATNAME(LVecBase2)(fill_value) { @@ -59,7 +59,7 @@ FLOATNAME(LVector2)(FLOATTYPE fill_value) : // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector2):: +INLINE_LINMATH FLOATNAME(LVector2):: FLOATNAME(LVector2)(FLOATTYPE x, FLOATTYPE y) : FLOATNAME(LVecBase2)(x, y) { @@ -70,7 +70,7 @@ FLOATNAME(LVector2)(FLOATTYPE x, FLOATTYPE y) : // Access: Public // Description: Returns a zero-length vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVector2) &FLOATNAME(LVector2):: +INLINE_LINMATH const FLOATNAME(LVector2) &FLOATNAME(LVector2):: zero() { return (const FLOATNAME(LVector2) &)FLOATNAME(LVecBase2)::zero(); } @@ -80,7 +80,7 @@ zero() { // Access: Public // Description: Returns a unit X vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVector2) &FLOATNAME(LVector2):: +INLINE_LINMATH const FLOATNAME(LVector2) &FLOATNAME(LVector2):: unit_x() { return (const FLOATNAME(LVector2) &)FLOATNAME(LVecBase2)::unit_x(); } @@ -90,7 +90,7 @@ unit_x() { // Access: Public // Description: Returns a unit Y vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVector2) &FLOATNAME(LVector2):: +INLINE_LINMATH const FLOATNAME(LVector2) &FLOATNAME(LVector2):: unit_y() { return (const FLOATNAME(LVector2) &)FLOATNAME(LVecBase2)::unit_y(); } @@ -100,7 +100,7 @@ unit_y() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector2) FLOATNAME(LVector2):: +INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector2):: operator - () const { return FLOATNAME(LVecBase2)::operator - (); } @@ -110,7 +110,7 @@ operator - () const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2) FLOATNAME(LVector2):: +INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVector2):: operator + (const FLOATNAME(LVecBase2) &other) const { return FLOATNAME(LVecBase2)::operator + (other); } @@ -120,7 +120,7 @@ operator + (const FLOATNAME(LVecBase2) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector2) FLOATNAME(LVector2):: +INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector2):: operator + (const FLOATNAME(LVector2) &other) const { return FLOATNAME(LVecBase2)::operator + (other); } @@ -130,7 +130,7 @@ operator + (const FLOATNAME(LVector2) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase2) FLOATNAME(LVector2):: +INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVector2):: operator - (const FLOATNAME(LVecBase2) &other) const { return FLOATNAME(LVecBase2)::operator - (other); } @@ -140,7 +140,7 @@ operator - (const FLOATNAME(LVecBase2) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector2) FLOATNAME(LVector2):: +INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector2):: operator - (const FLOATNAME(LVector2) &other) const { return FLOATNAME(LVecBase2)::operator - (other); } @@ -151,7 +151,7 @@ operator - (const FLOATNAME(LVector2) &other) const { // Description: Returns the length of the vector, by the Pythagorean // theorem. //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVector2):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVector2):: length() const { return csqrt((*this).dot(*this)); } @@ -162,7 +162,7 @@ length() const { // Description: Returns the square of the vector's length, cheap and // easy. //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVector2):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVector2):: length_squared() const { return (*this).dot(*this); } @@ -174,7 +174,7 @@ length_squared() const { // vector was normalized, false if it was a zero-length // vector. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVector2):: +INLINE_LINMATH bool FLOATNAME(LVector2):: normalize() { FLOATTYPE l2 = length_squared(); if (l2 == (FLOATTYPE)0.0) { @@ -193,7 +193,7 @@ normalize() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector2) FLOATNAME(LVector2):: +INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector2):: operator * (FLOATTYPE scalar) const { return FLOATNAME(LVector2)(FLOATNAME(LVecBase2)::operator * (scalar)); } @@ -203,7 +203,8 @@ operator * (FLOATTYPE scalar) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector2) FLOATNAME(LVector2):: +INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector2):: operator / (FLOATTYPE scalar) const { - return FLOATNAME(LVector2)(FLOATNAME(LVecBase2)::operator / (scalar)); + FLOATTYPE recip_scalar = 1.0/scalar; + return FLOATNAME(LVector2)(FLOATNAME(LVecBase2)::operator * (recip_scalar)); } diff --git a/panda/src/linmath/lvector2_src.h b/panda/src/linmath/lvector2_src.h index 556fbc9c76..f35713e2ee 100644 --- a/panda/src/linmath/lvector2_src.h +++ b/panda/src/linmath/lvector2_src.h @@ -9,30 +9,30 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA FLOATNAME(LVector2) : public FLOATNAME(LVecBase2) { PUBLISHED: - INLINE FLOATNAME(LVector2)(); - INLINE FLOATNAME(LVector2)(const FLOATNAME(LVecBase2) ©); - INLINE FLOATNAME(LVector2) &operator = (const FLOATNAME(LVecBase2) ©); - INLINE FLOATNAME(LVector2) &operator = (FLOATTYPE fill_value); - INLINE FLOATNAME(LVector2)(FLOATTYPE fill_value); - INLINE FLOATNAME(LVector2)(FLOATTYPE x, FLOATTYPE y); + INLINE_LINMATH FLOATNAME(LVector2)(); + INLINE_LINMATH FLOATNAME(LVector2)(const FLOATNAME(LVecBase2) ©); + INLINE_LINMATH FLOATNAME(LVector2) &operator = (const FLOATNAME(LVecBase2) ©); + INLINE_LINMATH FLOATNAME(LVector2) &operator = (FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LVector2)(FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LVector2)(FLOATTYPE x, FLOATTYPE y); - INLINE static const FLOATNAME(LVector2) &zero(); - INLINE static const FLOATNAME(LVector2) &unit_x(); - INLINE static const FLOATNAME(LVector2) &unit_y(); + INLINE_LINMATH static const FLOATNAME(LVector2) &zero(); + INLINE_LINMATH static const FLOATNAME(LVector2) &unit_x(); + INLINE_LINMATH static const FLOATNAME(LVector2) &unit_y(); - INLINE FLOATNAME(LVector2) operator - () const; + INLINE_LINMATH FLOATNAME(LVector2) operator - () const; - INLINE FLOATNAME(LVecBase2) operator + (const FLOATNAME(LVecBase2) &other) const; - INLINE FLOATNAME(LVector2) operator + (const FLOATNAME(LVector2) &other) const; + INLINE_LINMATH FLOATNAME(LVecBase2) operator + (const FLOATNAME(LVecBase2) &other) const; + INLINE_LINMATH FLOATNAME(LVector2) operator + (const FLOATNAME(LVector2) &other) const; - INLINE FLOATNAME(LVecBase2) operator - (const FLOATNAME(LVecBase2) &other) const; - INLINE FLOATNAME(LVector2) operator - (const FLOATNAME(LVector2) &other) const; + INLINE_LINMATH FLOATNAME(LVecBase2) operator - (const FLOATNAME(LVecBase2) &other) const; + INLINE_LINMATH FLOATNAME(LVector2) operator - (const FLOATNAME(LVector2) &other) const; - INLINE FLOATTYPE length() const; - INLINE FLOATTYPE length_squared() const; - INLINE bool normalize(); - INLINE FLOATNAME(LVector2) operator * (FLOATTYPE scalar) const; - INLINE FLOATNAME(LVector2) operator / (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATTYPE length() const; + INLINE_LINMATH FLOATTYPE length_squared() const; + INLINE_LINMATH bool normalize(); + INLINE_LINMATH FLOATNAME(LVector2) operator * (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATNAME(LVector2) operator / (FLOATTYPE scalar) const; public: static TypeHandle get_class_type() { diff --git a/panda/src/linmath/lvector3_src.I b/panda/src/linmath/lvector3_src.I index 8356d5625e..98491cf823 100644 --- a/panda/src/linmath/lvector3_src.I +++ b/panda/src/linmath/lvector3_src.I @@ -9,7 +9,7 @@ // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVector3):: FLOATNAME(LVector3)() { } @@ -18,7 +18,7 @@ FLOATNAME(LVector3)() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVector3):: FLOATNAME(LVector3)(const FLOATNAME(LVecBase3) ©) : FLOATNAME(LVecBase3)(copy) { } @@ -27,7 +27,7 @@ FLOATNAME(LVector3)(const FLOATNAME(LVecBase3) ©) : FLOATNAME(LVecBase3)(cop // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) &FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVector3) &FLOATNAME(LVector3):: operator = (const FLOATNAME(LVecBase3) ©) { FLOATNAME(LVecBase3)::operator = (copy); return *this; @@ -38,7 +38,7 @@ operator = (const FLOATNAME(LVecBase3) ©) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) &FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVector3) &FLOATNAME(LVector3):: operator = (FLOATTYPE fill_value) { FLOATNAME(LVecBase3)::operator = (fill_value); return *this; @@ -49,7 +49,7 @@ operator = (FLOATTYPE fill_value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVector3):: FLOATNAME(LVector3)(FLOATTYPE fill_value) : FLOATNAME(LVecBase3)(fill_value) { @@ -60,7 +60,7 @@ FLOATNAME(LVector3)(FLOATTYPE fill_value) : // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVector3):: FLOATNAME(LVector3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) : FLOATNAME(LVecBase3)(x, y, z) { @@ -71,7 +71,7 @@ FLOATNAME(LVector3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) : // Access: Public // Description: Returns a zero-length vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVector3) &FLOATNAME(LVector3):: +INLINE_LINMATH const FLOATNAME(LVector3) &FLOATNAME(LVector3):: zero() { return (const FLOATNAME(LVector3) &)FLOATNAME(LVecBase3)::zero(); } @@ -81,7 +81,7 @@ zero() { // Access: Public // Description: Returns a unit X vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVector3) &FLOATNAME(LVector3):: +INLINE_LINMATH const FLOATNAME(LVector3) &FLOATNAME(LVector3):: unit_x() { return (const FLOATNAME(LVector3) &)FLOATNAME(LVecBase3)::unit_x(); } @@ -91,7 +91,7 @@ unit_x() { // Access: Public // Description: Returns a unit Y vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVector3) &FLOATNAME(LVector3):: +INLINE_LINMATH const FLOATNAME(LVector3) &FLOATNAME(LVector3):: unit_y() { return (const FLOATNAME(LVector3) &)FLOATNAME(LVecBase3)::unit_y(); } @@ -101,7 +101,7 @@ unit_y() { // Access: Public // Description: Returns a unit Z vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVector3) &FLOATNAME(LVector3):: +INLINE_LINMATH const FLOATNAME(LVector3) &FLOATNAME(LVector3):: unit_z() { return (const FLOATNAME(LVector3) &)FLOATNAME(LVecBase3)::unit_z(); } @@ -111,7 +111,7 @@ unit_z() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3):: operator - () const { return FLOATNAME(LVecBase3)::operator - (); } @@ -121,7 +121,7 @@ operator - () const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVector3):: operator + (const FLOATNAME(LVecBase3) &other) const { return FLOATNAME(LVecBase3)::operator + (other); } @@ -131,7 +131,7 @@ operator + (const FLOATNAME(LVecBase3) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3):: operator + (const FLOATNAME(LVector3) &other) const { return FLOATNAME(LVecBase3)::operator + (other); } @@ -141,7 +141,7 @@ operator + (const FLOATNAME(LVector3) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase3) FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVector3):: operator - (const FLOATNAME(LVecBase3) &other) const { return FLOATNAME(LVecBase3)::operator - (other); } @@ -151,7 +151,7 @@ operator - (const FLOATNAME(LVecBase3) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3):: operator - (const FLOATNAME(LVector3) &other) const { return FLOATNAME(LVecBase3)::operator - (other); } @@ -162,7 +162,7 @@ operator - (const FLOATNAME(LVector3) &other) const { // Description: Returns the length of the vector, by the Pythagorean // theorem. //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVector3):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVector3):: length() const { return csqrt((*this).dot(*this)); } @@ -173,7 +173,7 @@ length() const { // Description: Returns the square of the vector's length, cheap and // easy. //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVector3):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVector3):: length_squared() const { return (*this).dot(*this); } @@ -185,7 +185,7 @@ length_squared() const { // vector was normalized, false if it was a zero-length // vector. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVector3):: +INLINE_LINMATH bool FLOATNAME(LVector3):: normalize() { FLOATTYPE l2 = length_squared(); if (l2 == (FLOATTYPE)0.0) { @@ -204,7 +204,7 @@ normalize() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3):: cross(const FLOATNAME(LVecBase3) &other) const { return FLOATNAME(LVecBase3)::cross(other); } @@ -214,7 +214,7 @@ cross(const FLOATNAME(LVecBase3) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3):: operator * (FLOATTYPE scalar) const { return FLOATNAME(LVector3)(FLOATNAME(LVecBase3)::operator * (scalar)); } @@ -224,9 +224,10 @@ operator * (FLOATTYPE scalar) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3):: operator / (FLOATTYPE scalar) const { - return FLOATNAME(LVector3)(FLOATNAME(LVecBase3)::operator / (scalar)); + FLOATTYPE recip_scalar = 1.0/scalar; + return FLOATNAME(LVector3)(FLOATNAME(LVecBase3)::operator * (recip_scalar)); } //////////////////////////////////////////////////////////////////// @@ -235,7 +236,7 @@ operator / (FLOATTYPE scalar) const { // Description: Returns the up vector for the given coordinate // system. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3):: up(CoordinateSystem cs) { if (cs == CS_default) { cs = default_coordinate_system; @@ -262,7 +263,7 @@ up(CoordinateSystem cs) { // Description: Returns the right vector for the given coordinate // system. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3):: right(CoordinateSystem) { return FLOATNAME(LVector3)(1.0, 0.0, 0.0); } @@ -273,7 +274,7 @@ right(CoordinateSystem) { // Description: Returns the forward vector for the given coordinate // system. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3):: forward(CoordinateSystem cs) { if (cs == CS_default) { cs = default_coordinate_system; @@ -304,7 +305,7 @@ forward(CoordinateSystem cs) { // Description: Returns the down vector for the given coordinate // system. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3):: down(CoordinateSystem cs) { return -up(cs); } @@ -315,7 +316,7 @@ down(CoordinateSystem cs) { // Description: Returns the left vector for the given coordinate // system. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3):: left(CoordinateSystem cs) { return -right(cs); } @@ -326,7 +327,7 @@ left(CoordinateSystem cs) { // Description: Returns the back vector for the given coordinate // system. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3):: back(CoordinateSystem cs) { return -forward(cs); } @@ -338,8 +339,42 @@ back(CoordinateSystem cs) { // forward, and up components, in whatever way the // coordinate system represents that vector. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) FLOATNAME(LVector3):: + +//INLINE_LINMATH FLOATNAME(LVector3) & FLOATNAME(LVector3):: +INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3):: rfu(FLOATTYPE right_v, FLOATTYPE fwd_v, FLOATTYPE up_v, CoordinateSystem cs) { - return forward(cs) * fwd_v + up(cs) * up_v + right(cs) * right_v; + + /* return forward(cs) * fwd_v + up(cs) * up_v + right(cs) * right_v; */ + + // fast implementation of above for axis-aligned coordinate systems + + + if (cs == CS_default) { + cs = default_coordinate_system; + } + FLOATTYPE vy,vz; + switch(cs) { + case CS_yup_right: + vz = -fwd_v; + vy = up_v; + break; + + case CS_yup_left: + vz = fwd_v; + vy = up_v; + break; + + case CS_zup_right: + vy = fwd_v; + vz = up_v; + break; + + case CS_zup_left: + vy = -fwd_v; + vz = up_v; + } + + return FLOATNAME(LVector3)(right_v,vy,vz); } + diff --git a/panda/src/linmath/lvector3_src.h b/panda/src/linmath/lvector3_src.h index 770de70156..79e4f27a8f 100644 --- a/panda/src/linmath/lvector3_src.h +++ b/panda/src/linmath/lvector3_src.h @@ -15,47 +15,46 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA FLOATNAME(LVector3) : public FLOATNAME(LVecBase3) { PUBLISHED: - INLINE FLOATNAME(LVector3)(); - INLINE FLOATNAME(LVector3)(const FLOATNAME(LVecBase3) ©); - INLINE FLOATNAME(LVector3) &operator = (const FLOATNAME(LVecBase3) ©); - INLINE FLOATNAME(LVector3) &operator = (FLOATTYPE fill_value); - INLINE FLOATNAME(LVector3)(FLOATTYPE fill_value); - INLINE FLOATNAME(LVector3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z); + INLINE_LINMATH FLOATNAME(LVector3)(); + INLINE_LINMATH FLOATNAME(LVector3)(const FLOATNAME(LVecBase3) ©); + INLINE_LINMATH FLOATNAME(LVector3) &operator = (const FLOATNAME(LVecBase3) ©); + INLINE_LINMATH FLOATNAME(LVector3) &operator = (FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LVector3)(FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LVector3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z); - INLINE static const FLOATNAME(LVector3) &zero(); - INLINE static const FLOATNAME(LVector3) &unit_x(); - INLINE static const FLOATNAME(LVector3) &unit_y(); - INLINE static const FLOATNAME(LVector3) &unit_z(); + INLINE_LINMATH static const FLOATNAME(LVector3) &zero(); + INLINE_LINMATH static const FLOATNAME(LVector3) &unit_x(); + INLINE_LINMATH static const FLOATNAME(LVector3) &unit_y(); + INLINE_LINMATH static const FLOATNAME(LVector3) &unit_z(); - INLINE FLOATNAME(LVector3) operator - () const; + INLINE_LINMATH FLOATNAME(LVector3) operator - () const; - INLINE FLOATNAME(LVecBase3) operator + (const FLOATNAME(LVecBase3) &other) const; - INLINE FLOATNAME(LVector3) operator + (const FLOATNAME(LVector3) &other) const; + INLINE_LINMATH FLOATNAME(LVecBase3) operator + (const FLOATNAME(LVecBase3) &other) const; + INLINE_LINMATH FLOATNAME(LVector3) operator + (const FLOATNAME(LVector3) &other) const; - INLINE FLOATNAME(LVecBase3) operator - (const FLOATNAME(LVecBase3) &other) const; - INLINE FLOATNAME(LVector3) operator - (const FLOATNAME(LVector3) &other) const; + INLINE_LINMATH FLOATNAME(LVecBase3) operator - (const FLOATNAME(LVecBase3) &other) const; + INLINE_LINMATH FLOATNAME(LVector3) operator - (const FLOATNAME(LVector3) &other) const; - INLINE FLOATTYPE length() const; - INLINE FLOATTYPE length_squared() const; - INLINE bool normalize(); - INLINE FLOATNAME(LVector3) cross(const FLOATNAME(LVecBase3) &other) const; - INLINE FLOATNAME(LVector3) operator * (FLOATTYPE scalar) const; - INLINE FLOATNAME(LVector3) operator / (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATTYPE length() const; + INLINE_LINMATH FLOATTYPE length_squared() const; + INLINE_LINMATH bool normalize(); + INLINE_LINMATH FLOATNAME(LVector3) cross(const FLOATNAME(LVecBase3) &other) const; + INLINE_LINMATH FLOATNAME(LVector3) operator * (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATNAME(LVector3) operator / (FLOATTYPE scalar) const; // Some special named constructors for LVector3. - INLINE static FLOATNAME(LVector3) up(CoordinateSystem cs = CS_default); - INLINE static FLOATNAME(LVector3) right(CoordinateSystem cs = CS_default); - INLINE static FLOATNAME(LVector3) forward(CoordinateSystem cs = CS_default); + INLINE_LINMATH static FLOATNAME(LVector3) up(CoordinateSystem cs = CS_default); + INLINE_LINMATH static FLOATNAME(LVector3) right(CoordinateSystem cs = CS_default); + INLINE_LINMATH static FLOATNAME(LVector3) forward(CoordinateSystem cs = CS_default); - INLINE static FLOATNAME(LVector3) down(CoordinateSystem cs = CS_default); - INLINE static FLOATNAME(LVector3) left(CoordinateSystem cs = CS_default); - INLINE static FLOATNAME(LVector3) back(CoordinateSystem cs = CS_default); + INLINE_LINMATH static FLOATNAME(LVector3) down(CoordinateSystem cs = CS_default); + INLINE_LINMATH static FLOATNAME(LVector3) left(CoordinateSystem cs = CS_default); + INLINE_LINMATH static FLOATNAME(LVector3) back(CoordinateSystem cs = CS_default); - INLINE static FLOATNAME(LVector3) rfu(FLOATTYPE right, - FLOATTYPE fwd, - FLOATTYPE up, - CoordinateSystem cs = CS_default); +// INLINE_LINMATH static FLOATNAME(LVector3) & rfu(FLOATTYPE right, + INLINE_LINMATH static FLOATNAME(LVector3) rfu(FLOATTYPE right, + FLOATTYPE fwd,FLOATTYPE up, CoordinateSystem cs = CS_default); public: static TypeHandle get_class_type() { diff --git a/panda/src/linmath/lvector4_src.I b/panda/src/linmath/lvector4_src.I index 6e2f92020b..9a4412ffc6 100644 --- a/panda/src/linmath/lvector4_src.I +++ b/panda/src/linmath/lvector4_src.I @@ -9,7 +9,7 @@ // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector4):: +INLINE_LINMATH FLOATNAME(LVector4):: FLOATNAME(LVector4)() { } @@ -18,7 +18,7 @@ FLOATNAME(LVector4)() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector4):: +INLINE_LINMATH FLOATNAME(LVector4):: FLOATNAME(LVector4)(const FLOATNAME(LVecBase4) ©) : FLOATNAME(LVecBase4)(copy) { } @@ -27,7 +27,7 @@ FLOATNAME(LVector4)(const FLOATNAME(LVecBase4) ©) : FLOATNAME(LVecBase4)(cop // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector4) &FLOATNAME(LVector4):: +INLINE_LINMATH FLOATNAME(LVector4) &FLOATNAME(LVector4):: operator = (const FLOATNAME(LVecBase4) ©) { FLOATNAME(LVecBase4)::operator = (copy); return *this; @@ -38,7 +38,7 @@ operator = (const FLOATNAME(LVecBase4) ©) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector4) &FLOATNAME(LVector4):: +INLINE_LINMATH FLOATNAME(LVector4) &FLOATNAME(LVector4):: operator = (FLOATTYPE fill_value) { FLOATNAME(LVecBase4)::operator = (fill_value); return *this; @@ -49,7 +49,7 @@ operator = (FLOATTYPE fill_value) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector4):: +INLINE_LINMATH FLOATNAME(LVector4):: FLOATNAME(LVector4)(FLOATTYPE fill_value) : FLOATNAME(LVecBase4)(fill_value) { @@ -60,7 +60,7 @@ FLOATNAME(LVector4)(FLOATTYPE fill_value) : // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector4):: +INLINE_LINMATH FLOATNAME(LVector4):: FLOATNAME(LVector4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w) : FLOATNAME(LVecBase4)(x, y, z, w) { @@ -71,7 +71,7 @@ FLOATNAME(LVector4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w) : // Access: Public // Description: Returns a zero-length vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVector4) &FLOATNAME(LVector4):: +INLINE_LINMATH const FLOATNAME(LVector4) &FLOATNAME(LVector4):: zero() { return (const FLOATNAME(LVector4) &)FLOATNAME(LVecBase4)::zero(); } @@ -81,7 +81,7 @@ zero() { // Access: Public // Description: Returns a unit X vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVector4) &FLOATNAME(LVector4):: +INLINE_LINMATH const FLOATNAME(LVector4) &FLOATNAME(LVector4):: unit_x() { return (const FLOATNAME(LVector4) &)FLOATNAME(LVecBase4)::unit_x(); } @@ -91,7 +91,7 @@ unit_x() { // Access: Public // Description: Returns a unit Y vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVector4) &FLOATNAME(LVector4):: +INLINE_LINMATH const FLOATNAME(LVector4) &FLOATNAME(LVector4):: unit_y() { return (const FLOATNAME(LVector4) &)FLOATNAME(LVecBase4)::unit_y(); } @@ -101,7 +101,7 @@ unit_y() { // Access: Public // Description: Returns a unit Z vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVector4) &FLOATNAME(LVector4):: +INLINE_LINMATH const FLOATNAME(LVector4) &FLOATNAME(LVector4):: unit_z() { return (const FLOATNAME(LVector4) &)FLOATNAME(LVecBase4)::unit_z(); } @@ -111,7 +111,7 @@ unit_z() { // Access: Public // Description: Returns a unit W vector. //////////////////////////////////////////////////////////////////// -INLINE const FLOATNAME(LVector4) &FLOATNAME(LVector4):: +INLINE_LINMATH const FLOATNAME(LVector4) &FLOATNAME(LVector4):: unit_w() { return (const FLOATNAME(LVector4) &)FLOATNAME(LVecBase4)::unit_w(); } @@ -121,7 +121,7 @@ unit_w() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector4) FLOATNAME(LVector4):: +INLINE_LINMATH FLOATNAME(LVector4) FLOATNAME(LVector4):: operator - () const { return FLOATNAME(LVecBase4)::operator - (); } @@ -131,7 +131,7 @@ operator - () const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4) FLOATNAME(LVector4):: +INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVector4):: operator + (const FLOATNAME(LVecBase4) &other) const { return FLOATNAME(LVecBase4)::operator + (other); } @@ -141,7 +141,7 @@ operator + (const FLOATNAME(LVecBase4) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector4) FLOATNAME(LVector4):: +INLINE_LINMATH FLOATNAME(LVector4) FLOATNAME(LVector4):: operator + (const FLOATNAME(LVector4) &other) const { return FLOATNAME(LVecBase4)::operator + (other); } @@ -151,7 +151,7 @@ operator + (const FLOATNAME(LVector4) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVecBase4) FLOATNAME(LVector4):: +INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVector4):: operator - (const FLOATNAME(LVecBase4) &other) const { return FLOATNAME(LVecBase4)::operator - (other); } @@ -161,7 +161,7 @@ operator - (const FLOATNAME(LVecBase4) &other) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector4) FLOATNAME(LVector4):: +INLINE_LINMATH FLOATNAME(LVector4) FLOATNAME(LVector4):: operator - (const FLOATNAME(LVector4) &other) const { return FLOATNAME(LVecBase4)::operator - (other); } @@ -172,7 +172,7 @@ operator - (const FLOATNAME(LVector4) &other) const { // Description: Returns the length of the vector, by the Pythagorean // theorem. //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVector4):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVector4):: length() const { return csqrt((*this).dot(*this)); } @@ -183,7 +183,7 @@ length() const { // Description: Returns the square of the vector's length, cheap and // easy. //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(LVector4):: +INLINE_LINMATH FLOATTYPE FLOATNAME(LVector4):: length_squared() const { return (*this).dot(*this); } @@ -195,7 +195,7 @@ length_squared() const { // vector was normalized, false if it was a zero-length // vector. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(LVector4):: +INLINE_LINMATH bool FLOATNAME(LVector4):: normalize() { FLOATTYPE l2 = length_squared(); if (l2 == (FLOATTYPE)0.0) { @@ -214,7 +214,7 @@ normalize() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector4) FLOATNAME(LVector4):: +INLINE_LINMATH FLOATNAME(LVector4) FLOATNAME(LVector4):: operator * (FLOATTYPE scalar) const { return FLOATNAME(LVector4)(FLOATNAME(LVecBase4)::operator * (scalar)); } @@ -224,7 +224,8 @@ operator * (FLOATTYPE scalar) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector4) FLOATNAME(LVector4):: +INLINE_LINMATH FLOATNAME(LVector4) FLOATNAME(LVector4):: operator / (FLOATTYPE scalar) const { - return FLOATNAME(LVector4)(FLOATNAME(LVecBase4)::operator / (scalar)); + FLOATTYPE recip_scalar = 1.0/scalar; + return FLOATNAME(LVector4)(FLOATNAME(LVecBase4)::operator * (recip_scalar)); } diff --git a/panda/src/linmath/lvector4_src.h b/panda/src/linmath/lvector4_src.h index 267181d2c6..f9d6addce7 100644 --- a/panda/src/linmath/lvector4_src.h +++ b/panda/src/linmath/lvector4_src.h @@ -9,32 +9,32 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA FLOATNAME(LVector4) : public FLOATNAME(LVecBase4) { PUBLISHED: - INLINE FLOATNAME(LVector4)(); - INLINE FLOATNAME(LVector4)(const FLOATNAME(LVecBase4) ©); - INLINE FLOATNAME(LVector4) &operator = (const FLOATNAME(LVecBase4) ©); - INLINE FLOATNAME(LVector4) &operator = (FLOATTYPE fill_value); - INLINE FLOATNAME(LVector4)(FLOATTYPE fill_value); - INLINE FLOATNAME(LVector4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); + INLINE_LINMATH FLOATNAME(LVector4)(); + INLINE_LINMATH FLOATNAME(LVector4)(const FLOATNAME(LVecBase4) ©); + INLINE_LINMATH FLOATNAME(LVector4) &operator = (const FLOATNAME(LVecBase4) ©); + INLINE_LINMATH FLOATNAME(LVector4) &operator = (FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LVector4)(FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LVector4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); - INLINE static const FLOATNAME(LVector4) &zero(); - INLINE static const FLOATNAME(LVector4) &unit_x(); - INLINE static const FLOATNAME(LVector4) &unit_y(); - INLINE static const FLOATNAME(LVector4) &unit_z(); - INLINE static const FLOATNAME(LVector4) &unit_w(); + INLINE_LINMATH static const FLOATNAME(LVector4) &zero(); + INLINE_LINMATH static const FLOATNAME(LVector4) &unit_x(); + INLINE_LINMATH static const FLOATNAME(LVector4) &unit_y(); + INLINE_LINMATH static const FLOATNAME(LVector4) &unit_z(); + INLINE_LINMATH static const FLOATNAME(LVector4) &unit_w(); - INLINE FLOATNAME(LVector4) operator - () const; + INLINE_LINMATH FLOATNAME(LVector4) operator - () const; - INLINE FLOATNAME(LVecBase4) operator + (const FLOATNAME(LVecBase4) &other) const; - INLINE FLOATNAME(LVector4) operator + (const FLOATNAME(LVector4) &other) const; + INLINE_LINMATH FLOATNAME(LVecBase4) operator + (const FLOATNAME(LVecBase4) &other) const; + INLINE_LINMATH FLOATNAME(LVector4) operator + (const FLOATNAME(LVector4) &other) const; - INLINE FLOATNAME(LVecBase4) operator - (const FLOATNAME(LVecBase4) &other) const; - INLINE FLOATNAME(LVector4) operator - (const FLOATNAME(LVector4) &other) const; + INLINE_LINMATH FLOATNAME(LVecBase4) operator - (const FLOATNAME(LVecBase4) &other) const; + INLINE_LINMATH FLOATNAME(LVector4) operator - (const FLOATNAME(LVector4) &other) const; - INLINE FLOATTYPE length() const; - INLINE FLOATTYPE length_squared() const; - INLINE bool normalize(); - INLINE FLOATNAME(LVector4) operator * (FLOATTYPE scalar) const; - INLINE FLOATNAME(LVector4) operator / (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATTYPE length() const; + INLINE_LINMATH FLOATTYPE length_squared() const; + INLINE_LINMATH bool normalize(); + INLINE_LINMATH FLOATNAME(LVector4) operator * (FLOATTYPE scalar) const; + INLINE_LINMATH FLOATNAME(LVector4) operator / (FLOATTYPE scalar) const; public: static TypeHandle get_class_type() { diff --git a/panda/src/linmath/nearly_zero.h b/panda/src/linmath/nearly_zero.h index 5e1472e4bc..a4d3b3aef1 100644 --- a/panda/src/linmath/nearly_zero.h +++ b/panda/src/linmath/nearly_zero.h @@ -10,12 +10,12 @@ // The following two functions are defined just to make the // NEARLY_ZERO() macro work. They each return a suitable nearly-zero // value for their corresponding numeric type. -INLINE double +INLINE_LINMATH double get_nearly_zero_value(double) { return 1.0e-12; } -INLINE float +INLINE_LINMATH float get_nearly_zero_value(float) { return 1.0e-6f; } diff --git a/panda/src/mathutil/boundingHexahedron.I b/panda/src/mathutil/boundingHexahedron.I index 6a2069bfac..0ddeae5722 100644 --- a/panda/src/mathutil/boundingHexahedron.I +++ b/panda/src/mathutil/boundingHexahedron.I @@ -3,27 +3,27 @@ // //////////////////////////////////////////////////////////////////// -INLINE BoundingHexahedron:: +INLINE_MATHUTIL BoundingHexahedron:: BoundingHexahedron() { } -INLINE int BoundingHexahedron:: +INLINE_MATHUTIL int BoundingHexahedron:: get_num_points() const { return num_points; } -INLINE LPoint3f BoundingHexahedron:: +INLINE_MATHUTIL LPoint3f BoundingHexahedron:: get_point(int n) const { nassertr(n >= 0 && n < num_points, LPoint3f(0.0, 0.0, 0.0)); return _points[n]; } -INLINE int BoundingHexahedron:: +INLINE_MATHUTIL int BoundingHexahedron:: get_num_planes() const { return num_planes; } -INLINE Planef BoundingHexahedron:: +INLINE_MATHUTIL Planef BoundingHexahedron:: get_plane(int n) const { nassertr(n >= 0 && n < num_planes, Planef()); return _planes[n]; diff --git a/panda/src/mathutil/boundingHexahedron.h b/panda/src/mathutil/boundingHexahedron.h index 88a695337f..0a2a7faaec 100644 --- a/panda/src/mathutil/boundingHexahedron.h +++ b/panda/src/mathutil/boundingHexahedron.h @@ -27,7 +27,7 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA BoundingHexahedron : public FiniteBoundingVolume { public: - INLINE BoundingHexahedron(); + INLINE_MATHUTIL BoundingHexahedron(); BoundingHexahedron(const Frustumf &frustum, bool is_ortho, CoordinateSystem cs = CS_default); virtual BoundingVolume *make_copy() const; @@ -41,10 +41,10 @@ public: virtual void output(ostream &out) const; virtual void write(ostream &out, int indent_level = 0) const; - INLINE int get_num_points() const; - INLINE LPoint3f get_point(int n) const; - INLINE int get_num_planes() const; - INLINE Planef get_plane(int n) const; + INLINE_MATHUTIL int get_num_points() const; + INLINE_MATHUTIL LPoint3f get_point(int n) const; + INLINE_MATHUTIL int get_num_planes() const; + INLINE_MATHUTIL Planef get_plane(int n) const; protected: virtual bool extend_other(BoundingVolume *other) const; diff --git a/panda/src/mathutil/boundingLine.I b/panda/src/mathutil/boundingLine.I index 9ef228ecc9..0127a32dc1 100644 --- a/panda/src/mathutil/boundingLine.I +++ b/panda/src/mathutil/boundingLine.I @@ -3,11 +3,11 @@ // //////////////////////////////////////////////////////////////////// -INLINE BoundingLine:: +INLINE_MATHUTIL BoundingLine:: BoundingLine() { } -INLINE BoundingLine:: +INLINE_MATHUTIL BoundingLine:: BoundingLine(const LPoint3f &a, const LPoint3f &b) : _origin(a), _vector(b - a) { @@ -18,14 +18,14 @@ BoundingLine(const LPoint3f &a, const LPoint3f &b) : } } -INLINE const LPoint3f &BoundingLine:: +INLINE_MATHUTIL const LPoint3f &BoundingLine:: get_point_a() const { nassertr(!is_empty(), _origin); nassertr(!is_infinite(), _origin); return _origin; } -INLINE LPoint3f BoundingLine:: +INLINE_MATHUTIL LPoint3f BoundingLine:: get_point_b() const { nassertr(!is_empty(), _origin); nassertr(!is_infinite(), _origin); diff --git a/panda/src/mathutil/boundingLine.h b/panda/src/mathutil/boundingLine.h index 46d409e3e5..ab848fff6c 100644 --- a/panda/src/mathutil/boundingLine.h +++ b/panda/src/mathutil/boundingLine.h @@ -23,8 +23,8 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA BoundingLine : public GeometricBoundingVolume { PUBLISHED: - INLINE BoundingLine(); - INLINE BoundingLine(const LPoint3f &a, const LPoint3f &b); + INLINE_MATHUTIL BoundingLine(); + INLINE_MATHUTIL BoundingLine(const LPoint3f &a, const LPoint3f &b); public: virtual BoundingVolume *make_copy() const; @@ -35,8 +35,8 @@ public: virtual void output(ostream &out) const; PUBLISHED: - INLINE const LPoint3f &get_point_a() const; - INLINE LPoint3f get_point_b() const; + INLINE_MATHUTIL const LPoint3f &get_point_a() const; + INLINE_MATHUTIL LPoint3f get_point_b() const; protected: virtual bool extend_other(BoundingVolume *other) const; diff --git a/panda/src/mathutil/boundingSphere.I b/panda/src/mathutil/boundingSphere.I index 40a20580b5..43fb3813a0 100644 --- a/panda/src/mathutil/boundingSphere.I +++ b/panda/src/mathutil/boundingSphere.I @@ -3,11 +3,11 @@ // //////////////////////////////////////////////////////////////////// -INLINE BoundingSphere:: +INLINE_MATHUTIL BoundingSphere:: BoundingSphere() { } -INLINE BoundingSphere:: +INLINE_MATHUTIL BoundingSphere:: BoundingSphere(const LPoint3f ¢er, float radius) : _center(center), _radius(radius) { @@ -17,14 +17,14 @@ BoundingSphere(const LPoint3f ¢er, float radius) : } } -INLINE const LPoint3f &BoundingSphere:: +INLINE_MATHUTIL const LPoint3f &BoundingSphere:: get_center() const { nassertr(!is_empty(), _center); nassertr(!is_infinite(), _center); return _center; } -INLINE float BoundingSphere:: +INLINE_MATHUTIL float BoundingSphere:: get_radius() const { nassertr(!is_empty(), 0.0); nassertr(!is_infinite(), 0.0); diff --git a/panda/src/mathutil/boundingSphere.h b/panda/src/mathutil/boundingSphere.h index b9fe6be1b3..c400aa59f1 100644 --- a/panda/src/mathutil/boundingSphere.h +++ b/panda/src/mathutil/boundingSphere.h @@ -18,8 +18,8 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA BoundingSphere : public FiniteBoundingVolume { PUBLISHED: - INLINE BoundingSphere(); - INLINE BoundingSphere(const LPoint3f ¢er, float radius); + INLINE_MATHUTIL BoundingSphere(); + INLINE_MATHUTIL BoundingSphere(const LPoint3f ¢er, float radius); public: virtual BoundingVolume *make_copy() const; @@ -33,8 +33,8 @@ public: virtual void output(ostream &out) const; PUBLISHED: - INLINE const LPoint3f &get_center() const; - INLINE float get_radius() const; + INLINE_MATHUTIL const LPoint3f &get_center() const; + INLINE_MATHUTIL float get_radius() const; protected: virtual bool extend_other(BoundingVolume *other) const; diff --git a/panda/src/mathutil/boundingVolume.I b/panda/src/mathutil/boundingVolume.I index 9f6a497184..f751cb0d54 100644 --- a/panda/src/mathutil/boundingVolume.I +++ b/panda/src/mathutil/boundingVolume.I @@ -8,7 +8,7 @@ // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE BoundingVolume:: +INLINE_MATHUTIL BoundingVolume:: BoundingVolume() { _flags = F_empty; } @@ -22,7 +22,7 @@ BoundingVolume() { // since that contains one point (the center). It // intersects with no other volumes. //////////////////////////////////////////////////////////////////// -INLINE bool BoundingVolume:: +INLINE_MATHUTIL bool BoundingVolume:: is_empty() const { return (_flags & F_empty) != 0; } @@ -43,7 +43,7 @@ is_empty() const { // It completely intersects with all other volumes // except empty volumes. //////////////////////////////////////////////////////////////////// -INLINE bool BoundingVolume:: +INLINE_MATHUTIL bool BoundingVolume:: is_infinite() const { return (_flags & F_infinite) != 0; } @@ -55,7 +55,7 @@ is_infinite() const { // finite. You can think of this as an infinite // extend_by() operation. //////////////////////////////////////////////////////////////////// -INLINE void BoundingVolume:: +INLINE_MATHUTIL void BoundingVolume:: set_infinite() { _flags = F_infinite; } @@ -66,7 +66,7 @@ set_infinite() { // Description: Increases the size of the volume to include the given // volume. //////////////////////////////////////////////////////////////////// -INLINE bool BoundingVolume:: +INLINE_MATHUTIL bool BoundingVolume:: extend_by(const BoundingVolume *vol) { if (vol->is_infinite()) { set_infinite(); @@ -88,7 +88,7 @@ extend_by(const BoundingVolume *vol) { // indicate the amount of intersection with the // indicated volume. //////////////////////////////////////////////////////////////////// -INLINE int BoundingVolume:: +INLINE_MATHUTIL int BoundingVolume:: contains(const BoundingVolume *vol) const { if (is_empty() || vol->is_empty()) { return IF_no_intersection; @@ -106,7 +106,7 @@ contains(const BoundingVolume *vol) const { return vol->contains_other(this); } -INLINE ostream &operator << (ostream &out, const BoundingVolume &bound) { +INLINE_MATHUTIL ostream &operator << (ostream &out, const BoundingVolume &bound) { bound.output(out); return out; } diff --git a/panda/src/mathutil/boundingVolume.h b/panda/src/mathutil/boundingVolume.h index 8291ac6d37..22700542cb 100644 --- a/panda/src/mathutil/boundingVolume.h +++ b/panda/src/mathutil/boundingVolume.h @@ -28,15 +28,15 @@ class BoundingLine; //////////////////////////////////////////////////////////////////// class EXPCL_PANDA BoundingVolume : public TypedReferenceCount { PUBLISHED: - INLINE BoundingVolume(); + INLINE_MATHUTIL BoundingVolume(); virtual BoundingVolume *make_copy() const=0; - INLINE bool is_empty() const; - INLINE bool is_infinite() const; + INLINE_MATHUTIL bool is_empty() const; + INLINE_MATHUTIL bool is_infinite() const; - INLINE void set_infinite(); + INLINE_MATHUTIL void set_infinite(); - INLINE bool extend_by(const BoundingVolume *vol); + INLINE_MATHUTIL bool extend_by(const BoundingVolume *vol); // It might be nice to make these template member functions so we // could have true STL-style first/last iterators, but that's @@ -76,7 +76,7 @@ PUBLISHED: IF_dont_understand = 0x08 }; - INLINE int contains(const BoundingVolume *vol) const; + INLINE_MATHUTIL int contains(const BoundingVolume *vol) const; virtual void output(ostream &out) const=0; virtual void write(ostream &out, int indent_level = 0) const; @@ -140,7 +140,7 @@ private: friend class BoundingLine; }; -INLINE ostream &operator << (ostream &out, const BoundingVolume &bound); +INLINE_MATHUTIL ostream &operator << (ostream &out, const BoundingVolume &bound); #include "boundingVolume.I" diff --git a/panda/src/mathutil/frustum_src.I b/panda/src/mathutil/frustum_src.I index 042934aae6..463053f667 100644 --- a/panda/src/mathutil/frustum_src.I +++ b/panda/src/mathutil/frustum_src.I @@ -8,7 +8,7 @@ // Access: // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(Frustum):: +INLINE_MATHUTIL FLOATNAME(Frustum):: FLOATNAME(Frustum)() { _fnear = 1.4142; _ffar = 10.0; @@ -23,7 +23,7 @@ FLOATNAME(Frustum)() { // Access: // Description: Sets up a two-dimensional orthographic frustum //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(Frustum)::make_ortho_2D(void) { +INLINE_MATHUTIL void FLOATNAME(Frustum)::make_ortho_2D(void) { make_ortho(-1, 1); } @@ -32,7 +32,7 @@ INLINE void FLOATNAME(Frustum)::make_ortho_2D(void) { // Access: // Description: Sets up a two-dimensional orthographic frustum //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(Frustum):: +INLINE_MATHUTIL void FLOATNAME(Frustum):: make_ortho_2D(FLOATTYPE l, FLOATTYPE r, FLOATTYPE t, FLOATTYPE b) { make_ortho(-1, 1, l, r, t, b); } @@ -42,7 +42,7 @@ make_ortho_2D(FLOATTYPE l, FLOATTYPE r, FLOATTYPE t, FLOATTYPE b) { // Access: // Description: Behaves like gluOrtho //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(Frustum)::make_ortho(FLOATTYPE fnear, FLOATTYPE ffar) { +INLINE_MATHUTIL void FLOATNAME(Frustum)::make_ortho(FLOATTYPE fnear, FLOATTYPE ffar) { _fnear = fnear; _ffar = ffar; _l = -1; @@ -56,7 +56,7 @@ INLINE void FLOATNAME(Frustum)::make_ortho(FLOATTYPE fnear, FLOATTYPE ffar) { // Access: // Description: Behaves like gluOrtho //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(Frustum):: +INLINE_MATHUTIL void FLOATNAME(Frustum):: make_ortho(FLOATTYPE fnear, FLOATTYPE ffar, FLOATTYPE l, FLOATTYPE r, FLOATTYPE t, FLOATTYPE b) { _fnear = fnear; @@ -89,7 +89,7 @@ make_ortho(FLOATTYPE fnear, FLOATTYPE ffar, FLOATTYPE l, FLOATTYPE r, // W yfov // //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(Frustum):: +INLINE_MATHUTIL void FLOATNAME(Frustum):: make_perspective_hfov(FLOATTYPE hfov, FLOATTYPE aspect, FLOATTYPE fnear, FLOATTYPE ffar) { _fnear = fnear; @@ -101,7 +101,7 @@ make_perspective_hfov(FLOATTYPE hfov, FLOATTYPE aspect, FLOATTYPE fnear, } -INLINE void FLOATNAME(Frustum):: +INLINE_MATHUTIL void FLOATNAME(Frustum):: make_perspective_vfov(FLOATTYPE yfov, FLOATTYPE aspect, FLOATTYPE fnear, FLOATTYPE ffar) { _fnear = fnear; @@ -113,7 +113,7 @@ make_perspective_vfov(FLOATTYPE yfov, FLOATTYPE aspect, FLOATTYPE fnear, } -INLINE void FLOATNAME(Frustum):: +INLINE_MATHUTIL void FLOATNAME(Frustum):: make_perspective(FLOATTYPE xfov, FLOATTYPE yfov, FLOATTYPE fnear, FLOATTYPE ffar) { _fnear = fnear; @@ -129,7 +129,7 @@ make_perspective(FLOATTYPE xfov, FLOATTYPE yfov, FLOATTYPE fnear, // Access: // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(Frustum):: +INLINE_MATHUTIL void FLOATNAME(Frustum):: get_perspective_params(FLOATTYPE& yfov, FLOATTYPE& aspect, FLOATTYPE& fnear, FLOATTYPE& ffar) const { yfov = rad_2_deg(atan(_t / _fnear)) * 2.0; @@ -143,7 +143,7 @@ get_perspective_params(FLOATTYPE& yfov, FLOATTYPE& aspect, // Access: // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(Frustum):: +INLINE_MATHUTIL void FLOATNAME(Frustum):: get_perspective_params(FLOATTYPE& xfov, FLOATTYPE& yfov, FLOATTYPE& aspect, FLOATTYPE& fnear, FLOATTYPE& ffar) const { xfov = rad_2_deg(atan(_r / _fnear)) * 2.0; @@ -157,7 +157,7 @@ get_perspective_params(FLOATTYPE& xfov, FLOATTYPE& yfov, FLOATTYPE& aspect, // perspective transform defined by the frustum, // accordinate to the indicated coordinate system. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) FLOATNAME(Frustum):: +INLINE_MATHUTIL FLOATNAME(LMatrix4) FLOATNAME(Frustum):: get_perspective_projection_mat(CoordinateSystem cs) const { if (cs == CS_default) { cs = default_coordinate_system; @@ -205,7 +205,7 @@ get_perspective_projection_mat(CoordinateSystem cs) const { // orthographic transform defined by the frustum, // accordinate to the indicated coordinate system. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix4) FLOATNAME(Frustum):: +INLINE_MATHUTIL FLOATNAME(LMatrix4) FLOATNAME(Frustum):: get_ortho_projection_mat(CoordinateSystem cs) const { if (cs == CS_default) { cs = default_coordinate_system; diff --git a/panda/src/mathutil/frustum_src.h b/panda/src/mathutil/frustum_src.h index 074dfc30d2..a929badd0e 100644 --- a/panda/src/mathutil/frustum_src.h +++ b/panda/src/mathutil/frustum_src.h @@ -9,32 +9,32 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA FLOATNAME(Frustum) { PUBLISHED: - INLINE FLOATNAME(Frustum)(); + INLINE_MATHUTIL FLOATNAME(Frustum)(); - INLINE void make_ortho_2D(void); - INLINE void make_ortho_2D(FLOATTYPE l, FLOATTYPE r, FLOATTYPE t, FLOATTYPE b); + INLINE_MATHUTIL void make_ortho_2D(void); + INLINE_MATHUTIL void make_ortho_2D(FLOATTYPE l, FLOATTYPE r, FLOATTYPE t, FLOATTYPE b); - INLINE void make_ortho(FLOATTYPE fnear, FLOATTYPE ffar); - INLINE void make_ortho(FLOATTYPE fnear, FLOATTYPE ffar, + INLINE_MATHUTIL void make_ortho(FLOATTYPE fnear, FLOATTYPE ffar); + INLINE_MATHUTIL void make_ortho(FLOATTYPE fnear, FLOATTYPE ffar, FLOATTYPE l, FLOATTYPE r, FLOATTYPE t, FLOATTYPE b); - INLINE void make_perspective_hfov(FLOATTYPE xfov, FLOATTYPE aspect, + INLINE_MATHUTIL void make_perspective_hfov(FLOATTYPE xfov, FLOATTYPE aspect, FLOATTYPE fnear, FLOATTYPE ffar); - INLINE void make_perspective_vfov(FLOATTYPE yfov, FLOATTYPE aspect, + INLINE_MATHUTIL void make_perspective_vfov(FLOATTYPE yfov, FLOATTYPE aspect, FLOATTYPE fnear, FLOATTYPE ffar); - INLINE void make_perspective(FLOATTYPE xfov, FLOATTYPE yfov, FLOATTYPE fnear, + INLINE_MATHUTIL void make_perspective(FLOATTYPE xfov, FLOATTYPE yfov, FLOATTYPE fnear, FLOATTYPE ffar); - INLINE void get_perspective_params(FLOATTYPE &yfov, FLOATTYPE &aspect, + INLINE_MATHUTIL void get_perspective_params(FLOATTYPE &yfov, FLOATTYPE &aspect, FLOATTYPE &fnear, FLOATTYPE &ffar) const; - INLINE void get_perspective_params(FLOATTYPE &xfov, FLOATTYPE &yfov, + INLINE_MATHUTIL void get_perspective_params(FLOATTYPE &xfov, FLOATTYPE &yfov, FLOATTYPE &aspect, FLOATTYPE &fnear, FLOATTYPE &ffar) const; public: - INLINE FLOATNAME(LMatrix4) + INLINE_MATHUTIL FLOATNAME(LMatrix4) get_perspective_projection_mat(CoordinateSystem cs = CS_default) const; - INLINE FLOATNAME(LMatrix4) + INLINE_MATHUTIL FLOATNAME(LMatrix4) get_ortho_projection_mat(CoordinateSystem cs = CS_default) const; public: diff --git a/panda/src/mathutil/geometricBoundingVolume.I b/panda/src/mathutil/geometricBoundingVolume.I index 253c64d7e6..729552330e 100644 --- a/panda/src/mathutil/geometricBoundingVolume.I +++ b/panda/src/mathutil/geometricBoundingVolume.I @@ -8,7 +8,7 @@ // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE GeometricBoundingVolume:: +INLINE_MATHUTIL GeometricBoundingVolume:: GeometricBoundingVolume() { } @@ -18,7 +18,7 @@ GeometricBoundingVolume() { // Description: Increases the size of the volume to include the given // volume. //////////////////////////////////////////////////////////////////// -INLINE bool GeometricBoundingVolume:: +INLINE_MATHUTIL bool GeometricBoundingVolume:: extend_by(const GeometricBoundingVolume *vol) { return BoundingVolume::extend_by(vol); } @@ -29,7 +29,7 @@ extend_by(const GeometricBoundingVolume *vol) { // Description: Increases the size of the volume to include the given // point. //////////////////////////////////////////////////////////////////// -INLINE bool GeometricBoundingVolume:: +INLINE_MATHUTIL bool GeometricBoundingVolume:: extend_by(const LPoint3f &point) { return extend_by_point(point); } @@ -40,7 +40,7 @@ extend_by(const LPoint3f &point) { // Description: Resets the volume to enclose only the volumes // indicated. //////////////////////////////////////////////////////////////////// -INLINE bool GeometricBoundingVolume:: +INLINE_MATHUTIL bool GeometricBoundingVolume:: around(const GeometricBoundingVolume **first, const GeometricBoundingVolume **last) { return BoundingVolume::around((const BoundingVolume **)first, @@ -53,7 +53,7 @@ around(const GeometricBoundingVolume **first, // Description: Resets the volume to enclose only the points // indicated. //////////////////////////////////////////////////////////////////// -INLINE bool GeometricBoundingVolume:: +INLINE_MATHUTIL bool GeometricBoundingVolume:: around(const LPoint3f *first, const LPoint3f *last) { _flags = F_empty; if (first != last) { @@ -70,7 +70,7 @@ around(const LPoint3f *first, const LPoint3f *last) { // indicate the amount of intersection with the // indicated volume. //////////////////////////////////////////////////////////////////// -INLINE int GeometricBoundingVolume:: +INLINE_MATHUTIL int GeometricBoundingVolume:: contains(const GeometricBoundingVolume *vol) const { return BoundingVolume::contains(vol); } @@ -82,7 +82,7 @@ contains(const GeometricBoundingVolume *vol) const { // indicate the amount of intersection with the // indicated point. //////////////////////////////////////////////////////////////////// -INLINE int GeometricBoundingVolume:: +INLINE_MATHUTIL int GeometricBoundingVolume:: contains(const LPoint3f &point) const { if (is_empty()) { return IF_no_intersection; @@ -98,7 +98,7 @@ contains(const LPoint3f &point) const { // indicate the amount of intersection with the // indicated line segment. //////////////////////////////////////////////////////////////////// -INLINE int GeometricBoundingVolume:: +INLINE_MATHUTIL int GeometricBoundingVolume:: contains(const LPoint3f &a, const LPoint3f &b) const { if (is_empty()) { return IF_no_intersection; diff --git a/panda/src/mathutil/geometricBoundingVolume.h b/panda/src/mathutil/geometricBoundingVolume.h index 2e0a15780e..b37a7fe864 100644 --- a/panda/src/mathutil/geometricBoundingVolume.h +++ b/panda/src/mathutil/geometricBoundingVolume.h @@ -21,23 +21,23 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA GeometricBoundingVolume : public BoundingVolume { public: - INLINE GeometricBoundingVolume(); + INLINE_MATHUTIL GeometricBoundingVolume(); PUBLISHED: - INLINE bool extend_by(const GeometricBoundingVolume *vol); - INLINE bool extend_by(const LPoint3f &point); + INLINE_MATHUTIL bool extend_by(const GeometricBoundingVolume *vol); + INLINE_MATHUTIL bool extend_by(const LPoint3f &point); // It might be nice to make these template member functions so we // could have true STL-style first/last iterators, but that's // impossible for virtual functions. - INLINE bool around(const GeometricBoundingVolume **first, + INLINE_MATHUTIL bool around(const GeometricBoundingVolume **first, const GeometricBoundingVolume **last); - INLINE bool around(const LPoint3f *first, + INLINE_MATHUTIL bool around(const LPoint3f *first, const LPoint3f *last); - INLINE int contains(const GeometricBoundingVolume *vol) const; - INLINE int contains(const LPoint3f &point) const; - INLINE int contains(const LPoint3f &a, const LPoint3f &b) const; + INLINE_MATHUTIL int contains(const GeometricBoundingVolume *vol) const; + INLINE_MATHUTIL int contains(const LPoint3f &point) const; + INLINE_MATHUTIL int contains(const LPoint3f &a, const LPoint3f &b) const; virtual LPoint3f get_approx_center() const=0; virtual void xform(const LMatrix4f &mat)=0; diff --git a/panda/src/mathutil/look_at_src.I b/panda/src/mathutil/look_at_src.I index c1d4577e96..05ed27ee17 100644 --- a/panda/src/mathutil/look_at_src.I +++ b/panda/src/mathutil/look_at_src.I @@ -3,17 +3,17 @@ // //////////////////////////////////////////////////////////////////// -INLINE void +INLINE_MATHUTIL void heads_up(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, CoordinateSystem cs) { heads_up(mat, fwd, FLOATNAME(LVector3)::up(cs), cs); } -INLINE void +INLINE_MATHUTIL void look_at(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, CoordinateSystem cs) { look_at(mat, fwd, FLOATNAME(LVector3)::up(cs), cs); } -INLINE void +INLINE_MATHUTIL void heads_up(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd, const FLOATNAME(LVector3) &up, CoordinateSystem cs) { FLOATNAME(LMatrix3) mat3; @@ -21,7 +21,7 @@ heads_up(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd, mat = FLOATNAME(LMatrix4)(mat3); } -INLINE void +INLINE_MATHUTIL void look_at(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd, const FLOATNAME(LVector3) &up, CoordinateSystem cs) { FLOATNAME(LMatrix3) mat3; @@ -29,12 +29,12 @@ look_at(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd, mat = FLOATNAME(LMatrix4)(mat3); } -INLINE void +INLINE_MATHUTIL void heads_up(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd, CoordinateSystem cs) { heads_up(mat, fwd, FLOATNAME(LVector3)::up(cs), cs); } -INLINE void +INLINE_MATHUTIL void look_at(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd, CoordinateSystem cs) { look_at(mat, fwd, FLOATNAME(LVector3)::up(cs), cs); } diff --git a/panda/src/mathutil/look_at_src.cxx b/panda/src/mathutil/look_at_src.cxx index 321693715a..150b8a54a7 100644 --- a/panda/src/mathutil/look_at_src.cxx +++ b/panda/src/mathutil/look_at_src.cxx @@ -3,7 +3,7 @@ // //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LMatrix3) +INLINE_MATHUTIL FLOATNAME(LMatrix3) make_xi_mat(const FLOATNAME(LVector2) &x) { return FLOATNAME(LMatrix3)(1, 0, 0, 0, x[0], x[1], @@ -11,7 +11,7 @@ make_xi_mat(const FLOATNAME(LVector2) &x) { } -INLINE FLOATNAME(LMatrix3) +INLINE_MATHUTIL FLOATNAME(LMatrix3) make_x_mat(const FLOATNAME(LVector2) &x) { return FLOATNAME(LMatrix3)(1, 0, 0, 0, x[1], x[0], @@ -19,7 +19,7 @@ make_x_mat(const FLOATNAME(LVector2) &x) { } -INLINE FLOATNAME(LMatrix3) +INLINE_MATHUTIL FLOATNAME(LMatrix3) make_y_mat(const FLOATNAME(LVector2) &y) { return FLOATNAME(LMatrix3)(y[1], 0, -y[0], 0, 1, 0, @@ -27,7 +27,7 @@ make_y_mat(const FLOATNAME(LVector2) &y) { } -INLINE FLOATNAME(LMatrix3) +INLINE_MATHUTIL FLOATNAME(LMatrix3) make_z_mat(const FLOATNAME(LVector2) &z) { return FLOATNAME(LMatrix3)(z[1], -z[0], 0, z[0], z[1], 0, diff --git a/panda/src/mathutil/look_at_src.h b/panda/src/mathutil/look_at_src.h index e0f325a7ff..eb289d052d 100644 --- a/panda/src/mathutil/look_at_src.h +++ b/panda/src/mathutil/look_at_src.h @@ -27,22 +27,22 @@ look_at(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, const FLOATNAME(LVector3) &up = FLOATNAME(LVector3)::up(), CoordinateSystem cs = CS_default); -INLINE void heads_up(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, +INLINE_MATHUTIL void heads_up(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, CoordinateSystem cs); -INLINE void look_at(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, +INLINE_MATHUTIL void look_at(FLOATNAME(LMatrix3) &mat, const FLOATNAME(LVector3) &fwd, CoordinateSystem cs); -INLINE void heads_up(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd, +INLINE_MATHUTIL void heads_up(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd, const FLOATNAME(LVector3) &up = FLOATNAME(LVector3)::up(), CoordinateSystem cs = CS_default); -INLINE void look_at(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd, +INLINE_MATHUTIL void look_at(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd, const FLOATNAME(LVector3) &up = FLOATNAME(LVector3)::up(), CoordinateSystem cs = CS_default); -INLINE void heads_up(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd, +INLINE_MATHUTIL void heads_up(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd, CoordinateSystem cs); -INLINE void look_at(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd, +INLINE_MATHUTIL void look_at(FLOATNAME(LMatrix4) &mat, const FLOATNAME(LVector3) &fwd, CoordinateSystem cs); END_PUBLISH diff --git a/panda/src/mathutil/mathHelpers.I b/panda/src/mathutil/mathHelpers.I index 2698113d06..81a7fb4cfc 100644 --- a/panda/src/mathutil/mathHelpers.I +++ b/panda/src/mathutil/mathHelpers.I @@ -8,7 +8,7 @@ //////////////////////////////////////////////////////////////////// #include -INLINE float distance(const LPoint3f &pos0, const LPoint3f &pos1) { +INLINE_MATHUTIL float distance(const LPoint3f &pos0, const LPoint3f &pos1) { LVector3f v = pos0 - pos1; return length(v); } diff --git a/panda/src/mathutil/mathHelpers.h b/panda/src/mathutil/mathHelpers.h index a3607c7e4a..832370dd0f 100644 --- a/panda/src/mathutil/mathHelpers.h +++ b/panda/src/mathutil/mathHelpers.h @@ -15,7 +15,7 @@ BEGIN_PUBLISH -INLINE float distance(const LPoint3f &pos0, const LPoint3f &pos1); +INLINE_MATHUTIL float distance(const LPoint3f &pos0, const LPoint3f &pos1); END_PUBLISH diff --git a/panda/src/mathutil/omniBoundingVolume.I b/panda/src/mathutil/omniBoundingVolume.I index 2882be4f2d..a73d1fda4a 100644 --- a/panda/src/mathutil/omniBoundingVolume.I +++ b/panda/src/mathutil/omniBoundingVolume.I @@ -8,7 +8,7 @@ // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE OmniBoundingVolume:: +INLINE_MATHUTIL OmniBoundingVolume:: OmniBoundingVolume() { _flags = F_infinite; } diff --git a/panda/src/mathutil/omniBoundingVolume.h b/panda/src/mathutil/omniBoundingVolume.h index 6b41e15c82..4666197c45 100644 --- a/panda/src/mathutil/omniBoundingVolume.h +++ b/panda/src/mathutil/omniBoundingVolume.h @@ -17,7 +17,7 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA OmniBoundingVolume : public GeometricBoundingVolume { PUBLISHED: - INLINE OmniBoundingVolume(); + INLINE_MATHUTIL OmniBoundingVolume(); public: virtual BoundingVolume *make_copy() const; diff --git a/panda/src/mathutil/plane_src.I b/panda/src/mathutil/plane_src.I index 6162e67d77..c82f68a197 100644 --- a/panda/src/mathutil/plane_src.I +++ b/panda/src/mathutil/plane_src.I @@ -10,7 +10,7 @@ // intersect the origin, perpendicular to the Z axis. // It's not clear how useful a default plane is. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(Plane):: +INLINE_MATHUTIL FLOATNAME(Plane):: FLOATNAME(Plane)(void) { _a = 0.0; _b = 0.0; @@ -23,7 +23,7 @@ FLOATNAME(Plane)(void) { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(Plane):: +INLINE_MATHUTIL FLOATNAME(Plane):: FLOATNAME(Plane)(const FLOATNAME(Plane) ©) : _a(copy._a), _b(copy._b), @@ -40,7 +40,7 @@ FLOATNAME(Plane)(const FLOATNAME(Plane) ©) : // viewed from the end of the normal vector, looking // down). //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(Plane):: +INLINE_MATHUTIL FLOATNAME(Plane):: FLOATNAME(Plane)(const FLOATNAME(LPoint3) &a, const FLOATNAME(LPoint3) &b, const FLOATNAME(LPoint3) &c) { FLOATNAME(LVector3) u = b - a; @@ -59,7 +59,7 @@ FLOATNAME(Plane)(const FLOATNAME(LPoint3) &a, const FLOATNAME(LPoint3) &b, // Description: Constructs a plane given a surface normal vector and // a point within the plane. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(Plane):: +INLINE_MATHUTIL FLOATNAME(Plane):: FLOATNAME(Plane)(const FLOATNAME(LVector3) &normal, const FLOATNAME(LPoint3) &point) { FLOATNAME(LVector3) p = normalize(normal); @@ -74,7 +74,7 @@ FLOATNAME(Plane)(const FLOATNAME(LVector3) &normal, const FLOATNAME(LPoint3) &po // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(Plane)& FLOATNAME(Plane):: +INLINE_MATHUTIL FLOATNAME(Plane)& FLOATNAME(Plane):: operator = (const FLOATNAME(Plane)& p) { _a = p._a; _b = p._b; @@ -88,7 +88,7 @@ operator = (const FLOATNAME(Plane)& p) { // Access: Public // Description: Transforms the plane by the indicated matrix. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(Plane) FLOATNAME(Plane):: +INLINE_MATHUTIL FLOATNAME(Plane) FLOATNAME(Plane):: operator * (const FLOATNAME(LMatrix3) &mat) const { FLOATNAME(LVector3) new_normal = get_normal() * mat; FLOATNAME(LPoint3) new_point = get_point() * mat; @@ -100,7 +100,7 @@ operator * (const FLOATNAME(LMatrix3) &mat) const { // Access: Public // Description: Transforms the plane by the indicated matrix. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(Plane) FLOATNAME(Plane):: +INLINE_MATHUTIL FLOATNAME(Plane) FLOATNAME(Plane):: operator * (const FLOATNAME(LMatrix4) &mat) const { FLOATNAME(LVector3) new_normal = get_normal() * mat; FLOATNAME(LPoint3) new_point = get_point() * mat; @@ -112,7 +112,7 @@ operator * (const FLOATNAME(LMatrix4) &mat) const { // Access: Public // Description: Returns the surface normal of the plane. //////////////////////////////////////////////////////////////////// -INLINE FLOATNAME(LVector3) FLOATNAME(Plane):: +INLINE_MATHUTIL FLOATNAME(LVector3) FLOATNAME(Plane):: get_normal() const { return FLOATNAME(LVector3)(_a, _b, _c); } @@ -127,7 +127,7 @@ get_normal() const { // the plane (on the opposite side from the normal). // It's zero if the point is exactly in the plane. //////////////////////////////////////////////////////////////////// -INLINE FLOATTYPE FLOATNAME(Plane):: +INLINE_MATHUTIL FLOATTYPE FLOATNAME(Plane):: dist_to_plane(const FLOATNAME(LPoint3) &point) const { return (_a * point[0] + _b * point[1] + _c * point[2] + _d); } @@ -142,7 +142,7 @@ dist_to_plane(const FLOATNAME(LPoint3) &point) const { // bearing on the intersection test. If true, sets // intersection_point to the point of intersection. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(Plane):: +INLINE_MATHUTIL bool FLOATNAME(Plane):: intersects_line(FLOATNAME(LPoint3) &intersection_point, const FLOATNAME(LPoint3) &p1, const FLOATNAME(LPoint3) &p2) const { @@ -171,7 +171,7 @@ intersects_line(FLOATNAME(LPoint3) &intersection_point, // point from, and t == 1.0 implies at point from + // delta, with other values of t accordingly. //////////////////////////////////////////////////////////////////// -INLINE bool FLOATNAME(Plane):: +INLINE_MATHUTIL bool FLOATNAME(Plane):: intersects_line(FLOATTYPE &t, const FLOATNAME(LPoint3) &from, const FLOATNAME(LVector3) &delta) const { @@ -189,7 +189,7 @@ intersects_line(FLOATTYPE &t, // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(Plane):: +INLINE_MATHUTIL void FLOATNAME(Plane):: output(ostream &out) const { out << "Plane(" << _a << " " << _b << " " << _c << " " << _d << ")"; } @@ -199,7 +199,7 @@ output(ostream &out) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(Plane):: +INLINE_MATHUTIL void FLOATNAME(Plane):: write(ostream &out, int indent_level) const { indent(out, indent_level) << *this << "\n"; } @@ -209,7 +209,7 @@ write(ostream &out, int indent_level) const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(Plane):: +INLINE_MATHUTIL void FLOATNAME(Plane):: write_datagram(Datagram &dest) { dest.add_float32(_a); @@ -223,7 +223,7 @@ write_datagram(Datagram &dest) // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE void FLOATNAME(Plane):: +INLINE_MATHUTIL void FLOATNAME(Plane):: read_datagram(DatagramIterator &source) { _a = source.get_float32(); diff --git a/panda/src/mathutil/plane_src.h b/panda/src/mathutil/plane_src.h index 178d36f72b..5a7809958e 100644 --- a/panda/src/mathutil/plane_src.h +++ b/panda/src/mathutil/plane_src.h @@ -9,43 +9,43 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA FLOATNAME(Plane) { PUBLISHED: - INLINE FLOATNAME(Plane)(void); - INLINE FLOATNAME(Plane)(const FLOATNAME(Plane) ©); - INLINE FLOATNAME(Plane)(const FLOATNAME(LPoint3) &a, const FLOATNAME(LPoint3) &b, + INLINE_MATHUTIL FLOATNAME(Plane)(void); + INLINE_MATHUTIL FLOATNAME(Plane)(const FLOATNAME(Plane) ©); + INLINE_MATHUTIL FLOATNAME(Plane)(const FLOATNAME(LPoint3) &a, const FLOATNAME(LPoint3) &b, const FLOATNAME(LPoint3) &c); - INLINE FLOATNAME(Plane)(const FLOATNAME(LVector3) &normal, + INLINE_MATHUTIL FLOATNAME(Plane)(const FLOATNAME(LVector3) &normal, const FLOATNAME(LPoint3) &point); - INLINE FLOATNAME(Plane)& operator = (const FLOATNAME(Plane)& copy); + INLINE_MATHUTIL FLOATNAME(Plane)& operator = (const FLOATNAME(Plane)& copy); - INLINE FLOATNAME(Plane) operator * (const FLOATNAME(LMatrix3) &mat) const; - INLINE FLOATNAME(Plane) operator * (const FLOATNAME(LMatrix4) &mat) const; + INLINE_MATHUTIL FLOATNAME(Plane) operator * (const FLOATNAME(LMatrix3) &mat) const; + INLINE_MATHUTIL FLOATNAME(Plane) operator * (const FLOATNAME(LMatrix4) &mat) const; FLOATNAME(LMatrix4) get_reflection_mat(void) const; - INLINE FLOATNAME(LVector3) get_normal() const; + INLINE_MATHUTIL FLOATNAME(LVector3) get_normal() const; FLOATNAME(LPoint3) get_point() const; - INLINE FLOATTYPE dist_to_plane(const FLOATNAME(LPoint3) &point) const; - INLINE bool intersects_line(FLOATNAME(LPoint3) &intersection_point, + INLINE_MATHUTIL FLOATTYPE dist_to_plane(const FLOATNAME(LPoint3) &point) const; + INLINE_MATHUTIL bool intersects_line(FLOATNAME(LPoint3) &intersection_point, const FLOATNAME(LPoint3) &p1, const FLOATNAME(LPoint3) &p2) const; - INLINE bool intersects_line(FLOATTYPE &t, + INLINE_MATHUTIL bool intersects_line(FLOATTYPE &t, const FLOATNAME(LPoint3) &from, const FLOATNAME(LVector3) &delta) const; - INLINE void output(ostream &out) const; - INLINE void write(ostream &out, int indent_level = 0) const; + INLINE_MATHUTIL void output(ostream &out) const; + INLINE_MATHUTIL void write(ostream &out, int indent_level = 0) const; public: - INLINE void write_datagram(Datagram &dest); - INLINE void read_datagram(DatagramIterator &source); + INLINE_MATHUTIL void write_datagram(Datagram &dest); + INLINE_MATHUTIL void read_datagram(DatagramIterator &source); public: FLOATTYPE _a, _b, _c, _d; }; -INLINE ostream &operator << (ostream &out, const FLOATNAME(Plane) &p) { +INLINE_MATHUTIL ostream &operator << (ostream &out, const FLOATNAME(Plane) &p) { p.output(out); return out; }