From 52a0c84fce13471a875ce2ab780e8ac1dc311c79 Mon Sep 17 00:00:00 2001 From: David Rose Date: Sun, 23 Jan 2005 16:39:16 +0000 Subject: [PATCH] add LQuaternionf::get_forward(), fix angle_rad() --- panda/src/linmath/lquaternion_src.I | 49 ++++++++++++++++++++++++----- panda/src/linmath/lquaternion_src.h | 4 +++ 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/panda/src/linmath/lquaternion_src.I b/panda/src/linmath/lquaternion_src.I index 8ca6bb90e7..7997c43b38 100644 --- a/panda/src/linmath/lquaternion_src.I +++ b/panda/src/linmath/lquaternion_src.I @@ -107,21 +107,23 @@ operator - (const FLOATNAME(LQuaternion) &other) const { } //////////////////////////////////////////////////////////////////// -// Function: LVector::angle_rad +// Function: LQuaternion::angle_rad // Access: Published -// Description: Returns the angle between this quat and the other -// one, expressed in radians. +// Description: Returns the angle between the orientation represented +// by this quaternion and the other one, expressed in +// radians. //////////////////////////////////////////////////////////////////// INLINE_LINMATH FLOATTYPE FLOATNAME(LQuaternion):: angle_rad(const FLOATNAME(LQuaternion) &other) const { - return get_axis().angle_rad(other.get_axis()); + return get_forward().angle_rad(other.get_forward()); } //////////////////////////////////////////////////////////////////// -// Function: LVector::angle_deg +// Function: LQuaternion::angle_deg // Access: Published -// Description: Returns the angle between this vector and the other -// one, expressed in degrees. +// Description: Returns the angle between the orientation represented +// by this quaternion and the other one, expressed in +// degrees. //////////////////////////////////////////////////////////////////// INLINE_LINMATH FLOATTYPE FLOATNAME(LQuaternion):: angle_deg(const FLOATNAME(LQuaternion) &other) const { @@ -299,6 +301,39 @@ get_angle() const { return rad_2_deg(acos(_v.data[0]) * 2.0); } +//////////////////////////////////////////////////////////////////// +// Function: LQuaternion::get_up +// Access: Public +// Description: Returns the orientation represented by this +// quaternion, expressed as an up vector. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LQuaternion):: +get_up(CoordinateSystem cs) const { + return xform(FLOATNAME(LVector3)::up(cs)); +} + +//////////////////////////////////////////////////////////////////// +// Function: LQuaternion::get_right +// Access: Public +// Description: Returns the orientation represented by this +// quaternion, expressed as a right vector. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LQuaternion):: +get_right(CoordinateSystem cs) const { + return xform(FLOATNAME(LVector3)::right(cs)); +} + +//////////////////////////////////////////////////////////////////// +// Function: LQuaternion::get_forward +// Access: Public +// Description: Returns the orientation represented by this +// quaternion, expressed as a forward vector. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LQuaternion):: +get_forward(CoordinateSystem cs) const { + return xform(FLOATNAME(LVector3)::forward(cs)); +} + //////////////////////////////////////////////////////////////////// // Function: LQuaternion::get_r diff --git a/panda/src/linmath/lquaternion_src.h b/panda/src/linmath/lquaternion_src.h index 08365a99a5..0d4ed76789 100644 --- a/panda/src/linmath/lquaternion_src.h +++ b/panda/src/linmath/lquaternion_src.h @@ -73,6 +73,10 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LVector3) get_axis() const; INLINE_LINMATH FLOATTYPE get_angle() const; + INLINE_LINMATH FLOATNAME(LVector3) get_up(CoordinateSystem cs = CS_default) const; + INLINE_LINMATH FLOATNAME(LVector3) get_right(CoordinateSystem cs = CS_default) const; + INLINE_LINMATH FLOATNAME(LVector3) get_forward(CoordinateSystem cs = CS_default) const; + INLINE_LINMATH FLOATTYPE get_r() const; INLINE_LINMATH FLOATTYPE get_i() const; INLINE_LINMATH FLOATTYPE get_j() const;