Browse Source

potential angle improvement for vector to vector checks)

Zachary Pavlov 18 years ago
parent
commit
a181b41465
2 changed files with 29 additions and 0 deletions
  1. 25 0
      panda/src/linmath/lvector3_src.I
  2. 4 0
      panda/src/linmath/lvector3_src.h

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

@@ -199,6 +199,31 @@ angle_rad(const FLOATNAME(LVector3) &other) const {
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: LVector::relative_angle_rad
+//       Access: Published
+//  Description: returns the signed angled between two vectors. 
+//               normalization is NOT necessary
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATTYPE FLOATNAME(LVector3)::
+relative_angle_rad(const FLOATNAME(LVector3) &other) const {
+  //okay, we'll 
+  return atan2((other._v.v._0*_v.v._1)-(other._v.v._1*_v.v._0), dot(other));
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: LVector::relative_angle_deg
+//       Access: Published
+//  Description: returns the signed angled between two vectors. 
+//               normalization is NOT necessary
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH FLOATTYPE FLOATNAME(LVector3)::
+relative_angle_deg(const FLOATNAME(LVector3) &other) const {
+  //okay, we'll 
+  return relative_angle_rad(other)*180/3.1415926535;
+}
+
+
 ////////////////////////////////////////////////////////////////////
 //     Function: LVector::angle_deg
 //       Access: Published

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

@@ -52,6 +52,10 @@ PUBLISHED:
   INLINE_LINMATH FLOATTYPE angle_rad(const FLOATNAME(LVector3) &other) const;
   INLINE_LINMATH FLOATTYPE angle_deg(const FLOATNAME(LVector3) &other) const;
 
+  INLINE_LINMATH FLOATTYPE relative_angle_rad(const FLOATNAME(LVector3) &other) const;
+  INLINE_LINMATH FLOATTYPE relative_angle_deg(const FLOATNAME(LVector3) &other) const;
+
+
   INLINE_LINMATH FLOATNAME(LVector3) operator * (FLOATTYPE scalar) const;
   INLINE_LINMATH FLOATNAME(LVector3) operator / (FLOATTYPE scalar) const;