Browse Source

Backport normalized() method to 1.9 branch

rdb 9 years ago
parent
commit
558f84a95f

+ 1 - 0
doc/ReleaseNotes

@@ -32,6 +32,7 @@ This issue fixes several bugs that were still found in 1.9.2.
 * Fix RAM caching of 2D texture arrays
 * Fix RAM caching of 2D texture arrays
 * Fix Ctrl+C interrupt propagation to runtime applications
 * Fix Ctrl+C interrupt propagation to runtime applications
 * Support for InvSphere, Box and Tube solids in bam2egg
 * Support for InvSphere, Box and Tube solids in bam2egg
+* Add normalized() method to vectors
 
 
 ------------------------  RELEASE 1.9.2  ------------------------
 ------------------------  RELEASE 1.9.2  ------------------------
 
 

+ 12 - 0
panda/src/linmath/lpoint2_src.I

@@ -186,6 +186,18 @@ operator / (FLOATTYPE scalar) const {
 }
 }
 
 
 #ifndef FLOATTYPE_IS_INT
 #ifndef FLOATTYPE_IS_INT
+////////////////////////////////////////////////////////////////////
+//     Function: LPoint2::normalized
+//       Access: Published
+//  Description: Normalizes the vector and returns the normalized
+//               vector as a copy. If the vector was a zero-length
+//               vector, a zero length vector will be returned.
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATNAME(LPoint2) FLOATNAME(LPoint2)::
+normalized() const {
+  return FLOATNAME(LVecBase2)::normalized();
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: LPoint2::project
 //     Function: LPoint2::project
 //       Access: Published
 //       Access: Published

+ 1 - 0
panda/src/linmath/lpoint2_src.h

@@ -51,6 +51,7 @@ PUBLISHED:
   INLINE_LINMATH FLOATNAME(LPoint2) operator / (FLOATTYPE scalar) const;
   INLINE_LINMATH FLOATNAME(LPoint2) operator / (FLOATTYPE scalar) const;
 
 
 #ifndef FLOATTYPE_IS_INT
 #ifndef FLOATTYPE_IS_INT
+  INLINE_LINMATH FLOATNAME(LPoint2) normalized() const;
   INLINE_LINMATH FLOATNAME(LPoint2) project(const FLOATNAME(LVecBase2) &onto) const;
   INLINE_LINMATH FLOATNAME(LPoint2) project(const FLOATNAME(LVecBase2) &onto) const;
 #endif
 #endif
 
 

+ 12 - 0
panda/src/linmath/lpoint3_src.I

@@ -230,6 +230,18 @@ cross(const FLOATNAME(LVecBase3) &other) const {
 }
 }
 
 
 #ifndef FLOATTYPE_IS_INT
 #ifndef FLOATTYPE_IS_INT
+////////////////////////////////////////////////////////////////////
+//     Function: LPoint3::normalized
+//       Access: Published
+//  Description: Normalizes the vector and returns the normalized
+//               vector as a copy. If the vector was a zero-length
+//               vector, a zero length vector will be returned.
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATNAME(LPoint3) FLOATNAME(LPoint3)::
+normalized() const {
+  return FLOATNAME(LVecBase3)::normalized();
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: LPoint3::project
 //     Function: LPoint3::project
 //       Access: Published
 //       Access: Published

+ 1 - 0
panda/src/linmath/lpoint3_src.h

@@ -61,6 +61,7 @@ PUBLISHED:
   INLINE_LINMATH FLOATNAME(LPoint3) cross(const FLOATNAME(LVecBase3) &other) const;
   INLINE_LINMATH FLOATNAME(LPoint3) cross(const FLOATNAME(LVecBase3) &other) const;
 
 
 #ifndef FLOATTYPE_IS_INT
 #ifndef FLOATTYPE_IS_INT
+  INLINE_LINMATH FLOATNAME(LPoint3) normalized() const;
   INLINE_LINMATH FLOATNAME(LPoint3) project(const FLOATNAME(LVecBase3) &onto) const;
   INLINE_LINMATH FLOATNAME(LPoint3) project(const FLOATNAME(LVecBase3) &onto) const;
 #endif
 #endif
 
 

+ 13 - 0
panda/src/linmath/lpoint4_src.I

@@ -217,6 +217,19 @@ operator / (FLOATTYPE scalar) const {
 }
 }
 
 
 #ifndef FLOATTYPE_IS_INT
 #ifndef FLOATTYPE_IS_INT
+
+////////////////////////////////////////////////////////////////////
+//     Function: LPoint4::normalized
+//       Access: Published
+//  Description: Normalizes the vector and returns the normalized
+//               vector as a copy. If the vector was a zero-length
+//               vector, a zero length vector will be returned.
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATNAME(LPoint4) FLOATNAME(LPoint4)::
+normalized() const {
+  return FLOATNAME(LVecBase4)::normalized();
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: LPoint4::project
 //     Function: LPoint4::project
 //       Access: Published
 //       Access: Published

+ 1 - 0
panda/src/linmath/lpoint4_src.h

@@ -53,6 +53,7 @@ PUBLISHED:
   INLINE_LINMATH FLOATNAME(LPoint4) operator / (FLOATTYPE scalar) const;
   INLINE_LINMATH FLOATNAME(LPoint4) operator / (FLOATTYPE scalar) const;
 
 
 #ifndef FLOATTYPE_IS_INT
 #ifndef FLOATTYPE_IS_INT
+  INLINE_LINMATH FLOATNAME(LPoint4) normalized() const;
   INLINE_LINMATH FLOATNAME(LPoint4) project(const FLOATNAME(LVecBase4) &onto) const;
   INLINE_LINMATH FLOATNAME(LPoint4) project(const FLOATNAME(LVecBase4) &onto) const;
 #endif
 #endif
 
 

+ 16 - 0
panda/src/linmath/lvecBase2_src.I

@@ -418,6 +418,22 @@ normalize() {
   return true;
   return true;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: LVecBase2::normalized
+//       Access: Published
+//  Description: Normalizes the vector and returns the normalized
+//               vector as a copy. If the vector was a zero-length
+//               vector, a zero length vector will be returned.
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVecBase2)::
+normalized() const {
+  FLOATTYPE l2 = length_squared();
+  if (l2 == (FLOATTYPE)0.0f) {
+    return FLOATNAME(LVecBase2)(0.0f);
+  }
+  return (*this) / csqrt(l2);
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: LVecBase2::project
 //     Function: LVecBase2::project
 //       Access: Published
 //       Access: Published

+ 1 - 0
panda/src/linmath/lvecBase2_src.h

@@ -94,6 +94,7 @@ PUBLISHED:
 #ifndef FLOATTYPE_IS_INT
 #ifndef FLOATTYPE_IS_INT
   INLINE_LINMATH FLOATTYPE length() const;
   INLINE_LINMATH FLOATTYPE length() const;
   INLINE_LINMATH bool normalize();
   INLINE_LINMATH bool normalize();
+  INLINE_LINMATH FLOATNAME(LVecBase2) normalized() const;
   INLINE_LINMATH FLOATNAME(LVecBase2) project(const FLOATNAME(LVecBase2) &onto) const;
   INLINE_LINMATH FLOATNAME(LVecBase2) project(const FLOATNAME(LVecBase2) &onto) const;
 #endif
 #endif
 
 

+ 16 - 0
panda/src/linmath/lvecBase3_src.I

@@ -509,6 +509,22 @@ normalize() {
   return true;
   return true;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: LVecBase3::normalized
+//       Access: Published
+//  Description: Normalizes the vector and returns the normalized
+//               vector as a copy. If the vector was a zero-length
+//               vector, a zero length vector will be returned.
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
+normalized() const {
+  FLOATTYPE l2 = length_squared();
+  if (l2 == (FLOATTYPE)0.0f) {
+    return FLOATNAME(LVecBase3)(0.0f);
+  }
+  return (*this) / csqrt(l2);
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: LVecBase3::project
 //     Function: LVecBase3::project
 //       Access: Published
 //       Access: Published

+ 1 - 0
panda/src/linmath/lvecBase3_src.h

@@ -103,6 +103,7 @@ PUBLISHED:
 #ifndef FLOATTYPE_IS_INT
 #ifndef FLOATTYPE_IS_INT
   INLINE_LINMATH FLOATTYPE length() const;
   INLINE_LINMATH FLOATTYPE length() const;
   INLINE_LINMATH bool normalize();
   INLINE_LINMATH bool normalize();
+  INLINE_LINMATH FLOATNAME(LVecBase3) normalized() const;
   INLINE_LINMATH FLOATNAME(LVecBase3) project(const FLOATNAME(LVecBase3) &onto) const;
   INLINE_LINMATH FLOATNAME(LVecBase3) project(const FLOATNAME(LVecBase3) &onto) const;
 #endif
 #endif
 
 

+ 16 - 0
panda/src/linmath/lvecBase4_src.I

@@ -559,6 +559,22 @@ normalize() {
   return true;
   return true;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: LVecBase4::normalized
+//       Access: Published
+//  Description: Normalizes the vector and returns the normalized
+//               vector as a copy. If the vector was a zero-length
+//               vector, a zero length vector will be returned.
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::
+normalized() const {
+  FLOATTYPE l2 = length_squared();
+  if (l2 == (FLOATTYPE)0.0f) {
+    return FLOATNAME(LVecBase4)(0.0f);
+  }
+  return (*this) / csqrt(l2);
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: LVecBase4::project
 //     Function: LVecBase4::project
 //       Access: Published
 //       Access: Published

+ 1 - 0
panda/src/linmath/lvecBase4_src.h

@@ -113,6 +113,7 @@ PUBLISHED:
 #ifndef FLOATTYPE_IS_INT
 #ifndef FLOATTYPE_IS_INT
   INLINE_LINMATH FLOATTYPE length() const;
   INLINE_LINMATH FLOATTYPE length() const;
   INLINE_LINMATH bool normalize();
   INLINE_LINMATH bool normalize();
+  INLINE_LINMATH FLOATNAME(LVecBase4) normalized() const;
   INLINE_LINMATH FLOATNAME(LVecBase4) project(const FLOATNAME(LVecBase4) &onto) const;
   INLINE_LINMATH FLOATNAME(LVecBase4) project(const FLOATNAME(LVecBase4) &onto) const;
 #endif
 #endif
 
 

+ 12 - 0
panda/src/linmath/lvector2_src.I

@@ -175,6 +175,18 @@ operator / (FLOATTYPE scalar) const {
 }
 }
 
 
 #ifndef FLOATTYPE_IS_INT
 #ifndef FLOATTYPE_IS_INT
+////////////////////////////////////////////////////////////////////
+//     Function: LVector2::normalized
+//       Access: Published
+//  Description: Normalizes the vector and returns the normalized
+//               vector as a copy. If the vector was a zero-length
+//               vector, a zero length vector will be returned.
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector2)::
+normalized() const {
+  return FLOATNAME(LVecBase2)::normalized();
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: LVector2::project
 //     Function: LVector2::project
 //       Access: Published
 //       Access: Published

+ 1 - 0
panda/src/linmath/lvector2_src.h

@@ -44,6 +44,7 @@ PUBLISHED:
   INLINE_LINMATH FLOATNAME(LVector2) operator / (FLOATTYPE scalar) const;
   INLINE_LINMATH FLOATNAME(LVector2) operator / (FLOATTYPE scalar) const;
 
 
 #ifndef FLOATTYPE_IS_INT
 #ifndef FLOATTYPE_IS_INT
+  INLINE_LINMATH FLOATNAME(LVector2) normalized() const;
   INLINE_LINMATH FLOATNAME(LVector2) project(const FLOATNAME(LVecBase2) &onto) const;
   INLINE_LINMATH FLOATNAME(LVector2) project(const FLOATNAME(LVecBase2) &onto) const;
   INLINE_LINMATH FLOATTYPE signed_angle_rad(const FLOATNAME(LVector2) &other) const;
   INLINE_LINMATH FLOATTYPE signed_angle_rad(const FLOATNAME(LVector2) &other) const;
   INLINE_LINMATH FLOATTYPE signed_angle_deg(const FLOATNAME(LVector2) &other) const;
   INLINE_LINMATH FLOATTYPE signed_angle_deg(const FLOATNAME(LVector2) &other) const;

+ 13 - 0
panda/src/linmath/lvector3_src.I

@@ -220,6 +220,19 @@ cross(const FLOATNAME(LVecBase3) &other) const {
 }
 }
 
 
 #ifndef FLOATTYPE_IS_INT
 #ifndef FLOATTYPE_IS_INT
+
+////////////////////////////////////////////////////////////////////
+//     Function: LVector3::normalized
+//       Access: Published
+//  Description: Normalizes the vector and returns the normalized
+//               vector as a copy. If the vector was a zero-length
+//               vector, a zero length vector will be returned.
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3)::
+normalized() const {
+  return FLOATNAME(LVecBase3)::normalized();
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: LVector3::project
 //     Function: LVector3::project
 //       Access: Published
 //       Access: Published

+ 1 - 0
panda/src/linmath/lvector3_src.h

@@ -55,6 +55,7 @@ PUBLISHED:
   INLINE_LINMATH FLOATNAME(LVector3) cross(const FLOATNAME(LVecBase3) &other) const;
   INLINE_LINMATH FLOATNAME(LVector3) cross(const FLOATNAME(LVecBase3) &other) const;
 
 
 #ifndef FLOATTYPE_IS_INT
 #ifndef FLOATTYPE_IS_INT
+  INLINE_LINMATH FLOATNAME(LVector3) normalized() const;
   INLINE_LINMATH FLOATNAME(LVector3) project(const FLOATNAME(LVecBase3) &onto) const;
   INLINE_LINMATH FLOATNAME(LVector3) project(const FLOATNAME(LVecBase3) &onto) const;
   INLINE_LINMATH FLOATTYPE angle_rad(const FLOATNAME(LVector3) &other) const;
   INLINE_LINMATH FLOATTYPE angle_rad(const FLOATNAME(LVector3) &other) const;
   INLINE_LINMATH FLOATTYPE angle_deg(const FLOATNAME(LVector3) &other) const;
   INLINE_LINMATH FLOATTYPE angle_deg(const FLOATNAME(LVector3) &other) const;

+ 13 - 0
panda/src/linmath/lvector4_src.I

@@ -207,6 +207,19 @@ operator / (FLOATTYPE scalar) const {
 }
 }
 
 
 #ifndef FLOATTYPE_IS_INT
 #ifndef FLOATTYPE_IS_INT
+
+////////////////////////////////////////////////////////////////////
+//     Function: LVector4::normalized
+//       Access: Published
+//  Description: Normalizes the vector and returns the normalized
+//               vector as a copy. If the vector was a zero-length
+//               vector, a zero length vector will be returned.
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATNAME(LVector4) FLOATNAME(LVector4)::
+normalized() const {
+  return FLOATNAME(LVecBase4)::normalized();
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: LVector4::project
 //     Function: LVector4::project
 //       Access: Published
 //       Access: Published

+ 1 - 0
panda/src/linmath/lvector4_src.h

@@ -47,6 +47,7 @@ PUBLISHED:
   INLINE_LINMATH FLOATNAME(LVector4) operator / (FLOATTYPE scalar) const;
   INLINE_LINMATH FLOATNAME(LVector4) operator / (FLOATTYPE scalar) const;
 
 
 #ifndef FLOATTYPE_IS_INT
 #ifndef FLOATTYPE_IS_INT
+  INLINE_LINMATH FLOATNAME(LVector4) normalized() const;
   INLINE_LINMATH FLOATNAME(LVector4) project(const FLOATNAME(LVecBase4) &onto) const;
   INLINE_LINMATH FLOATNAME(LVector4) project(const FLOATNAME(LVecBase4) &onto) const;
 #endif
 #endif