diff --git a/panda/src/linmath/lvec3_ops_src.I b/panda/src/linmath/lvec3_ops_src.I index 6b9f5c7db4..7f35785a95 100644 --- a/panda/src/linmath/lvec3_ops_src.I +++ b/panda/src/linmath/lvec3_ops_src.I @@ -81,7 +81,7 @@ cross(const FLOATNAME(LVector3) &a, const FLOATNAME(LVector3) &b) { //////////////////////////////////////////////////////////////////// INLINE_LINMATH FLOATTYPE -length(const FLOATNAME(LVector3) &a) { +length(const FLOATNAME(LVecBase3) &a) { return a.length(); } @@ -92,7 +92,7 @@ length(const FLOATNAME(LVector3) &a) { //////////////////////////////////////////////////////////////////// INLINE_LINMATH FLOATNAME(LVector3) -normalize(const FLOATNAME(LVector3) &v) { +normalize(const FLOATNAME(LVecBase3) &v) { FLOATNAME(LVector3) v1 = v; v1.normalize(); return v1; diff --git a/panda/src/linmath/lvec3_ops_src.h b/panda/src/linmath/lvec3_ops_src.h index aa53adbfad..506bf07a2b 100644 --- a/panda/src/linmath/lvec3_ops_src.h +++ b/panda/src/linmath/lvec3_ops_src.h @@ -48,11 +48,11 @@ cross(const FLOATNAME(LVector3) &a, const FLOATNAME(LVector3) &b); // Length of a vector. INLINE_LINMATH FLOATTYPE -length(const FLOATNAME(LVector3) &a); +length(const FLOATNAME(LVecBase3) &a); // A normalized vector. INLINE_LINMATH FLOATNAME(LVector3) -normalize(const FLOATNAME(LVector3) &v); +normalize(const FLOATNAME(LVecBase3) &v); INLINE_LINMATH void generic_write_datagram(Datagram &dest, const FLOATNAME(LVecBase3) &value); diff --git a/panda/src/linmath/lvecBase3_src.I b/panda/src/linmath/lvecBase3_src.I index de366c29a3..8a4daa6ccb 100644 --- a/panda/src/linmath/lvecBase3_src.I +++ b/panda/src/linmath/lvecBase3_src.I @@ -383,6 +383,49 @@ set(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) { _v.v._2 = z; } +//////////////////////////////////////////////////////////////////// +// Function: LVecBase3::length +// Access: Published +// Description: Returns the length of the vector, by the Pythagorean +// theorem. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase3):: +length() const { + return csqrt((*this).dot(*this)); +} + +//////////////////////////////////////////////////////////////////// +// Function: LVecBase3::length_squared +// Access: Published +// Description: Returns the square of the vector's length, cheap and +// easy. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase3):: +length_squared() const { + return (*this).dot(*this); +} + +//////////////////////////////////////////////////////////////////// +// Function: LVecBase3::normalize +// Access: Published +// Description: Normalizes the vector in place. Returns true if the +// vector was normalized, false if it was a zero-length +// vector. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH bool FLOATNAME(LVecBase3):: +normalize() { + FLOATTYPE l2 = length_squared(); + if (l2 == (FLOATTYPE)0.0f) { + set(0.0f, 0.0f, 0.0f); + return false; + + } else if (!IS_THRESHOLD_EQUAL(l2, 1.0f, (NEARLY_ZERO(FLOATTYPE) * NEARLY_ZERO(FLOATTYPE)))) { + (*this) /= csqrt(l2); + } + + return true; +} + //////////////////////////////////////////////////////////////////// // Function: LVecBase3::dot // Access: Published diff --git a/panda/src/linmath/lvecBase3_src.h b/panda/src/linmath/lvecBase3_src.h index 062f7f501c..969ec1f59f 100644 --- a/panda/src/linmath/lvecBase3_src.h +++ b/panda/src/linmath/lvecBase3_src.h @@ -78,6 +78,10 @@ PUBLISHED: INLINE_LINMATH void fill(FLOATTYPE fill_value); INLINE_LINMATH void set(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z); + INLINE_LINMATH FLOATTYPE length() const; + INLINE_LINMATH FLOATTYPE length_squared() const; + INLINE_LINMATH bool normalize(); + INLINE_LINMATH FLOATTYPE dot(const FLOATNAME(LVecBase3) &other) const; INLINE_LINMATH FLOATNAME(LVecBase3) cross(const FLOATNAME(LVecBase3) &other) const; diff --git a/panda/src/linmath/lvector3_src.I b/panda/src/linmath/lvector3_src.I index 459733f294..73aaf3bcf2 100644 --- a/panda/src/linmath/lvector3_src.I +++ b/panda/src/linmath/lvector3_src.I @@ -169,49 +169,6 @@ operator - (const FLOATNAME(LVector3) &other) const { return FLOATNAME(LVecBase3)::operator - (other); } -//////////////////////////////////////////////////////////////////// -// Function: LVector3::length -// Access: Published -// Description: Returns the length of the vector, by the Pythagorean -// theorem. -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATTYPE FLOATNAME(LVector3):: -length() const { - return csqrt((*this).dot(*this)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::length_squared -// Access: Published -// Description: Returns the square of the vector's length, cheap and -// easy. -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATTYPE FLOATNAME(LVector3):: -length_squared() const { - return (*this).dot(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::normalize -// Access: Published -// Description: Normalizes the vector in place. Returns true if the -// vector was normalized, false if it was a zero-length -// vector. -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH bool FLOATNAME(LVector3):: -normalize() { - FLOATTYPE l2 = length_squared(); - if (l2 == (FLOATTYPE)0.0f) { - set(0.0f, 0.0f, 0.0f); - return false; - - } else if (!IS_THRESHOLD_EQUAL(l2, 1.0f, (NEARLY_ZERO(FLOATTYPE) * NEARLY_ZERO(FLOATTYPE)))) { - (*this) /= csqrt(l2); - } - - return true; -} - //////////////////////////////////////////////////////////////////// // Function: LVector3::cross // Access: Published diff --git a/panda/src/linmath/lvector3_src.h b/panda/src/linmath/lvector3_src.h index 05bde9188b..030ed881b3 100644 --- a/panda/src/linmath/lvector3_src.h +++ b/panda/src/linmath/lvector3_src.h @@ -48,9 +48,6 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LVecBase3) operator - (const FLOATNAME(LVecBase3) &other) const; INLINE_LINMATH FLOATNAME(LVector3) operator - (const FLOATNAME(LVector3) &other) 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 FLOATTYPE angle_rad(const FLOATNAME(LVector3) &other) const; INLINE_LINMATH FLOATTYPE angle_deg(const FLOATNAME(LVector3) &other) const;