more math operations

This commit is contained in:
David Rose 2005-01-23 00:23:01 +00:00
parent 843c9d07b9
commit 287f4f387c
11 changed files with 265 additions and 99 deletions

View File

@ -47,11 +47,10 @@ INLINE float ctan(float v) {
} }
INLINE void INLINE void
sincosf(float v, float *pSinResult, float *pCosResult) { csincos(float v, float *pSinResult, float *pCosResult) {
// MS VC defines _M_IX86 for x86. gcc should define _X86_
// MS VC defines _M_IX86 for x86. gcc should define _X86_
#if defined(_M_IX86) || defined(_X86_) #if defined(_M_IX86) || defined(_X86_)
//#define fsincos_opcode __asm _emit 0xd9 __asm _emit 0xfb //#define fsincos_opcode __asm _emit 0xd9 __asm _emit 0xfb
__asm { __asm {
mov eax, pSinResult mov eax, pSinResult
mov edx, pCosResult mov edx, pCosResult
@ -66,30 +65,17 @@ sincosf(float v, float *pSinResult, float *pCosResult) {
#endif //!_X86_ #endif //!_X86_
} }
INLINE void ////////////////////////////////////////////////////////////////////
sincosd(double v, double *pSinResult, double *pCosResult) { // Function: csin_over_x
#if defined(_M_IX86) || defined(_X86_) // Description: Computes sin(x) / x, well-behaved as x approaches 0.
//#define fsincos_opcode __asm _emit 0xd9 __asm _emit 0xfb ////////////////////////////////////////////////////////////////////
__asm { INLINE float
mov eax, pSinResult csin_over_x(float v) {
mov edx, pCosResult if (1.0f + v * v == 1.0f) {
fld v return 1.0f;
fsincos } else {
fstp QWORD ptr [edx] return csin(v) / v;
fstp QWORD ptr [eax]
} }
#else //!_X86_
*pSinResult = sin(v);
*pCosResult = cos(v);
#endif //!_X86_
}
INLINE void csincos(float v,float *pSinResult, float *pCosResult) {
sincosf(v,pSinResult,pCosResult);
}
INLINE void csincos(double v,double *pSinResult, double *pCosResult) {
sincosd(v,pSinResult,pCosResult);
} }
INLINE float cabs(float v) { INLINE float cabs(float v) {
@ -104,6 +90,14 @@ INLINE float catan2(float y, float x) {
return atan2f(y, x); return atan2f(y, x);
} }
INLINE float casin(float v) {
return asinf(v);
}
INLINE float cacos(float v) {
return acosf(v);
}
#ifdef __INTEL_COMPILER #ifdef __INTEL_COMPILER
// see float.h // see float.h
#define FPU_CONTROLWORD_WRITEMASK 0xFFFFF // if you look at defn of _CW_DEFAULT, all settings fall within 0xFFFFF #define FPU_CONTROLWORD_WRITEMASK 0xFFFFF // if you look at defn of _CW_DEFAULT, all settings fall within 0xFFFFF
@ -152,6 +146,37 @@ INLINE double ctan(double v) {
return tan(v); return tan(v);
} }
INLINE void
csincos(double v, double *pSinResult, double *pCosResult) {
#if defined(_M_IX86) || defined(_X86_)
//#define fsincos_opcode __asm _emit 0xd9 __asm _emit 0xfb
__asm {
mov eax, pSinResult
mov edx, pCosResult
fld v
fsincos
fstp QWORD ptr [edx]
fstp QWORD ptr [eax]
}
#else //!_X86_
*pSinResult = sin(v);
*pCosResult = cos(v);
#endif //!_X86_
}
////////////////////////////////////////////////////////////////////
// Function: csin_over_x
// Description: Computes sin(x) / x, well-behaved as x approaches 0.
////////////////////////////////////////////////////////////////////
INLINE double
csin_over_x(double v) {
if (1.0 + v * v == 1.0) {
return 1.0;
} else {
return csin(v) / v;
}
}
INLINE double cabs(double v) { INLINE double cabs(double v) {
return fabs(v); return fabs(v);
} }
@ -164,6 +189,14 @@ INLINE double catan2(double y, double x) {
return atan2(y, x); return atan2(y, x);
} }
INLINE double casin(double v) {
return asin(v);
}
INLINE double cacos(double v) {
return acos(v);
}
INLINE bool cnan(double v) { INLINE bool cnan(double v) {
#ifndef _WIN32 #ifndef _WIN32
return (isnan(v) != 0); return (isnan(v) != 0);

View File

@ -34,9 +34,11 @@ INLINE float csin(float v);
INLINE float ccos(float v); INLINE float ccos(float v);
INLINE float ctan(float v); INLINE float ctan(float v);
INLINE void csincos(float v, float *pSinResult, float *pCosResult); // does both at once (faster on x86) INLINE void csincos(float v, float *pSinResult, float *pCosResult); // does both at once (faster on x86)
INLINE float csin_over_x(float v);
INLINE float cabs(float v); INLINE float cabs(float v);
INLINE float catan(float v); INLINE float catan(float v);
INLINE float catan2(float y, float x); INLINE float catan2(float y, float x);
INLINE float casin(float v);
//INLINE float cfloor(float f); //INLINE float cfloor(float f);
//INLINE float cceil(float f); //INLINE float cceil(float f);
@ -46,10 +48,11 @@ INLINE double csqrt(double v);
INLINE double csin(double v); INLINE double csin(double v);
INLINE double ccos(double v); INLINE double ccos(double v);
INLINE double ctan(double v); INLINE double ctan(double v);
INLINE void csincos(double v, double *pSinResult, double *pCosResult); // does both at once (faster on x86)
INLINE double cabs(double v); INLINE double cabs(double v);
INLINE double catan(double v); INLINE double catan(double v);
INLINE double catan2(double y, double x); INLINE double catan2(double y, double x);
INLINE void csincos(double v, double *pSinResult, double *pCosResult); // does both at once (faster on x86) INLINE double casin(double y, double x);
// Returns true if the number is nan, false if it's a genuine number // Returns true if the number is nan, false if it's a genuine number
// or infinity. // or infinity.

View File

@ -33,7 +33,7 @@
lvecBase4_src.h lvector2.h lvector2_src.I lvector2_src.cxx \ lvecBase4_src.h lvector2.h lvector2_src.I lvector2_src.cxx \
lvector2_src.h lvector3.h lvector3_src.I lvector3_src.cxx \ lvector2_src.h lvector3.h lvector3_src.I lvector3_src.cxx \
lvector3_src.h lvector4.h lvector4_src.I lvector4_src.cxx \ lvector3_src.h lvector4.h lvector4_src.I lvector4_src.cxx \
lvector4_src.h mathNumbers.h pta_Colorf.h \ lvector4_src.h mathNumbers.h mathNumbers.I pta_Colorf.h \
pta_Normalf.h pta_TexCoordf.h pta_Vertexf.h vector_Colorf.h \ pta_Normalf.h pta_TexCoordf.h pta_Vertexf.h vector_Colorf.h \
vector_LPoint2f.h vector_LVecBase3f.h vector_Normalf.h \ vector_LPoint2f.h vector_LVecBase3f.h vector_Normalf.h \
vector_TexCoordf.h vector_Vertexf.h vector_TexCoordf.h vector_Vertexf.h
@ -68,7 +68,7 @@
lvecBase3_src.I lvecBase3_src.h lvecBase4.h lvecBase4_src.I \ lvecBase3_src.I lvecBase3_src.h lvecBase4.h lvecBase4_src.I \
lvecBase4_src.h lvector2.h lvector2_src.I lvector2_src.h \ lvecBase4_src.h lvector2.h lvector2_src.I lvector2_src.h \
lvector3.h lvector3_src.I lvector3_src.h lvector4.h lvector4_src.I \ lvector3.h lvector3_src.I lvector3_src.h lvector4.h lvector4_src.I \
lvector4_src.h mathNumbers.h pta_Colorf.h \ lvector4_src.h mathNumbers.h mathNumbers.I pta_Colorf.h \
pta_Normalf.h pta_TexCoordf.h pta_Vertexf.h vector_Colorf.h \ pta_Normalf.h pta_TexCoordf.h pta_Vertexf.h vector_Colorf.h \
vector_LPoint2f.h vector_LVecBase3f.h vector_Normalf.h \ vector_LPoint2f.h vector_LVecBase3f.h vector_Normalf.h \
vector_TexCoordf.h vector_Vertexf.h vector_TexCoordf.h vector_Vertexf.h

View File

@ -106,6 +106,28 @@ operator - (const FLOATNAME(LQuaternion) &other) const {
return FLOATNAME(LVecBase4)::operator - (other); return FLOATNAME(LVecBase4)::operator - (other);
} }
////////////////////////////////////////////////////////////////////
// Function: LVector::angle_rad
// Access: Published
// Description: Returns the angle between this quat and the other
// one, expressed in radians.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATTYPE FLOATNAME(LQuaternion)::
angle_rad(const FLOATNAME(LQuaternion) &other) const {
return get_axis().angle_rad(other.get_axis());
}
////////////////////////////////////////////////////////////////////
// Function: LVector::angle_deg
// Access: Published
// Description: Returns the angle between this vector and the other
// one, expressed in degrees.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATTYPE FLOATNAME(LQuaternion)::
angle_deg(const FLOATNAME(LQuaternion) &other) const {
return rad_2_deg(angle_rad(other));
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LQuaternion::quaternion * scalar // Function: LQuaternion::quaternion * scalar
// Access: Public // Access: Public
@ -256,11 +278,12 @@ set_from_matrix(const FLOATNAME(LMatrix4) &m) {
// Access: Public // Access: Public
// Description: This, along with get_angle(), returns the rotation // Description: This, along with get_angle(), returns the rotation
// represented by the quaternion as an angle about an // represented by the quaternion as an angle about an
// arbitrary axis. This returns the axis. // arbitrary axis. This returns the axis; it is not
// normalized.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LQuaternion):: INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LQuaternion)::
get_axis() const { get_axis() const {
return ::normalize(FLOATNAME(LVector3)(_v.data[1], _v.data[2], _v.data[3])); return FLOATNAME(LVector3)(_v.data[1], _v.data[2], _v.data[3]);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

View File

@ -41,6 +41,9 @@ PUBLISHED:
INLINE_LINMATH FLOATNAME(LQuaternion) INLINE_LINMATH FLOATNAME(LQuaternion)
operator - (const FLOATNAME(LQuaternion) &other) const; operator - (const FLOATNAME(LQuaternion) &other) const;
INLINE_LINMATH FLOATTYPE angle_rad(const FLOATNAME(LQuaternion) &other) const;
INLINE_LINMATH FLOATTYPE angle_deg(const FLOATNAME(LQuaternion) &other) const;
INLINE_LINMATH FLOATNAME(LQuaternion) operator * (FLOATTYPE scalar) const; INLINE_LINMATH FLOATNAME(LQuaternion) operator * (FLOATTYPE scalar) const;
INLINE_LINMATH FLOATNAME(LQuaternion) operator / (FLOATTYPE scalar) const; INLINE_LINMATH FLOATNAME(LQuaternion) operator / (FLOATTYPE scalar) const;

View File

@ -25,6 +25,8 @@
#include "datagram.h" #include "datagram.h"
#include "datagramIterator.h" #include "datagramIterator.h"
#include "checksumHashGenerator.h" #include "checksumHashGenerator.h"
#include "mathNumbers.h"
#include "deg_2_rad.h"
#include "cmath.h" #include "cmath.h"
#include "nearly_zero.h" #include "nearly_zero.h"

View File

@ -359,7 +359,7 @@ end() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::fill // Function: LVecBase3::fill
// Access: Public // Access: Published
// Description: Sets each element of the vector to the indicated // Description: Sets each element of the vector to the indicated
// fill_value. This is particularly useful for // fill_value. This is particularly useful for
// initializing to zero. // initializing to zero.
@ -373,7 +373,7 @@ fill(FLOATTYPE fill_value) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::set // Function: LVecBase3::set
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH void FLOATNAME(LVecBase3):: INLINE_LINMATH void FLOATNAME(LVecBase3)::
@ -385,7 +385,7 @@ set(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::dot // Function: LVecBase3::dot
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase3):: INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase3)::
@ -395,7 +395,7 @@ dot(const FLOATNAME(LVecBase3) &other) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::cross // Function: LVecBase3::cross
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
@ -407,7 +407,7 @@ cross(const FLOATNAME(LVecBase3) &other) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::operator < // Function: LVecBase3::operator <
// Access: Public // Access: Published
// Description: This performs a lexicographical comparison. It's of // Description: This performs a lexicographical comparison. It's of
// questionable mathematical meaning, but sometimes has // questionable mathematical meaning, but sometimes has
// a practical purpose for sorting unique vectors, // a practical purpose for sorting unique vectors,
@ -421,7 +421,7 @@ operator < (const FLOATNAME(LVecBase3) &other) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::operator == // Function: LVecBase3::operator ==
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH bool FLOATNAME(LVecBase3):: INLINE_LINMATH bool FLOATNAME(LVecBase3)::
@ -433,7 +433,7 @@ operator == (const FLOATNAME(LVecBase3) &other) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::operator != // Function: LVecBase3::operator !=
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH bool FLOATNAME(LVecBase3):: INLINE_LINMATH bool FLOATNAME(LVecBase3)::
@ -463,8 +463,8 @@ get_standardized_rotation(FLOATTYPE angle_in_degrees) {
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::compare_hpr_to // Function: LVecBase3::get_standardized_hpr
// Access: Public // Access: Published
// Description: Try to un-spin the hpr to a standard form. Like // Description: Try to un-spin the hpr to a standard form. Like
// all standards, someone decides between many // all standards, someone decides between many
// arbitrary posible standards. This function assumes // arbitrary posible standards. This function assumes
@ -491,7 +491,7 @@ get_standardized_hpr() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::compare_to // Function: LVecBase3::compare_to
// Access: Public // Access: Published
// Description: This flavor of compare_to uses a default threshold // Description: This flavor of compare_to uses a default threshold
// value based on the numeric type. // value based on the numeric type.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -502,7 +502,7 @@ compare_to(const FLOATNAME(LVecBase3) &other) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::compare_to // Function: LVecBase3::compare_to
// Access: Public // Access: Published
// Description: Sorts vectors lexicographically, componentwise. // Description: Sorts vectors lexicographically, componentwise.
// Returns a number less than 0 if this vector sorts // Returns a number less than 0 if this vector sorts
// before the other one, greater than zero if it sorts // before the other one, greater than zero if it sorts
@ -525,7 +525,7 @@ compare_to(const FLOATNAME(LVecBase3) &other, FLOATTYPE threshold) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::get_hash // Function: LVecBase3::get_hash
// Access: Public // Access: Published
// Description: Returns a suitable hash for phash_map. // Description: Returns a suitable hash for phash_map.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH size_t FLOATNAME(LVecBase3):: INLINE_LINMATH size_t FLOATNAME(LVecBase3)::
@ -535,7 +535,7 @@ get_hash() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::get_hash // Function: LVecBase3::get_hash
// Access: Public // Access: Published
// Description: Returns a suitable hash for phash_map. // Description: Returns a suitable hash for phash_map.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH size_t FLOATNAME(LVecBase3):: INLINE_LINMATH size_t FLOATNAME(LVecBase3)::
@ -545,7 +545,7 @@ get_hash(FLOATTYPE threshold) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::add_hash // Function: LVecBase3::add_hash
// Access: Public // Access: Published
// Description: Adds the vector into the running hash. // Description: Adds the vector into the running hash.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH size_t FLOATNAME(LVecBase3):: INLINE_LINMATH size_t FLOATNAME(LVecBase3)::
@ -555,7 +555,7 @@ add_hash(size_t hash) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::add_hash // Function: LVecBase3::add_hash
// Access: Public // Access: Published
// Description: Adds the vector into the running hash. // Description: Adds the vector into the running hash.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH size_t FLOATNAME(LVecBase3):: INLINE_LINMATH size_t FLOATNAME(LVecBase3)::
@ -569,7 +569,7 @@ add_hash(size_t hash, FLOATTYPE threshold) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::unary - // Function: LVecBase3::unary -
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
@ -579,7 +579,7 @@ operator - () const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::vector + vector // Function: LVecBase3::vector + vector
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
@ -591,7 +591,7 @@ operator + (const FLOATNAME(LVecBase3) &other) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::vector - vector // Function: LVecBase3::vector - vector
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
@ -603,7 +603,7 @@ operator - (const FLOATNAME(LVecBase3) &other) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::vector * scalar // Function: LVecBase3::vector * scalar
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
@ -615,7 +615,7 @@ operator * (FLOATTYPE scalar) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::vector / scalar // Function: LVecBase3::vector / scalar
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
@ -628,7 +628,7 @@ operator / (FLOATTYPE scalar) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::operator += // Function: LVecBase3::operator +=
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH void FLOATNAME(LVecBase3):: INLINE_LINMATH void FLOATNAME(LVecBase3)::
@ -640,7 +640,7 @@ operator += (const FLOATNAME(LVecBase3) &other) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::operator -= // Function: LVecBase3::operator -=
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH void FLOATNAME(LVecBase3):: INLINE_LINMATH void FLOATNAME(LVecBase3)::
@ -652,7 +652,7 @@ operator -= (const FLOATNAME(LVecBase3) &other) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::operator *= // Function: LVecBase3::operator *=
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH void FLOATNAME(LVecBase3):: INLINE_LINMATH void FLOATNAME(LVecBase3)::
@ -664,7 +664,7 @@ operator *= (FLOATTYPE scalar) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::operator /= // Function: LVecBase3::operator /=
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH void FLOATNAME(LVecBase3):: INLINE_LINMATH void FLOATNAME(LVecBase3)::
@ -677,7 +677,7 @@ operator /= (FLOATTYPE scalar) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::cross product (with assigment) // Function: LVecBase3::cross product (with assigment)
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH void FLOATNAME(LVecBase3):: INLINE_LINMATH void FLOATNAME(LVecBase3)::
@ -687,7 +687,7 @@ cross_into(const FLOATNAME(LVecBase3) &other) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::almost_equal // Function: LVecBase3::almost_equal
// Access: Public // Access: Published
// Description: Returns true if two vectors are memberwise equal // Description: Returns true if two vectors are memberwise equal
// within a specified tolerance. // within a specified tolerance.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -700,7 +700,7 @@ almost_equal(const FLOATNAME(LVecBase3) &other, FLOATTYPE threshold) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::almost_equal // Function: LVecBase3::almost_equal
// Access: Public // Access: Published
// Description: Returns true if two vectors are memberwise equal // Description: Returns true if two vectors are memberwise equal
// within a default tolerance based on the numeric type. // within a default tolerance based on the numeric type.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -711,7 +711,7 @@ almost_equal(const FLOATNAME(LVecBase3) &other) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVecBase3::output // Function: LVecBase3::output
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH void FLOATNAME(LVecBase3):: INLINE_LINMATH void FLOATNAME(LVecBase3)::

View File

@ -19,7 +19,7 @@
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::Default Constructor // Function: LVector3::Default Constructor
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVector3):: INLINE_LINMATH FLOATNAME(LVector3)::
@ -28,7 +28,7 @@ FLOATNAME(LVector3)() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::Copy Constructor // Function: LVector3::Copy Constructor
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVector3):: INLINE_LINMATH FLOATNAME(LVector3)::
@ -37,7 +37,7 @@ FLOATNAME(LVector3)(const FLOATNAME(LVecBase3) &copy) : FLOATNAME(LVecBase3)(cop
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::Copy Assignment Operator // Function: LVector3::Copy Assignment Operator
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVector3) &FLOATNAME(LVector3):: INLINE_LINMATH FLOATNAME(LVector3) &FLOATNAME(LVector3)::
@ -48,7 +48,7 @@ operator = (const FLOATNAME(LVecBase3) &copy) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::Copy Fill Operator // Function: LVector3::Copy Fill Operator
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVector3) &FLOATNAME(LVector3):: INLINE_LINMATH FLOATNAME(LVector3) &FLOATNAME(LVector3)::
@ -59,7 +59,7 @@ operator = (FLOATTYPE fill_value) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::Constructor // Function: LVector3::Constructor
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVector3):: INLINE_LINMATH FLOATNAME(LVector3)::
@ -70,7 +70,7 @@ FLOATNAME(LVector3)(FLOATTYPE fill_value) :
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::Constructor // Function: LVector3::Constructor
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVector3):: INLINE_LINMATH FLOATNAME(LVector3)::
@ -81,7 +81,7 @@ FLOATNAME(LVector3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) :
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::zero Named Constructor // Function: LVector3::zero Named Constructor
// Access: Public // Access: Published
// Description: Returns a zero-length vector. // Description: Returns a zero-length vector.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH const FLOATNAME(LVector3) &FLOATNAME(LVector3):: INLINE_LINMATH const FLOATNAME(LVector3) &FLOATNAME(LVector3)::
@ -91,7 +91,7 @@ zero() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::unit_x Named Constructor // Function: LVector3::unit_x Named Constructor
// Access: Public // Access: Published
// Description: Returns a unit X vector. // Description: Returns a unit X vector.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH const FLOATNAME(LVector3) &FLOATNAME(LVector3):: INLINE_LINMATH const FLOATNAME(LVector3) &FLOATNAME(LVector3)::
@ -101,7 +101,7 @@ unit_x() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::unit_y Named Constructor // Function: LVector3::unit_y Named Constructor
// Access: Public // Access: Published
// Description: Returns a unit Y vector. // Description: Returns a unit Y vector.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH const FLOATNAME(LVector3) &FLOATNAME(LVector3):: INLINE_LINMATH const FLOATNAME(LVector3) &FLOATNAME(LVector3)::
@ -111,7 +111,7 @@ unit_y() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::unit_z Named Constructor // Function: LVector3::unit_z Named Constructor
// Access: Public // Access: Published
// Description: Returns a unit Z vector. // Description: Returns a unit Z vector.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH const FLOATNAME(LVector3) &FLOATNAME(LVector3):: INLINE_LINMATH const FLOATNAME(LVector3) &FLOATNAME(LVector3)::
@ -121,7 +121,7 @@ unit_z() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::unary - // Function: LVector3::unary -
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3):: INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3)::
@ -131,7 +131,7 @@ operator - () const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::vector + vecbase // Function: LVector3::vector + vecbase
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVector3):: INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVector3)::
@ -141,7 +141,7 @@ operator + (const FLOATNAME(LVecBase3) &other) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::vector + vector // Function: LVector3::vector + vector
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3):: INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3)::
@ -151,7 +151,7 @@ operator + (const FLOATNAME(LVector3) &other) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::vector - vecbase // Function: LVector3::vector - vecbase
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVector3):: INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVector3)::
@ -161,7 +161,7 @@ operator - (const FLOATNAME(LVecBase3) &other) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::vector - vector // Function: LVector3::vector - vector
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3):: INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3)::
@ -171,7 +171,7 @@ operator - (const FLOATNAME(LVector3) &other) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::length // Function: LVector3::length
// Access: Public // Access: Published
// Description: Returns the length of the vector, by the Pythagorean // Description: Returns the length of the vector, by the Pythagorean
// theorem. // theorem.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -182,7 +182,7 @@ length() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::length_squared // Function: LVector3::length_squared
// Access: Public // Access: Published
// Description: Returns the square of the vector's length, cheap and // Description: Returns the square of the vector's length, cheap and
// easy. // easy.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -193,7 +193,7 @@ length_squared() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::normalize // Function: LVector3::normalize
// Access: Public // Access: Published
// Description: Normalizes the vector in place. Returns true if the // Description: Normalizes the vector in place. Returns true if the
// vector was normalized, false if it was a zero-length // vector was normalized, false if it was a zero-length
// vector. // vector.
@ -214,7 +214,7 @@ normalize() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::cross // Function: LVector3::cross
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3):: INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3)::
@ -222,9 +222,37 @@ cross(const FLOATNAME(LVecBase3) &other) const {
return FLOATNAME(LVecBase3)::cross(other); return FLOATNAME(LVecBase3)::cross(other);
} }
////////////////////////////////////////////////////////////////////
// Function: LVector::angle_rad
// Access: Published
// Description: Returns the angle between this vector and the other
// one, expressed in radians.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATTYPE FLOATNAME(LVector3)::
angle_rad(const FLOATNAME(LVector3) &other) const {
// This algorithm yields better results than acos(dot(other)), which
// behaves poorly as dot(other) approaches 1.0.
if (dot(other) < 0.0f) {
return MathNumbers::cpi((FLOATTYPE)0.0f) - 2.0f * casin((-(*this)-other).length());
} else {
return 2.0f * casin(((*this)-other).length() / 2.0f);
}
}
////////////////////////////////////////////////////////////////////
// Function: LVector::angle_deg
// Access: Published
// Description: Returns the angle between this vector and the other
// one, expressed in degrees.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATTYPE FLOATNAME(LVector3)::
angle_deg(const FLOATNAME(LVector3) &other) const {
return rad_2_deg(angle_rad(other));
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::operator * scalar // Function: LVector3::operator * scalar
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3):: INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3)::
@ -234,7 +262,7 @@ operator * (FLOATTYPE scalar) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::operator / scalar // Function: LVector3::operator / scalar
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3):: INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3)::
@ -245,7 +273,7 @@ operator / (FLOATTYPE scalar) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::up // Function: LVector3::up
// Access: Public, Static // Access: Published, Static
// Description: Returns the up vector for the given coordinate // Description: Returns the up vector for the given coordinate
// system. // system.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -272,7 +300,7 @@ up(CoordinateSystem cs) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::right // Function: LVector3::right
// Access: Public, Static // Access: Published, Static
// Description: Returns the right vector for the given coordinate // Description: Returns the right vector for the given coordinate
// system. // system.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -283,7 +311,7 @@ right(CoordinateSystem) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::forward // Function: LVector3::forward
// Access: Public, Static // Access: Published, Static
// Description: Returns the forward vector for the given coordinate // Description: Returns the forward vector for the given coordinate
// system. // system.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -314,7 +342,7 @@ forward(CoordinateSystem cs) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::down // Function: LVector3::down
// Access: Public, Static // Access: Published, Static
// Description: Returns the down vector for the given coordinate // Description: Returns the down vector for the given coordinate
// system. // system.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -325,7 +353,7 @@ down(CoordinateSystem cs) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::left // Function: LVector3::left
// Access: Public, Static // Access: Published, Static
// Description: Returns the left vector for the given coordinate // Description: Returns the left vector for the given coordinate
// system. // system.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -336,7 +364,7 @@ left(CoordinateSystem cs) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::back // Function: LVector3::back
// Access: Public, Static // Access: Published, Static
// Description: Returns the back vector for the given coordinate // Description: Returns the back vector for the given coordinate
// system. // system.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -347,7 +375,7 @@ back(CoordinateSystem cs) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: LVector3::rfu // Function: LVector3::rfu
// Access: Public, Static // Access: Published, Static
// Description: Returns a vector that is described by its right, // Description: Returns a vector that is described by its right,
// forward, and up components, in whatever way the // forward, and up components, in whatever way the
// coordinate system represents that vector. // coordinate system represents that vector.

View File

@ -52,6 +52,9 @@ PUBLISHED:
INLINE_LINMATH FLOATTYPE length_squared() const; INLINE_LINMATH FLOATTYPE length_squared() const;
INLINE_LINMATH bool normalize(); INLINE_LINMATH bool normalize();
INLINE_LINMATH FLOATNAME(LVector3) cross(const FLOATNAME(LVecBase3) &other) const; INLINE_LINMATH FLOATNAME(LVector3) cross(const FLOATNAME(LVecBase3) &other) const;
INLINE_LINMATH FLOATTYPE angle_rad(const FLOATNAME(LVector3) &other) const;
INLINE_LINMATH FLOATTYPE angle_deg(const FLOATNAME(LVector3) &other) const;
INLINE_LINMATH FLOATNAME(LVector3) operator * (FLOATTYPE scalar) const; INLINE_LINMATH FLOATNAME(LVector3) operator * (FLOATTYPE scalar) const;
INLINE_LINMATH FLOATNAME(LVector3) operator / (FLOATTYPE scalar) const; INLINE_LINMATH FLOATNAME(LVector3) operator / (FLOATTYPE scalar) const;

62
panda/src/linmath/mathNumbers.I Executable file
View File

@ -0,0 +1,62 @@
// Filename: mathNumbers.I
// Created by: drose (22Jan05)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: MathNumbers::cpi
// Access: Public, Static
// Description: Returns pi as a single-precision or double-precision
// number, according to the type of the parameter.
////////////////////////////////////////////////////////////////////
INLINE float MathNumbers::
cpi(float) {
return pi_f;
}
////////////////////////////////////////////////////////////////////
// Function: MathNumbers::cln2
// Access: Public, Static
// Description: Returns ln(2) as a single-precision or double-precision
// number, according to the type of the parameter.
////////////////////////////////////////////////////////////////////
INLINE float MathNumbers::
cln2(float) {
return ln2_f;
}
////////////////////////////////////////////////////////////////////
// Function: MathNumbers::cpi
// Access: Public, Static
// Description: Returns pi as a single-precision or double-precision
// number, according to the type of the parameter.
////////////////////////////////////////////////////////////////////
INLINE double MathNumbers::
cpi(double) {
return pi;
}
////////////////////////////////////////////////////////////////////
// Function: MathNumbers::cln2
// Access: Public, Static
// Description: Returns ln(2) as a single-precision or double-precision
// number, according to the type of the parameter.
////////////////////////////////////////////////////////////////////
INLINE double MathNumbers::
cln2(double) {
return ln2;
}

View File

@ -31,6 +31,15 @@ PUBLISHED:
static const double ln2; static const double ln2;
static const double rad_2_deg; static const double rad_2_deg;
static const double deg_2_rad; static const double deg_2_rad;
public:
INLINE static float cpi(float);
INLINE static float cln2(float);
INLINE static double cpi(double);
INLINE static double cln2(double);
}; };
#include "mathNumbers.I"
#endif #endif