diff --git a/doc/ReleaseNotes b/doc/ReleaseNotes index f3bebcc191..6320ff52a8 100644 --- a/doc/ReleaseNotes +++ b/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 Ctrl+C interrupt propagation to runtime applications * Support for InvSphere, Box and Tube solids in bam2egg +* Add normalized() method to vectors ------------------------ RELEASE 1.9.2 ------------------------ diff --git a/panda/src/linmath/lpoint2_src.I b/panda/src/linmath/lpoint2_src.I index a3f27084f6..ef38d96a96 100644 --- a/panda/src/linmath/lpoint2_src.I +++ b/panda/src/linmath/lpoint2_src.I @@ -186,6 +186,18 @@ operator / (FLOATTYPE scalar) const { } #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 // Access: Published diff --git a/panda/src/linmath/lpoint2_src.h b/panda/src/linmath/lpoint2_src.h index 5347325800..f426f733ba 100644 --- a/panda/src/linmath/lpoint2_src.h +++ b/panda/src/linmath/lpoint2_src.h @@ -51,6 +51,7 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LPoint2) operator / (FLOATTYPE scalar) const; #ifndef FLOATTYPE_IS_INT + INLINE_LINMATH FLOATNAME(LPoint2) normalized() const; INLINE_LINMATH FLOATNAME(LPoint2) project(const FLOATNAME(LVecBase2) &onto) const; #endif diff --git a/panda/src/linmath/lpoint3_src.I b/panda/src/linmath/lpoint3_src.I index 9f8143c7d7..21ff1be9f2 100644 --- a/panda/src/linmath/lpoint3_src.I +++ b/panda/src/linmath/lpoint3_src.I @@ -230,6 +230,18 @@ cross(const FLOATNAME(LVecBase3) &other) const { } #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 // Access: Published diff --git a/panda/src/linmath/lpoint3_src.h b/panda/src/linmath/lpoint3_src.h index e8645529ff..7cb4c4978e 100644 --- a/panda/src/linmath/lpoint3_src.h +++ b/panda/src/linmath/lpoint3_src.h @@ -61,6 +61,7 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LPoint3) cross(const FLOATNAME(LVecBase3) &other) const; #ifndef FLOATTYPE_IS_INT + INLINE_LINMATH FLOATNAME(LPoint3) normalized() const; INLINE_LINMATH FLOATNAME(LPoint3) project(const FLOATNAME(LVecBase3) &onto) const; #endif diff --git a/panda/src/linmath/lpoint4_src.I b/panda/src/linmath/lpoint4_src.I index d1a7e7b3ab..5bbe378f58 100644 --- a/panda/src/linmath/lpoint4_src.I +++ b/panda/src/linmath/lpoint4_src.I @@ -217,6 +217,19 @@ operator / (FLOATTYPE scalar) const { } #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 // Access: Published diff --git a/panda/src/linmath/lpoint4_src.h b/panda/src/linmath/lpoint4_src.h index 50eeb1ce5d..72c874035b 100644 --- a/panda/src/linmath/lpoint4_src.h +++ b/panda/src/linmath/lpoint4_src.h @@ -53,6 +53,7 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LPoint4) operator / (FLOATTYPE scalar) const; #ifndef FLOATTYPE_IS_INT + INLINE_LINMATH FLOATNAME(LPoint4) normalized() const; INLINE_LINMATH FLOATNAME(LPoint4) project(const FLOATNAME(LVecBase4) &onto) const; #endif diff --git a/panda/src/linmath/lvecBase2_src.I b/panda/src/linmath/lvecBase2_src.I index b561cb0b7a..45cdf2d661 100644 --- a/panda/src/linmath/lvecBase2_src.I +++ b/panda/src/linmath/lvecBase2_src.I @@ -418,6 +418,22 @@ normalize() { 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 // Access: Published diff --git a/panda/src/linmath/lvecBase2_src.h b/panda/src/linmath/lvecBase2_src.h index f1f6d125e0..4340a6a296 100644 --- a/panda/src/linmath/lvecBase2_src.h +++ b/panda/src/linmath/lvecBase2_src.h @@ -94,6 +94,7 @@ PUBLISHED: #ifndef FLOATTYPE_IS_INT INLINE_LINMATH FLOATTYPE length() const; INLINE_LINMATH bool normalize(); + INLINE_LINMATH FLOATNAME(LVecBase2) normalized() const; INLINE_LINMATH FLOATNAME(LVecBase2) project(const FLOATNAME(LVecBase2) &onto) const; #endif diff --git a/panda/src/linmath/lvecBase3_src.I b/panda/src/linmath/lvecBase3_src.I index 13310a8af1..ef3c6b8d04 100644 --- a/panda/src/linmath/lvecBase3_src.I +++ b/panda/src/linmath/lvecBase3_src.I @@ -509,6 +509,22 @@ normalize() { 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 // Access: Published diff --git a/panda/src/linmath/lvecBase3_src.h b/panda/src/linmath/lvecBase3_src.h index 1a4ec5ce97..b51e7c42e4 100644 --- a/panda/src/linmath/lvecBase3_src.h +++ b/panda/src/linmath/lvecBase3_src.h @@ -103,6 +103,7 @@ PUBLISHED: #ifndef FLOATTYPE_IS_INT INLINE_LINMATH FLOATTYPE length() const; INLINE_LINMATH bool normalize(); + INLINE_LINMATH FLOATNAME(LVecBase3) normalized() const; INLINE_LINMATH FLOATNAME(LVecBase3) project(const FLOATNAME(LVecBase3) &onto) const; #endif diff --git a/panda/src/linmath/lvecBase4_src.I b/panda/src/linmath/lvecBase4_src.I index 5b42095e93..e1b76ccf92 100644 --- a/panda/src/linmath/lvecBase4_src.I +++ b/panda/src/linmath/lvecBase4_src.I @@ -559,6 +559,22 @@ normalize() { 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 // Access: Published diff --git a/panda/src/linmath/lvecBase4_src.h b/panda/src/linmath/lvecBase4_src.h index 988d31b859..d9511fee0e 100644 --- a/panda/src/linmath/lvecBase4_src.h +++ b/panda/src/linmath/lvecBase4_src.h @@ -113,6 +113,7 @@ PUBLISHED: #ifndef FLOATTYPE_IS_INT INLINE_LINMATH FLOATTYPE length() const; INLINE_LINMATH bool normalize(); + INLINE_LINMATH FLOATNAME(LVecBase4) normalized() const; INLINE_LINMATH FLOATNAME(LVecBase4) project(const FLOATNAME(LVecBase4) &onto) const; #endif diff --git a/panda/src/linmath/lvector2_src.I b/panda/src/linmath/lvector2_src.I index 45c7975fea..def84b52a1 100644 --- a/panda/src/linmath/lvector2_src.I +++ b/panda/src/linmath/lvector2_src.I @@ -175,6 +175,18 @@ operator / (FLOATTYPE scalar) const { } #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 // Access: Published diff --git a/panda/src/linmath/lvector2_src.h b/panda/src/linmath/lvector2_src.h index 2ee50d34ab..c63e11b2aa 100644 --- a/panda/src/linmath/lvector2_src.h +++ b/panda/src/linmath/lvector2_src.h @@ -44,6 +44,7 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LVector2) operator / (FLOATTYPE scalar) const; #ifndef FLOATTYPE_IS_INT + INLINE_LINMATH FLOATNAME(LVector2) normalized() 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_deg(const FLOATNAME(LVector2) &other) const; diff --git a/panda/src/linmath/lvector3_src.I b/panda/src/linmath/lvector3_src.I index 318d32d2c9..e04e4531f0 100644 --- a/panda/src/linmath/lvector3_src.I +++ b/panda/src/linmath/lvector3_src.I @@ -220,6 +220,19 @@ cross(const FLOATNAME(LVecBase3) &other) const { } #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 // Access: Published diff --git a/panda/src/linmath/lvector3_src.h b/panda/src/linmath/lvector3_src.h index 7e0dd196bb..4d0a6f69c8 100644 --- a/panda/src/linmath/lvector3_src.h +++ b/panda/src/linmath/lvector3_src.h @@ -55,6 +55,7 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LVector3) cross(const FLOATNAME(LVecBase3) &other) const; #ifndef FLOATTYPE_IS_INT + INLINE_LINMATH FLOATNAME(LVector3) normalized() 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_deg(const FLOATNAME(LVector3) &other) const; diff --git a/panda/src/linmath/lvector4_src.I b/panda/src/linmath/lvector4_src.I index 78333268f4..0423b63cf7 100644 --- a/panda/src/linmath/lvector4_src.I +++ b/panda/src/linmath/lvector4_src.I @@ -207,6 +207,19 @@ operator / (FLOATTYPE scalar) const { } #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 // Access: Published diff --git a/panda/src/linmath/lvector4_src.h b/panda/src/linmath/lvector4_src.h index ebf87429f6..5f149d92fe 100644 --- a/panda/src/linmath/lvector4_src.h +++ b/panda/src/linmath/lvector4_src.h @@ -47,6 +47,7 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LVector4) operator / (FLOATTYPE scalar) const; #ifndef FLOATTYPE_IS_INT + INLINE_LINMATH FLOATNAME(LVector4) normalized() const; INLINE_LINMATH FLOATNAME(LVector4) project(const FLOATNAME(LVecBase4) &onto) const; #endif