This is the base quaternion class. More...

Inheritance diagram for LQuaternionf:
LVecBase4f LOrientationf LRotationf

Public Member Functions

 __init__ ()
 
 __init__ (const LQuaternionf)
 
 __init__ (const LVecBase4f copy)
 
 __init__ (float r, const LVecBase3f copy)
 
 __init__ (float r, float i, float j, float k)
 
bool almostEqual (const LQuaternionf other)
 Returns true if two quaternions are memberwise equal within a default tolerance based on the numeric type. More...
 
bool almostEqual (const LQuaternionf other, float threshold)
 Returns true if two quaternions are memberwise equal within a specified tolerance. More...
 
bool almostSameDirection (const LQuaternionf other, float threshold)
 Returns true if two quaternions represent the same rotation within a specified tolerance. More...
 
float angleDeg (const LQuaternionf other)
 Returns the angle between the orientation represented by this quaternion and the other one, expressed in degrees. More...
 
float angleRad (const LQuaternionf other)
 Returns the angle between the orientation represented by this quaternion and the other one, expressed in radians. More...
 
LQuaternionf conjugate ()
 Returns the complex conjugate of this quat. More...
 
bool conjugateFrom (const LQuaternionf other)
 Computes the conjugate of the other quat, and stores the result in this quat. More...
 
bool conjugateInPlace ()
 Sets this to be the conjugate of the current quat. More...
 
 extractToMatrix (LMatrix3f m)
 Based on the quat lib from VRPN. More...
 
 extractToMatrix (LMatrix4f m)
 Based on the quat lib from VRPN. More...
 
float getAngle ()
 This, along with get_axis(), returns the rotation represented by the quaternion as an angle about an arbitrary axis. More...
 
float getAngleRad ()
 This, along with get_axis(), returns the rotation represented by the quaternion as an angle about an arbitrary axis. More...
 
LVector3f getAxis ()
 This, along with get_angle(), returns the rotation represented by the quaternion as an angle about an arbitrary axis. More...
 
LVector3f getAxisNormalized ()
 This, along with get_angle(), returns the rotation represented by the quaternion as an angle about an arbitrary axis. More...
 
LVector3f getForward (CoordinateSystem cs)
 Returns the orientation represented by this quaternion, expressed as a forward vector. More...
 
LVecBase3f getHpr (CoordinateSystem cs)
 Extracts the equivalent Euler angles from the unit quaternion. More...
 
float getI ()
 
float getJ ()
 
float getK ()
 
float getR ()
 
LVector3f getRight (CoordinateSystem cs)
 Returns the orientation represented by this quaternion, expressed as a right vector. More...
 
LVector3f getUp (CoordinateSystem cs)
 Returns the orientation represented by this quaternion, expressed as an up vector. More...
 
bool invertFrom (const LQuaternionf other)
 Computes the inverse of the other quat, and stores the result in this quat. More...
 
bool invertInPlace ()
 Inverts the current quat. More...
 
bool isAlmostIdentity (float tolerance)
 Returns true if this quaternion represents the identity transformation within a given tolerance. More...
 
bool isIdentity ()
 Returns true if this quaternion represents the identity transformation: no rotation. More...
 
bool isSameDirection (const LQuaternionf other)
 Returns true if two quaternions represent the same rotation within a default tolerance based on the numeric type. More...
 
LQuaternionf multiply (const LQuaternionf rhs)
 actual multiply call (non virtual) More...
 
bool normalize ()
 
LMatrix3f operator* (const LMatrix3f)
 
LMatrix4f operator* (const LMatrix4f)
 
LQuaternionf operator* (const LQuaternionf)
 
LQuaternionf operator* (float scalar)
 
LQuaternionf operator*= (const LQuaternionf)
 
LQuaternionf operator+ (const LQuaternionf other)
 
LQuaternionf operator- ()
 
LQuaternionf operator- (const LQuaternionf other)
 
LQuaternionf operator/ (float scalar)
 
 output (Ostream)
 
 setFromAxisAngle (float angle_deg, const LVector3f axis)
 angle_deg is the angle about the axis in degrees. More...
 
 setFromAxisAngleRad (float angle_rad, const LVector3f axis)
 angle_rad is the angle about the axis in radians. More...
 
 setFromMatrix (const LMatrix3f m)
 Sets the quaternion according to the rotation represented by the matrix. More...
 
 setFromMatrix (const LMatrix4f m)
 
 setHpr (const LVecBase3f hpr, CoordinateSystem cs)
 Sets the quaternion as the unit quaternion that is equivalent to these Euler angles. More...
 
 setI (float i)
 
 setJ (float j)
 
 setK (float k)
 
 setR (float r)
 
LVecBase3f xform (const LVecBase3f v)
 Transforms a 3-d vector by the indicated rotation. More...
 
LVecBase4f xform (const LVecBase4f v)
 Transforms a 4-d vector by the indicated rotation. More...
 
- Public Member Functions inherited from LVecBase4f
object __getattr__ (str attr_name)
 
 __init__ ()
 
 __init__ (const LPoint3f point)
 Constructs an LVecBase4 from an LPoint3. More...
 
 __init__ (const LVecBase3f copy, float w)
 
 __init__ (const LVecBase4f)
 
 __init__ (const LVector3f vector)
 Constructs an LVecBase4 from an LVector3. More...
 
 __init__ (const UnalignedLVecBase4f copy)
 
 __init__ (float fill_value)
 
 __init__ (float x, float y, float z, float w)
 
object __ipow__ (float exponent)
 
LVecBase4f __pow__ (float exponent)
 
object __reduce__ ()
 
str __repr__ ()
 
int __setattr__ (str attr_name, object assign)
 
size_t addHash (size_t hash)
 Adds the vector into the running hash. More...
 
size_t addHash (size_t hash, float threshold)
 Adds the vector into the running hash. More...
 
 addToCell (int i, float value)
 
 addW (float value)
 
 addX (float value)
 
 addY (float value)
 
 addZ (float value)
 
bool almostEqual (const LVecBase4f other)
 Returns true if two vectors are memberwise equal within a default tolerance based on the numeric type. More...
 
bool almostEqual (const LVecBase4f other, float threshold)
 Returns true if two vectors are memberwise equal within a specified tolerance. More...
 
int compareTo (const LVecBase4f other)
 This flavor of compare_to uses a default threshold value based on the numeric type. More...
 
int compareTo (const LVecBase4f other, float threshold)
 Sorts vectors lexicographically, componentwise. More...
 
 componentwiseMult (const LVecBase4f other)
 
float dot (const LVecBase4f other)
 
 fill (float fill_value)
 Sets each element of the vector to the indicated fill_value. More...
 
LVecBase4f fmax (const LVecBase4f other)
 
LVecBase4f fmin (const LVecBase4f other)
 
 generateHash (ChecksumHashGenerator hashgen)
 Adds the vector to the indicated hash generator. More...
 
 generateHash (ChecksumHashGenerator hashgen, float threshold)
 Adds the vector to the indicated hash generator. More...
 
float getCell (int i)
 
 getData ()
 Returns the address of the first of the four data elements in the vector. More...
 
size_t getHash ()
 Returns a suitable hash for phash_map. More...
 
size_t getHash (float threshold)
 Returns a suitable hash for phash_map. More...
 
float getW ()
 
float getX ()
 
LVecBase2f getXy ()
 Returns the x and y component of this vector. More...
 
LVecBase3f getXyz ()
 Returns the x, y and z component of this vector. More...
 
float getY ()
 
float getZ ()
 
bool isNan ()
 Returns true if any component of the vector is not-a-number, false otherwise. More...
 
float length ()
 Returns the length of the vector, by the Pythagorean theorem. More...
 
float lengthSquared ()
 Returns the square of the vector's length, cheap and easy. More...
 
bool normalize ()
 Normalizes the vector in place. More...
 
LVecBase4f normalized ()
 Normalizes the vector and returns the normalized vector as a copy. More...
 
 operator new (size_t size)
 
bool operator!= (const LVecBase4f other)
 
LVecBase4f operator* (float scalar)
 
LVecBase4f operator*= (float scalar)
 
LVecBase4f operator+ (const LVecBase4f other)
 
LVecBase4f operator+= (const LVecBase4f other)
 
LVecBase4f operator- ()
 
LVecBase4f operator- (const LVecBase4f other)
 
LVecBase4f operator-= (const LVecBase4f other)
 
LVecBase4f operator/ (float scalar)
 
LVecBase4f operator/= (float scalar)
 
bool operator< (const LVecBase4f other)
 
LVecBase4f operator= (const LVecBase4f copy)
 
LVecBase4f operator= (float fill_value)
 
bool operator== (const LVecBase4f other)
 
 operator[] (int i, float assign_val)
 
float operator[] (int i)
 
 output (Ostream out)
 
LVecBase4f project (const LVecBase4f onto)
 Returns a new vector representing the projection of this vector onto another one. More...
 
 readDatagram (DatagramIterator source)
 Reads the vector from the Datagram using get_stdfloat(). More...
 
 readDatagramFixed (DatagramIterator source)
 Reads the vector from the Datagram using get_float32() or get_float64(). More...
 
 set (float x, float y, float z, float w)
 
 setCell (int i, float value)
 
 setW (float value)
 
 setX (float value)
 
 setY (float value)
 
 setZ (float value)
 
 writeDatagram (Datagram destination)
 Writes the vector to the Datagram using add_stdfloat(). More...
 
 writeDatagramFixed (Datagram destination)
 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 getClassType ()
 
static const LQuaternionf identQuat ()
 Returns an identity quaternion. More...
 
static LQuaternionf pureImaginary (const LVector3f v)
 
- Static Public Member Functions inherited from LVecBase4f
static TypeHandle getClassType ()
 
static int getNumComponents ()
 
static int size ()
 
static const LVecBase4f unitW ()
 Returns a unit W vector. More...
 
static const LVecBase4f unitX ()
 Returns a unit X vector. More...
 
static const LVecBase4f unitY ()
 Returns a unit Y vector. More...
 
static const LVecBase4f unitZ ()
 Returns a unit Z vector. More...
 
static const LVecBase4f zero ()
 Returns a zero-length vector. More...
 

Additional Inherited Members

- Public Types inherited from LVecBase4f
enum  { num_components = 4, is_int = 0 }
 
- Public Attributes inherited from LVecBase4f
float x
 
LVecBase2f xy
 
LVecBase3f xyz
 
float y
 
float z
 

Detailed Description

This is the base quaternion class.

Member Function Documentation

__init__ ( )
__init__ ( const LQuaternionf  )
__init__ ( const LVecBase4f  copy)
__init__ ( float  r,
const LVecBase3f  copy 
)
__init__ ( float  r,
float  i,
float  j,
float  k 
)
bool almostEqual ( const LQuaternionf  other)

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

bool almostEqual ( const LQuaternionf  other,
float  threshold 
)

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

bool almostSameDirection ( const LQuaternionf  other,
float  threshold 
)

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

float angleDeg ( const LQuaternionf  other)

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

float angleRad ( const LQuaternionf  other)

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

LQuaternionf conjugate ( )

Returns the complex conjugate of this quat.

bool conjugateFrom ( const LQuaternionf  other)

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.

bool conjugateInPlace ( )

Sets this to be the conjugate of the current quat.

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

extractToMatrix ( LMatrix3f  m)

Based on the quat lib from VRPN.

extractToMatrix ( LMatrix4f  m)

Based on the quat lib from VRPN.

float getAngle ( )

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.

float getAngleRad ( )

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.

LVector3f getAxis ( )

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.

LVector3f getAxisNormalized ( )

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

This returns the normalized axis.

static TypeHandle getClassType ( )
static
LVector3f getForward ( CoordinateSystem  cs)

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

LVecBase3f getHpr ( CoordinateSystem  cs)

Extracts the equivalent Euler angles from the unit quaternion.

float getI ( )
float getJ ( )
float getK ( )
float getR ( )
LVector3f getRight ( CoordinateSystem  cs)

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

LVector3f getUp ( CoordinateSystem  cs)

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

static const LQuaternionf identQuat ( )
static

Returns an identity quaternion.

bool invertFrom ( const LQuaternionf  other)

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.

bool invertInPlace ( )

Inverts the current quat.

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

bool isAlmostIdentity ( float  tolerance)

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

bool isIdentity ( )

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

bool isSameDirection ( const LQuaternionf  other)

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

LQuaternionf multiply ( const LQuaternionf  rhs)

actual multiply call (non virtual)

bool normalize ( )
LMatrix3f operator* ( const LMatrix3f  )
LMatrix4f operator* ( const LMatrix4f  )
LQuaternionf operator* ( const LQuaternionf  )
LQuaternionf operator* ( float  scalar)
LQuaternionf operator*= ( const LQuaternionf  )
LQuaternionf operator+ ( const LQuaternionf  other)
LQuaternionf operator- ( )
LQuaternionf operator- ( const LQuaternionf  other)
LQuaternionf operator/ ( float  scalar)
output ( Ostream  )
static LQuaternionf pureImaginary ( const LVector3f  v)
static
setFromAxisAngle ( float  angle_deg,
const LVector3f  axis 
)

angle_deg is the angle about the axis in degrees.

axis must be normalized.

setFromAxisAngleRad ( float  angle_rad,
const LVector3f  axis 
)

angle_rad is the angle about the axis in radians.

axis must be normalized.

setFromMatrix ( 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.

setFromMatrix ( const LMatrix4f  m)
setHpr ( const LVecBase3f  hpr,
CoordinateSystem  cs 
)

Sets the quaternion as the unit quaternion that is equivalent to these Euler angles.

(from Real-time Rendering, p.49)

setI ( float  i)
setJ ( float  j)
setK ( float  k)
setR ( float  r)
LVecBase3f xform ( const LVecBase3f  v)

Transforms a 3-d vector by the indicated rotation.

LVecBase4f xform ( const LVecBase4f  v)

Transforms a 4-d vector by the indicated rotation.