more robustification

This commit is contained in:
David Rose 2002-06-21 21:59:42 +00:00
parent 4ea946cf40
commit efd134a00e
2 changed files with 42 additions and 4 deletions

View File

@ -187,6 +187,32 @@ set_from_matrix(const FLOATNAME(LMatrix4) &m) {
set_from_matrix(m.get_upper_3());
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternion::get_axis
// Access: Public
// Description: This, along with get_angle(), returns the rotation
// represented by the quaternion as an angle about an
// arbitrary axis. This returns the axis.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LQuaternion)::
get_axis() const {
return ::normalize(FLOATNAME(LVector3)(_v.data[1], _v.data[2], _v.data[3]));
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternion::get_angle
// Access: Public
// Description: This, along with get_axis(), returns the rotation
// represented by the quaternion as an angle about an
// arbitrary axis. This returns the angle, in degrees
// counterclockwise about the axis.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATTYPE FLOATNAME(LQuaternion)::
get_angle() const {
return rad_2_deg(acos(_v.data[0]) * 2.0);
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternion::get_r
// Access: public
@ -304,7 +330,7 @@ normalize() {
////////////////////////////////////////////////////////////////////
INLINE_LINMATH bool FLOATNAME(LQuaternion)::
invert_from(const FLOATNAME(LQuaternion) &other) {
set(other._v.v._0, -other._v.v._1, -other._v.v._2, -other._v.v._3);
set(-other._v.v._0, other._v.v._1, other._v.v._2, other._v.v._3);
return true;
}
@ -317,12 +343,20 @@ invert_from(const FLOATNAME(LQuaternion) &other) {
////////////////////////////////////////////////////////////////////
INLINE_LINMATH bool FLOATNAME(LQuaternion)::
invert_in_place() {
_v.v._1 = -_v.v._1;
_v.v._2 = -_v.v._2;
_v.v._3 = -_v.v._3;
_v.v._0 = -_v.v._0;
return true;
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternion::is_identity
// Access: Public
// Description: Returns true if this quaternion represents the
// identity transformation: no rotation.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH bool FLOATNAME(LQuaternion)::
is_identity() const {
return (IS_NEARLY_EQUAL(_v.v._0, -1.0f) || IS_NEARLY_EQUAL(_v.v._0, 1.0f));
}
////////////////////////////////////////////////////////////////////
// Function: LQuaternion::ident_quat

View File

@ -55,6 +55,9 @@ PUBLISHED:
void set_hpr(const FLOATNAME(LVecBase3) &hpr);
FLOATNAME(LVecBase3) get_hpr() const;
INLINE_LINMATH FLOATNAME(LVector3) get_axis() const;
INLINE_LINMATH FLOATTYPE get_angle() const;
INLINE_LINMATH FLOATTYPE get_r() const;
INLINE_LINMATH FLOATTYPE get_i() const;
INLINE_LINMATH FLOATTYPE get_j() const;
@ -70,6 +73,7 @@ PUBLISHED:
INLINE_LINMATH bool invert_from(const FLOATNAME(LQuaternion) &other);
INLINE_LINMATH bool invert_in_place();
INLINE_LINMATH bool is_identity() const;
INLINE_LINMATH static const FLOATNAME(LQuaternion) &ident_quat();
private: