Panda3D
Public Member Functions | Static Public Member Functions | List of all members
LQuaternionf Class Reference

This is the base quaternion class. More...

#include "lquaternion.h"

Inheritance diagram for LQuaternionf:
LVecBase4f LOrientationf LRotationf

Public Member Functions

 LQuaternionf (const LVecBase4f &copy)
 
 LQuaternionf (float r, const LVecBase3f &copy)
 
 LQuaternionf (float r, float i, float j, float k)
 
bool almost_equal (const LQuaternionf &other) const
 Returns true if two quaternions are memberwise equal within a default tolerance based on the numeric type. More...
 
bool almost_equal (const LQuaternionf &other, float threshold) const
 Returns true if two quaternions are memberwise equal within a specified tolerance. More...
 
bool almost_same_direction (const LQuaternionf &other, float threshold) const
 Returns true if two quaternions represent the same rotation within a specified tolerance. More...
 
float angle_deg (const LQuaternionf &other) const
 Returns the angle between the orientation represented by this quaternion and the other one, expressed in degrees. More...
 
float angle_rad (const LQuaternionf &other) const
 Returns the angle between the orientation represented by this quaternion and the other one, expressed in radians. More...
 
LQuaternionf conjugate () const
 Returns the complex conjugate of this quat. More...
 
bool conjugate_from (const LQuaternionf &other)
 Computes the conjugate of the other quat, and stores the result in this quat. More...
 
bool conjugate_in_place ()
 Sets this to be the conjugate of the current quat. More...
 
void extract_to_matrix (LMatrix3f &m) const
 Based on the quat lib from VRPN. More...
 
void extract_to_matrix (LMatrix4f &m) const
 Based on the quat lib from VRPN. More...
 
float get_angle () const
 This, along with get_axis(), returns the rotation represented by the quaternion as an angle about an arbitrary axis. More...
 
float get_angle_rad () const
 This, along with get_axis(), returns the rotation represented by the quaternion as an angle about an arbitrary axis. More...
 
LVector3f get_axis () const
 This, along with get_angle(), returns the rotation represented by the quaternion as an angle about an arbitrary axis. More...
 
LVector3f get_axis_normalized () const
 This, along with get_angle(), returns the rotation represented by the quaternion as an angle about an arbitrary axis. More...
 
LVector3f get_forward (CoordinateSystem cs=CS_default) const
 Returns the orientation represented by this quaternion, expressed as a forward vector. More...
 
LVecBase3f get_hpr (CoordinateSystem cs=CS_default) const
 Extracts the equivalent Euler angles from the unit quaternion. More...
 
float get_i () const
 
float get_j () const
 
float get_k () const
 
float get_r () const
 
LVector3f get_right (CoordinateSystem cs=CS_default) const
 Returns the orientation represented by this quaternion, expressed as a right vector. More...
 
LVector3f get_up (CoordinateSystem cs=CS_default) const
 Returns the orientation represented by this quaternion, expressed as an up vector. More...
 
bool invert_from (const LQuaternionf &other)
 Computes the inverse of the other quat, and stores the result in this quat. More...
 
bool invert_in_place ()
 Inverts the current quat. More...
 
bool is_almost_identity (float tolerance) const
 Returns true if this quaternion represents the identity transformation within a given tolerance. More...
 
bool is_identity () const
 Returns true if this quaternion represents the identity transformation: no rotation. More...
 
bool is_same_direction (const LQuaternionf &other) const
 Returns true if two quaternions represent the same rotation within a default tolerance based on the numeric type. More...
 
LQuaternionf multiply (const LQuaternionf &rhs) const
 actual multiply call (non virtual) More...
 
bool normalize ()
 
LQuaternionf operator* (float scalar) const
 
LQuaternionf operator* (const LQuaternionf &) const
 
LMatrix3f operator* (const LMatrix3f &)
 Quat * Matrix = matrix. More...
 
LMatrix4f operator* (const LMatrix4f &)
 Quat * Matrix = matrix. More...
 
LQuaternionfoperator*= (const LQuaternionf &)
 
LQuaternionf operator+ (const LQuaternionf &other) const
 
LQuaternionf operator- () const
 
LQuaternionf operator- (const LQuaternionf &other) const
 
LQuaternionf operator/ (float scalar) const
 
void output (ostream &) const
 
void set_from_axis_angle (float angle_deg, const LVector3f &axis)
 angle_deg is the angle about the axis in degrees. More...
 
void set_from_axis_angle_rad (float angle_rad, const LVector3f &axis)
 angle_rad is the angle about the axis in radians. More...
 
void set_from_matrix (const LMatrix3f &m)
 Sets the quaternion according to the rotation represented by the matrix. More...
 
void set_from_matrix (const LMatrix4f &m)
 
void set_hpr (const LVecBase3f &hpr, CoordinateSystem cs=CS_default)
 Sets the quaternion as the unit quaternion that is equivalent to these Euler angles. More...
 
void set_i (float i)
 
void set_j (float j)
 
void set_k (float k)
 
void set_r (float r)
 
LVecBase3f xform (const LVecBase3f &v) const
 Transforms a 3-d vector by the indicated rotation. More...
 
LVecBase4f xform (const LVecBase4f &v) const
 Transforms a 4-d vector by the indicated rotation. More...
 
- Public Member Functions inherited from LVecBase4f
 LVecBase4f (const LVecBase4f &copy)
 
 LVecBase4f (const UnalignedLVecBase4f &copy)
 
 LVecBase4f (float fill_value)
 
 LVecBase4f (float x, float y, float z, float w)
 
 LVecBase4f (const LVecBase3f &copy, float w)
 
 LVecBase4f (const LPoint3f &point)
 Constructs an LVecBase4 from an LPoint3. More...
 
 LVecBase4f (const LVector3f &vector)
 Constructs an LVecBase4 from an LVector3. More...
 
 LVecBase4f (const EVector4 &v)
 
size_t add_hash (size_t hash) const
 Adds the vector into the running hash. More...
 
size_t add_hash (size_t hash, float threshold) const
 Adds the vector into the running hash. More...
 
void add_to_cell (int i, float value)
 
void add_w (float value)
 
void add_x (float value)
 
void add_y (float value)
 
void add_z (float value)
 
bool almost_equal (const LVecBase4f &other, float threshold) const
 Returns true if two vectors are memberwise equal within a specified tolerance. More...
 
bool almost_equal (const LVecBase4f &other) const
 Returns true if two vectors are memberwise equal within a default tolerance based on the numeric type. More...
 
iterator begin ()
 Returns an iterator that may be used to traverse the elements of the matrix, STL-style. More...
 
const_iterator begin () const
 Returns an iterator that may be used to traverse the elements of the matrix, STL-style. More...
 
int compare_to (const LVecBase4f &other) const
 This flavor of compare_to uses a default threshold value based on the numeric type. More...
 
int compare_to (const LVecBase4f &other, float threshold) const
 Sorts vectors lexicographically, componentwise. More...
 
void componentwise_mult (const LVecBase4f &other)
 
float dot (const LVecBase4f &other) const
 
iterator end ()
 Returns an iterator that may be used to traverse the elements of the matrix, STL-style. More...
 
const_iterator end () const
 Returns an iterator that may be used to traverse the elements of the matrix, STL-style. More...
 
void extract_data (float *)
 
void fill (float fill_value)
 Sets each element of the vector to the indicated fill_value. More...
 
LVecBase4f fmax (const LVecBase4f &other) const
 
LVecBase4f fmin (const LVecBase4f &other) const
 
void generate_hash (ChecksumHashGenerator &hashgen) const
 Adds the vector to the indicated hash generator. More...
 
void generate_hash (ChecksumHashGenerator &hashgen, float threshold) const
 Adds the vector to the indicated hash generator. More...
 
float get_cell (int i) const
 
const float * get_data () const
 Returns the address of the first of the four data elements in the vector. More...
 
size_t get_hash () const
 Returns a suitable hash for phash_map. More...
 
size_t get_hash (float threshold) const
 Returns a suitable hash for phash_map. More...
 
int get_num_components () const
 Returns the number of elements in the vector, four. More...
 
float get_w () const
 
float get_x () const
 
float get_y () const
 
float get_z () const
 
bool is_nan () const
 Returns true if any component of the vector is not-a-number, false otherwise. More...
 
float length () const
 Returns the length of the vector, by the Pythagorean theorem. More...
 
float length_squared () const
 Returns the square of the vector's length, cheap and easy. More...
 
bool normalize ()
 Normalizes the vector in place. More...
 
LVecBase4f normalized () const
 Normalizes the vector and returns the normalized vector as a copy. More...
 
bool operator!= (const LVecBase4f &other) const
 
LVecBase4f operator* (float scalar) const
 
void operator*= (float scalar)
 
LVecBase4f operator+ (const LVecBase4f &other) const
 
void operator+= (const LVecBase4f &other)
 
LVecBase4f operator- () const
 
LVecBase4f operator- (const LVecBase4f &other) const
 
void operator-= (const LVecBase4f &other)
 
LVecBase4f operator/ (float scalar) const
 
void operator/= (float scalar)
 
bool operator< (const LVecBase4f &other) const
 This performs a lexicographical comparison. More...
 
LVecBase4foperator= (const LVecBase4f &copy)
 
LVecBase4foperator= (const UnalignedLVecBase4f &copy)
 
LVecBase4foperator= (float fill_value)
 
bool operator== (const LVecBase4f &other) const
 
float operator[] (int i) const
 
float & operator[] (int i)
 
void output (ostream &out) const
 
LVecBase4f project (const LVecBase4f &onto) const
 Returns a new vector representing the projection of this vector onto another one. More...
 
void read_datagram (DatagramIterator &source)
 Reads the vector from the Datagram using get_stdfloat(). More...
 
void read_datagram_fixed (DatagramIterator &source)
 Reads the vector from the Datagram using get_float32() or get_float64(). More...
 
void set (float x, float y, float z, float w)
 
void set_cell (int i, float value)
 
void set_w (float value)
 
void set_x (float value)
 
void set_y (float value)
 
void set_z (float value)
 
void write_datagram (Datagram &destination) const
 Writes the vector to the Datagram using add_stdfloat(). More...
 
void write_datagram_fixed (Datagram &destination) const
 Writes the vector to the Datagram using add_float32() or add_float64(), depending on the type of floats in the vector, regardless of the setting of Datagram::set_stdfloat_double(). More...
 

Static Public Member Functions

static TypeHandle get_class_type ()
 
static const LQuaternionfident_quat ()
 Returns an identity quaternion. More...
 
static void init_type ()
 
static LQuaternionf pure_imaginary (const LVector3f &v)
 
- Static Public Member Functions inherited from LVecBase4f
static TypeHandle get_class_type ()
 
static void init_type ()
 
static int size ()
 Returns 4: the number of components of a LVecBase4. More...
 
static const LVecBase4funit_w ()
 Returns a unit W vector. More...
 
static const LVecBase4funit_x ()
 Returns a unit X vector. More...
 
static const LVecBase4funit_y ()
 Returns a unit Y vector. More...
 
static const LVecBase4funit_z ()
 Returns a unit Z vector. More...
 
static const LVecBase4fzero ()
 Returns a zero-length vector. More...
 

Additional Inherited Members

- Public Types inherited from LVecBase4f
enum  { num_components = 4, is_int = 0 }
 
typedef const float * const_iterator
 
typedef LSimpleMatrix< float, 1, 4 > EVector4
 
typedef const float * iterator
 
typedef float numeric_type
 
- Public Attributes inherited from LVecBase4f
EVector4 _v
 

Detailed Description

This is the base quaternion class.

Definition at line 96 of file lquaternion.h.

Member Function Documentation

◆ almost_equal() [1/2]

bool LQuaternionf::almost_equal ( const LQuaternionf other) const
inline

Returns true if two quaternions are memberwise equal within a default tolerance based on the numeric type.

Definition at line 454 of file lquaternion.h.

◆ almost_equal() [2/2]

bool LQuaternionf::almost_equal ( const LQuaternionf other,
float  threshold 
) const
inline

Returns true if two quaternions are memberwise equal within a specified tolerance.

Definition at line 465 of file lquaternion.h.

◆ almost_same_direction()

bool LQuaternionf::almost_same_direction ( const LQuaternionf other,
float  threshold 
) const
inline

Returns true if two quaternions represent the same rotation within a specified tolerance.

Definition at line 492 of file lquaternion.h.

References LMatrix4f::get_upper_3().

◆ angle_deg()

float LQuaternionf::angle_deg ( const LQuaternionf other) const
inline

Returns the angle between the orientation represented by this quaternion and the other one, expressed in degrees.

Definition at line 371 of file lquaternion.h.

◆ angle_rad()

float LQuaternionf::angle_rad ( const LQuaternionf other) const
inline

Returns the angle between the orientation represented by this quaternion and the other one, expressed in radians.

Definition at line 359 of file lquaternion.h.

References get_forward().

Referenced by CLerpNodePathInterval::priv_reverse_instant().

◆ conjugate()

LQuaternionf LQuaternionf::conjugate ( ) const
inline

Returns the complex conjugate of this quat.

Definition at line 745 of file lquaternion.h.

◆ conjugate_from()

bool LQuaternionf::conjugate_from ( const LQuaternionf other)
inline

Computes the conjugate of the other quat, and stores the result in this quat.

This is a fully general operation and makes no assumptions about the type of transform represented by the quat.

The other quat must be a different object than this quat. However, if you need to get a conjugate of a quat in place, see conjugate_in_place.

The return value is true if the quat was successfully inverted, false if there was a singularity.

Definition at line 766 of file lquaternion.h.

◆ conjugate_in_place()

bool LQuaternionf::conjugate_in_place ( )
inline

Sets this to be the conjugate of the current quat.

Returns true if the successful, false if the quat was singular.

Definition at line 779 of file lquaternion.h.

◆ extract_to_matrix() [1/2]

void LQuaternionf::extract_to_matrix ( LMatrix3f m) const

◆ extract_to_matrix() [2/2]

void LQuaternionf::extract_to_matrix ( LMatrix4f m) const

Based on the quat lib from VRPN.

Definition at line 129 of file lquaternion.cxx.

◆ get_angle()

float LQuaternionf::get_angle ( ) const
inline

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.

It is necessary to ensure the quaternion has been normalized (for instance, with a call to normalize()) before calling this method.

Definition at line 577 of file lquaternion.h.

◆ get_angle_rad()

float LQuaternionf::get_angle_rad ( ) const
inline

This, along with get_axis(), returns the rotation represented by the quaternion as an angle about an arbitrary axis.

This returns the angle, in radians counterclockwise about the axis.

It is necessary to ensure the quaternion has been normalized (for instance, with a call to normalize()) before calling this method.

Definition at line 560 of file lquaternion.h.

◆ get_axis()

LVector3f LQuaternionf::get_axis ( ) const
inline

This, along with get_angle(), returns the rotation represented by the quaternion as an angle about an arbitrary axis.

This returns the axis; it is not normalized.

Definition at line 529 of file lquaternion.h.

◆ get_axis_normalized()

LVector3f LQuaternionf::get_axis_normalized ( ) const
inline

This, along with get_angle(), returns the rotation represented by the quaternion as an angle about an arbitrary axis.

This returns the normalized axis.

Definition at line 541 of file lquaternion.h.

◆ get_forward()

LVector3f LQuaternionf::get_forward ( CoordinateSystem  cs = CS_default) const
inline

Returns the orientation represented by this quaternion, expressed as a forward vector.

Definition at line 637 of file lquaternion.h.

Referenced by angle_rad(), and LQuaterniond::angle_rad().

◆ get_hpr()

LVecBase3f LQuaternionf::get_hpr ( CoordinateSystem  cs = CS_default) const

Extracts the equivalent Euler angles from the unit quaternion.

Definition at line 207 of file lquaternion.cxx.

Referenced by CLerpNodePathInterval::priv_step(), CLerpNodePathInterval::set_end_hpr(), and PhysicsObject::write().

◆ get_right()

LVector3f LQuaternionf::get_right ( CoordinateSystem  cs = CS_default) const
inline

Returns the orientation represented by this quaternion, expressed as a right vector.

Definition at line 626 of file lquaternion.h.

◆ get_up()

LVector3f LQuaternionf::get_up ( CoordinateSystem  cs = CS_default) const
inline

Returns the orientation represented by this quaternion, expressed as an up vector.

Definition at line 615 of file lquaternion.h.

◆ ident_quat()

const LQuaternionf & LQuaternionf::ident_quat ( )
inlinestatic

◆ invert_from()

bool LQuaternionf::invert_from ( const LQuaternionf other)
inline

Computes the inverse of the other quat, and stores the result in this quat.

This is a fully general operation and makes no assumptions about the type of transform represented by the quat.

The other quat must be a different object than this quat. However, if you need to invert a quat in place, see invert_in_place.

The return value is true if the quat was successfully inverted, false if there was a singularity.

Definition at line 804 of file lquaternion.h.

◆ invert_in_place()

bool LQuaternionf::invert_in_place ( )
inline

Inverts the current quat.

Returns true if the inverse is successful, false if the quat was singular.

Definition at line 817 of file lquaternion.h.

◆ is_almost_identity()

bool LQuaternionf::is_almost_identity ( float  tolerance) const
inline

Returns true if this quaternion represents the identity transformation within a given tolerance.

Definition at line 840 of file lquaternion.h.

◆ is_identity()

bool LQuaternionf::is_identity ( ) const
inline

Returns true if this quaternion represents the identity transformation: no rotation.

Definition at line 829 of file lquaternion.h.

Referenced by EggSaver::add_node().

◆ is_same_direction()

bool LQuaternionf::is_same_direction ( const LQuaternionf other) const
inline

Returns true if two quaternions represent the same rotation within a default tolerance based on the numeric type.

Definition at line 481 of file lquaternion.h.

◆ multiply()

LQuaternionf LQuaternionf::multiply ( const LQuaternionf rhs) const
inline

actual multiply call (non virtual)

Definition at line 312 of file lquaternion.h.

◆ operator*() [1/2]

LMatrix3f LQuaternionf::operator* ( const LMatrix3f m)
inline

Quat * Matrix = matrix.

Definition at line 422 of file lquaternion.h.

◆ operator*() [2/2]

LMatrix4f LQuaternionf::operator* ( const LMatrix4f m)
inline

Quat * Matrix = matrix.

Definition at line 434 of file lquaternion.h.

References LMatrix4f::get_col(), LMatrix4f::get_row(), and LMatrix4f::get_upper_3().

◆ set_from_axis_angle()

void LQuaternionf::set_from_axis_angle ( float  angle_deg,
const LVector3f axis 
)
inline

angle_deg is the angle about the axis in degrees.

axis must be normalized.

Definition at line 604 of file lquaternion.h.

Referenced by PhysicsObject::add_impact().

◆ set_from_axis_angle_rad()

void LQuaternionf::set_from_axis_angle_rad ( float  angle_rad,
const LVector3f axis 
)
inline

angle_rad is the angle about the axis in radians.

axis must be normalized.

Definition at line 588 of file lquaternion.h.

References LVecBase3f::length().

◆ set_from_matrix()

void LQuaternionf::set_from_matrix ( const LMatrix3f m)

Sets the quaternion according to the rotation represented by the matrix.

Originally we tried an algorithm presented by Do-While Jones, but that turned out to be broken. This is based on the quat lib from UNC.

Definition at line 311 of file lquaternion.cxx.

References TypeHandle::none().

◆ set_hpr()

void LQuaternionf::set_hpr ( const LVecBase3f hpr,
CoordinateSystem  cs = CS_default 
)

◆ xform() [1/2]

LVecBase3f LQuaternionf::xform ( const LVecBase3f v) const
inline

◆ xform() [2/2]

LVecBase4f LQuaternionf::xform ( const LVecBase4f v) const
inline

Transforms a 4-d vector by the indicated rotation.

Definition at line 296 of file lquaternion.h.


The documentation for this class was generated from the following files: