Prechádzať zdrojové kódy

deprecate relative_angle_deg, add signed_angle_deg

David Rose 17 rokov pred
rodič
commit
812356e83d

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

@@ -20,6 +20,7 @@
 #include "coordinateSystem.h"
 #include "lvecBase3.h"
 #include "lvector3.h"
+#include "lpoint2.h"
 
 #include "fltnames.h"
 #include "lpoint3_src.h"

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

@@ -115,6 +115,39 @@ unit_z() {
   return (const FLOATNAME(LPoint3) &)FLOATNAME(LVecBase3)::unit_z();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: LPoint3::get_xy
+//       Access: Public
+//  Description: Returns a 2-component vector that shares just the
+//               first two components of this vector.
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATNAME(LPoint2) FLOATNAME(LPoint3)::
+get_xy() const {
+  return FLOATNAME(LPoint2)(_v.v._0, _v.v._1);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: LPoint3::get_xz
+//       Access: Public
+//  Description: Returns a 2-component vector that shares just the
+//               first and last components of this vector.
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATNAME(LPoint2) FLOATNAME(LPoint3)::
+get_xz() const {
+  return FLOATNAME(LPoint2)(_v.v._0, _v.v._2);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: LPoint3::get_yz
+//       Access: Public
+//  Description: Returns a 2-component vector that shares just the
+//               last two components of this vector.
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATNAME(LPoint2) FLOATNAME(LPoint3)::
+get_yz() const {
+  return FLOATNAME(LPoint2)(_v.v._1, _v.v._2);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: LPoint3::unary -
 //       Access: Public

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

@@ -36,6 +36,10 @@ PUBLISHED:
   INLINE_LINMATH static const FLOATNAME(LPoint3) &unit_y();
   INLINE_LINMATH static const FLOATNAME(LPoint3) &unit_z();
 
+  INLINE_LINMATH FLOATNAME(LPoint2) get_xy() const;
+  INLINE_LINMATH FLOATNAME(LPoint2) get_xz() const;
+  INLINE_LINMATH FLOATNAME(LPoint2) get_yz() const;
+
   INLINE_LINMATH FLOATNAME(LPoint3) operator - () const;
 
   INLINE_LINMATH FLOATNAME(LVecBase3)

+ 2 - 0
panda/src/linmath/lvecBase2.h

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

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

@@ -23,6 +23,7 @@
 #include "checksumHashGenerator.h"
 #include "mathNumbers.h"
 #include "deg_2_rad.h"
+#include "lvecBase2.h"
 
 #include "cmath.h"
 #include "nearly_zero.h"

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

@@ -273,6 +273,39 @@ set_z(FLOATTYPE value) {
   _v.v._2 = value;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: LVecBase3::get_xy
+//       Access: Public
+//  Description: Returns a 2-component vector that shares just the
+//               first two components of this vector.
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVecBase3)::
+get_xy() const {
+  return FLOATNAME(LVecBase2)(_v.v._0, _v.v._1);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: LVecBase3::get_xz
+//       Access: Public
+//  Description: Returns a 2-component vector that shares just the
+//               first and last components of this vector.
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVecBase3)::
+get_xz() const {
+  return FLOATNAME(LVecBase2)(_v.v._0, _v.v._2);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: LVecBase3::get_yz
+//       Access: Public
+//  Description: Returns a 2-component vector that shares just the
+//               last two components of this vector.
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVecBase3)::
+get_yz() const {
+  return FLOATNAME(LVecBase2)(_v.v._1, _v.v._2);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: LVecBase3::add_to_cell
 //       Access: Public

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

@@ -56,6 +56,10 @@ PUBLISHED:
   INLINE_LINMATH void set_y(FLOATTYPE value);
   INLINE_LINMATH void set_z(FLOATTYPE value);
 
+  INLINE_LINMATH FLOATNAME(LVecBase2) get_xy() const;
+  INLINE_LINMATH FLOATNAME(LVecBase2) get_xz() const;
+  INLINE_LINMATH FLOATNAME(LVecBase2) get_yz() const;
+
   // These next functions add to an existing value.
   // i.e. foo.set_x(foo.get_x() + value)
   // These are useful to reduce overhead in scripting

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

@@ -218,6 +218,29 @@ operator / (FLOATTYPE scalar) const {
   return FLOATNAME(LVector2)(FLOATNAME(LVecBase2)::operator * (recip_scalar));
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: LVector2::signed_angle_rad
+//       Access: Published
+//  Description: returns the signed angled between two vectors. 
+//               normalization is NOT necessary
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATTYPE FLOATNAME(LVector2)::
+signed_angle_rad(const FLOATNAME(LVector2) &other) const {
+  return catan2((_v.v._0*other._v.v._1)-(_v.v._1*other._v.v._0), dot(other));
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: LVector2::signed_angle_deg
+//       Access: Published
+//  Description: returns the signed angled between two vectors. 
+//               normalization is NOT necessary
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATTYPE FLOATNAME(LVector2)::
+signed_angle_deg(const FLOATNAME(LVector2) &other) const {
+  return rad_2_deg(signed_angle_rad(other));
+}
+
+
 #ifdef HAVE_PYTHON
 ////////////////////////////////////////////////////////////////////
 //     Function: LVector2::python_repr

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

@@ -43,6 +43,9 @@ PUBLISHED:
   INLINE_LINMATH FLOATNAME(LVector2) operator * (FLOATTYPE scalar) const;
   INLINE_LINMATH FLOATNAME(LVector2) operator / (FLOATTYPE scalar) const;
 
+  INLINE_LINMATH FLOATTYPE signed_angle_rad(const FLOATNAME(LVector2) &other) const;
+  INLINE_LINMATH FLOATTYPE signed_angle_deg(const FLOATNAME(LVector2) &other) const;
+
 #ifdef HAVE_PYTHON
   INLINE_LINMATH void python_repr(ostream &out, const string &class_name) const;
 #endif

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

@@ -21,6 +21,7 @@
 #include "cmath.h"
 #include "config_linmath.h"
 #include "lvecBase3.h"
+#include "lvector2.h"
 
 #include "fltnames.h"
 #include "lvector3_src.h"

+ 87 - 19
panda/src/linmath/lvector3_src.I

@@ -115,6 +115,39 @@ unit_z() {
   return (const FLOATNAME(LVector3) &)FLOATNAME(LVecBase3)::unit_z();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: LVector3::get_xy
+//       Access: Public
+//  Description: Returns a 2-component vector that shares just the
+//               first two components of this vector.
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector3)::
+get_xy() const {
+  return FLOATNAME(LVector2)(_v.v._0, _v.v._1);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: LVector3::get_xz
+//       Access: Public
+//  Description: Returns a 2-component vector that shares just the
+//               first and last components of this vector.
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector3)::
+get_xz() const {
+  return FLOATNAME(LVector2)(_v.v._0, _v.v._2);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: LVector3::get_yz
+//       Access: Public
+//  Description: Returns a 2-component vector that shares just the
+//               last two components of this vector.
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector3)::
+get_yz() const {
+  return FLOATNAME(LVector2)(_v.v._1, _v.v._2);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: LVector3::unary -
 //       Access: Published
@@ -178,9 +211,9 @@ cross(const FLOATNAME(LVecBase3) &other) const {
 ////////////////////////////////////////////////////////////////////
 //     Function: LVector::angle_rad
 //       Access: Published
-//  Description: Returns the angle between this vector and the other
-//               one, expressed in radians.  Both vectors should be
-//               initially normalized.
+//  Description: Returns the unsigned angle between this vector and
+//               the other one, expressed in radians.  Both vectors
+//               should be initially normalized.
 ////////////////////////////////////////////////////////////////////
 INLINE_LINMATH FLOATTYPE FLOATNAME(LVector3)::
 angle_rad(const FLOATNAME(LVector3) &other) const {
@@ -196,38 +229,73 @@ angle_rad(const FLOATNAME(LVector3) &other) const {
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: LVector::relative_angle_rad
+//     Function: LVector::angle_deg
 //       Access: Published
-//  Description: returns the signed angled between two vectors. 
-//               normalization is NOT necessary
+//  Description: Returns the angle between this vector and the other
+//               one, expressed in degrees.  Both vectors should be
+//               initially normalized.
 ////////////////////////////////////////////////////////////////////
 INLINE_LINMATH FLOATTYPE FLOATNAME(LVector3)::
-relative_angle_rad(const FLOATNAME(LVector3) &other) const {
-  return atan2((_v.v._0*other._v.v._1)-(_v.v._1*other._v.v._0), dot(other));
+angle_deg(const FLOATNAME(LVector3) &other) const {
+  return rad_2_deg(angle_rad(other));
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: LVector::relative_angle_deg
+//     Function: LVector::signed_angle_rad
 //       Access: Published
-//  Description: returns the signed angled between two vectors. 
-//               normalization is NOT necessary
+//  Description: returns the signed angle between two vectors.
+//               The angle is positive if the rotation from this
+//               vector to other is clockwise when looking in the
+//               direction of the ref vector.
+//
+//               Vectors (except the ref vector) should be initially
+//               normalized.
 ////////////////////////////////////////////////////////////////////
 INLINE_LINMATH FLOATTYPE FLOATNAME(LVector3)::
-relative_angle_deg(const FLOATNAME(LVector3) &other) const {
-  return relative_angle_rad(other)*180/3.1415926535;
+signed_angle_rad(const FLOATNAME(LVector3) &other, 
+                 const FLOATNAME(LVector3) &ref) const {
+  FLOATTYPE angle = angle_rad(other);
+  if (cross(other).dot(ref) < 0.0f) {
+    angle = -angle;
+  }
+  return angle;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: LVector::signed_angle_deg
+//       Access: Published
+//  Description: Returns the signed angle between two vectors. 
+//               The angle is positive if the rotation from this
+//               vector to other is clockwise when looking in the
+//               direction of the ref vector.
+//
+//               Vectors (except the ref vector) should be initially
+//               normalized.
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATTYPE FLOATNAME(LVector3)::
+signed_angle_deg(const FLOATNAME(LVector3) &other,
+                 const FLOATNAME(LVector3) &ref) const {
+  return rad_2_deg(signed_angle_rad(other, ref));
+}
 
 ////////////////////////////////////////////////////////////////////
-//     Function: LVector::angle_deg
+//     Function: LVector::relative_angle_rad
 //       Access: Published
-//  Description: Returns the angle between this vector and the other
-//               one, expressed in degrees.  Both vectors should be
-//               initially normalized.
+//  Description: This method is deprecated.  Do not use.
 ////////////////////////////////////////////////////////////////////
 INLINE_LINMATH FLOATTYPE FLOATNAME(LVector3)::
-angle_deg(const FLOATNAME(LVector3) &other) const {
-  return rad_2_deg(angle_rad(other));
+relative_angle_rad(const FLOATNAME(LVector3) &other) const {
+  return atan2((_v.v._0*other._v.v._1)-(_v.v._1*other._v.v._0), dot(other));
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: LVector::relative_angle_deg
+//       Access: Published
+//  Description: This method is deprecated.  Do not use.
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATTYPE FLOATNAME(LVector3)::
+relative_angle_deg(const FLOATNAME(LVector3) &other) const {
+  return relative_angle_rad(other)*180/3.1415926535;
 }
 
 ////////////////////////////////////////////////////////////////////

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

@@ -36,6 +36,10 @@ PUBLISHED:
   INLINE_LINMATH static const FLOATNAME(LVector3) &unit_y();
   INLINE_LINMATH static const FLOATNAME(LVector3) &unit_z();
 
+  INLINE_LINMATH FLOATNAME(LVector2) get_xy() const;
+  INLINE_LINMATH FLOATNAME(LVector2) get_xz() const;
+  INLINE_LINMATH FLOATNAME(LVector2) get_yz() const;
+
   INLINE_LINMATH FLOATNAME(LVector3) operator - () const;
 
   INLINE_LINMATH FLOATNAME(LVecBase3) operator + (const FLOATNAME(LVecBase3) &other) const;
@@ -48,6 +52,11 @@ PUBLISHED:
   INLINE_LINMATH FLOATTYPE angle_rad(const FLOATNAME(LVector3) &other) const;
   INLINE_LINMATH FLOATTYPE angle_deg(const FLOATNAME(LVector3) &other) const;
 
+  INLINE_LINMATH FLOATTYPE signed_angle_rad(const FLOATNAME(LVector3) &other,
+                                            const FLOATNAME(LVector3) &ref) const;
+  INLINE_LINMATH FLOATTYPE signed_angle_deg(const FLOATNAME(LVector3) &other,
+                                            const FLOATNAME(LVector3) &ref) const;
+
   INLINE_LINMATH FLOATTYPE relative_angle_rad(const FLOATNAME(LVector3) &other) const;
   INLINE_LINMATH FLOATTYPE relative_angle_deg(const FLOATNAME(LVector3) &other) const;