Browse Source

make normalize() and length() methods on LVecBase3f instead of just LVector3f

David Rose 20 years ago
parent
commit
34e47c5504

+ 2 - 2
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;

+ 2 - 2
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);

+ 43 - 0
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

+ 4 - 0
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;
 

+ 0 - 43
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

+ 0 - 3
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;