Panda3D
Public Member Functions | Static Public Member Functions

Quat Class Reference

This is the base quaternion class. More...

Inheritance diagram for Quat:
VBase4 LOrientationf LRotationf

List of all members.

Public Member Functions

 Quat ()
 Quat (VBase4 const copy)
 Quat (float, float, float, float)
 Quat (float, VBase3 const copy)
unsigned int addHash (unsigned int hash)
 Adds the vector into the running hash.
unsigned int addHash (unsigned int hash, float threshold)
 Adds the vector into the running hash.
 addToCell (int i, float value)
 addW (float value)
 addX (float value)
 addY (float value)
 addZ (float value)
bool almostEqual (Quat const other, float threshold)
 Returns true if two quaternions are memberwise equal within a specified tolerance.
bool almostEqual (Quat const other)
 Returns true if two quaternions are memberwise equal within a default tolerance based on the numeric type.
bool almostEqual (VBase4 const other)
 Returns true if two vectors are memberwise equal within a default tolerance based on the numeric type.
bool almostEqual (VBase4 const other, float threshold)
 Returns true if two vectors are memberwise equal within a specified tolerance.
bool almostSameDirection (Quat const other, float threshold)
 Returns true if two quaternions represent the same rotation within a specified tolerance.
float angleDeg (Quat const other)
 Returns the angle between the orientation represented by this quaternion and the other one, expressed in degrees.
float angleRad (Quat const other)
 Returns the angle between the orientation represented by this quaternion and the other one, expressed in radians.
int compareTo (VBase4 const other)
 This flavor of compare_to uses a default threshold value based on the numeric type.
int compareTo (VBase4 const other, float threshold)
 Sorts vectors lexicographically, componentwise.
Quat conjugate ()
 Returns the complex conjugate of this quat.
bool conjugateFrom (Quat const other)
 Computes the conjugate of the other quat, and stores the result in this quat.
bool conjugateInPlace ()
 Sets this to be the conjugate of the current quat.
float dot (VBase4 const other)
 extractToMatrix (Mat3 m)
 Based on the quat lib from VRPN.
 extractToMatrix (Mat4 m)
 Based on the quat lib from VRPN.
 fill (float fill_value)
 Sets each element of the vector to the indicated fill_value.
VBase4 fmax (VBase4 const other)
VBase4 fmin (VBase4 const other)
float getAngle ()
 This, along with get_axis(), returns the rotation represented by the quaternion as an angle about an arbitrary axis.
float getAngleRad ()
 This, along with get_axis(), returns the rotation represented by the quaternion as an angle about an arbitrary axis.
PyObject getattr (string attr_name)
 This is used to implement swizzle masks.
Vec3 getAxis ()
 This, along with get_angle(), returns the rotation represented by the quaternion as an angle about an arbitrary axis.
Vec3 getAxisNormalized ()
 This, along with get_angle(), returns the rotation represented by the quaternion as an angle about an arbitrary axis.
float getCell (int i)
 getData ()
 Returns the address of the first of the four data elements in the vector.
Vec3 getForward (CoordinateSystem cs)
 Returns the orientation represented by this quaternion, expressed as a forward vector.
Vec3 getForward ()
 Returns the orientation represented by this quaternion, expressed as a forward vector.
unsigned int getHash (float threshold)
 Returns a suitable hash for phash_map.
unsigned int getHash ()
 Returns a suitable hash for phash_map.
VBase3 getHpr ()
 Extracts the equivalent Euler angles from the unit quaternion.
VBase3 getHpr (CoordinateSystem cs)
 Extracts the equivalent Euler angles from the unit quaternion.
float getI ()
float getJ ()
float getK ()
int getNumComponents ()
 Returns the number of elements in the vector, four.
float getR ()
Vec3 getRight (CoordinateSystem cs)
 Returns the orientation represented by this quaternion, expressed as a right vector.
Vec3 getRight ()
 Returns the orientation represented by this quaternion, expressed as a right vector.
Vec3 getUp (CoordinateSystem cs)
 Returns the orientation represented by this quaternion, expressed as an up vector.
Vec3 getUp ()
 Returns the orientation represented by this quaternion, expressed as an up vector.
float getW ()
float getX ()
float getY ()
float getZ ()
bool invertFrom (Quat const other)
 Computes the inverse of the other quat, and stores the result in this quat.
bool invertInPlace ()
 Inverts the current quat.
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 isNan ()
 Returns true if any component of the vector is not-a-number, false otherwise.
bool isSameDirection (Quat const other)
 Returns true if two quaternions represent the same rotation within a default tolerance based on the numeric type.
float length ()
 Returns the length of the vector, by the Pythagorean theorem.
float lengthSquared ()
 Returns the square of the vector's length, cheap and easy.
Quat multiply (Quat const rhs)
 actual multiply call (non virtual)
bool normalize ()
 Normalizes the vector in place.
 operator new (unsigned int size)
bool operator!= (VBase4 const other)
Quat operator* (Quat const )
Quat operator* (float scalar)
Mat3 operator* (Mat3 const )
 Quat * Matrix = matrix.
Mat4 operator* (Mat4 const )
 Quat * Matrix = matrix.
Quat operator*= (Quat const )
VBase4 operator*= (float scalar)
Quat operator+ (Quat const other)
VBase4 operator+ (VBase4 const other)
VBase4 operator+= (VBase4 const other)
Quat operator- ()
VBase4 operator- (VBase4 const other)
Quat operator- (Quat const other)
VBase4 operator-= (VBase4 const other)
Quat operator/ (float scalar)
VBase4 operator/= (float scalar)
bool operator< (VBase4 const other)
 This performs a lexicographical comparison.
bool operator== (VBase4 const other)
float operator[] (int i)
 operator[] (int i)
 output (ostream)
VBase4 project (VBase4 const onto)
 Returns a new vector representing the projection of this vector onto another one.
 pythonRepr (ostream out, string class_name)
PyObject reduce (PyObject self)
 This special Python method is implement to provide support for the pickle module.
 set (float x, float y, float z, float w)
int setattr (PyObject self, string attr_name, PyObject assign)
 This is used to implement write masks.
 setCell (int i, float value)
 setFromAxisAngle (float angle_deg, Vec3 const axis)
 angle_deg is the angle about the axis in degrees.
 setFromAxisAngleRad (float angle_rad, Vec3 const axis)
 angle_rad is the angle about the axis in radians.
 setFromMatrix (Mat3 const m)
 Sets the quaternion according to the rotation represented by the matrix.
 setFromMatrix (Mat4 const m)
 setHpr (VBase3 const hpr, CoordinateSystem cs)
 Sets the quaternion as the unit quaternion that is equivalent to these Euler angles.
 setHpr (VBase3 const hpr)
 Sets the quaternion as the unit quaternion that is equivalent to these Euler angles.
 setI (float i)
 setitem (int i, float v)
 setJ (float j)
 setK (float k)
 setR (float r)
 setW (float value)
 setX (float value)
 setY (float value)
 setZ (float value)
VBase3 xform (VBase3 const v)
 Transforms a 3-d vector by the indicated rotation.
VBase4 xform (VBase4 const v)
 Transforms a 4-d vector by the indicated rotation.

Static Public Member Functions

static TypeHandle getClassType ()
static Quat const identQuat ()
 Returns an identity quaternion.
static Quat pureImaginary (Vec3 const )
static int size ()
 Returns 4: the number of components of a LVecBase4.
static VBase4 const unitW ()
 Returns a unit W vector.
static VBase4 const unitX ()
 Returns a unit X vector.
static VBase4 const unitY ()
 Returns a unit Y vector.
static VBase4 const unitZ ()
 Returns a unit Z vector.
static VBase4 const zero ()
 Returns a zero-length vector.

Detailed Description

This is the base quaternion class.


Constructor & Destructor Documentation

Quat ( )
Quat ( VBase4 const  copy)
Quat ( float  ,
VBase3 const  copy 
)
Quat ( float  ,
float  ,
float  ,
float   
)

Member Function Documentation

unsigned int addHash ( unsigned int  hash) [inherited]

Adds the vector into the running hash.

unsigned int addHash ( unsigned int  hash,
float  threshold 
) [inherited]

Adds the vector into the running hash.

addToCell ( int  i,
float  value 
) [inherited]
addW ( float  value) [inherited]
addX ( float  value) [inherited]
addY ( float  value) [inherited]
addZ ( float  value) [inherited]
bool almostEqual ( Quat const  other)

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

bool almostEqual ( Quat const  other,
float  threshold 
)

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

bool almostEqual ( VBase4 const  other) [inherited]

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

bool almostEqual ( VBase4 const  other,
float  threshold 
) [inherited]

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

bool almostSameDirection ( Quat const  other,
float  threshold 
)

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

float angleDeg ( Quat const  other)

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

float angleRad ( Quat const  other)

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

int compareTo ( VBase4 const  other,
float  threshold 
) [inherited]

Sorts vectors lexicographically, componentwise.

Returns a number less than 0 if this vector sorts before the other one, greater than zero if it sorts after, 0 if they are equivalent (within the indicated tolerance).

int compareTo ( VBase4 const  other) [inherited]

This flavor of compare_to uses a default threshold value based on the numeric type.

Quat conjugate ( )

Returns the complex conjugate of this quat.

bool conjugateFrom ( Quat const  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.

float dot ( VBase4 const  other) [inherited]
extractToMatrix ( Mat3  m)

Based on the quat lib from VRPN.

extractToMatrix ( Mat4  m)

Based on the quat lib from VRPN.

fill ( float  fill_value) [inherited]

Sets each element of the vector to the indicated fill_value.

This is particularly useful for initializing to zero.

VBase4 fmax ( VBase4 const  other) [inherited]
VBase4 fmin ( VBase4 const  other) [inherited]
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.

PyObject getattr ( string  attr_name) [inherited]

This is used to implement swizzle masks.

Reimplemented in Vec4, and Point4.

Vec3 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.

Vec3 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.

float getCell ( int  i) [inherited]
static TypeHandle getClassType ( ) [static]

Reimplemented from VBase4.

Reimplemented in LRotationf, and LOrientationf.

getData ( ) [inherited]

Returns the address of the first of the four data elements in the vector.

The remaining elements occupy the next positions consecutively in memory.

Vec3 getForward ( CoordinateSystem  cs)

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

Vec3 getForward ( )

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

unsigned int getHash ( ) [inherited]

Returns a suitable hash for phash_map.

unsigned int getHash ( float  threshold) [inherited]

Returns a suitable hash for phash_map.

VBase3 getHpr ( CoordinateSystem  cs)

Extracts the equivalent Euler angles from the unit quaternion.

VBase3 getHpr ( )

Extracts the equivalent Euler angles from the unit quaternion.

float getI ( )
float getJ ( )
float getK ( )
int getNumComponents ( ) [inherited]

Returns the number of elements in the vector, four.

float getR ( )
Vec3 getRight ( CoordinateSystem  cs)

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

Vec3 getRight ( )

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

Vec3 getUp ( CoordinateSystem  cs)

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

Vec3 getUp ( )

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

float getW ( ) [inherited]
float getX ( ) [inherited]
float getY ( ) [inherited]
float getZ ( ) [inherited]
static Quat const identQuat ( ) [static]

Returns an identity quaternion.

bool invertFrom ( Quat const  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 isNan ( ) [inherited]

Returns true if any component of the vector is not-a-number, false otherwise.

bool isSameDirection ( Quat const  other)

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

float length ( ) [inherited]

Returns the length of the vector, by the Pythagorean theorem.

float lengthSquared ( ) [inherited]

Returns the square of the vector's length, cheap and easy.

Quat multiply ( Quat const  rhs)

actual multiply call (non virtual)

bool normalize ( )

Normalizes the vector in place.

Returns true if the vector was normalized, false if it was a zero-length vector.

Reimplemented from VBase4.

operator new ( unsigned int  size) [inherited]
bool operator!= ( VBase4 const  other) [inherited]
Mat3 operator* ( Mat3  const)

Quat * Matrix = matrix.

Quat operator* ( Quat  const)

Reimplemented in LRotationf, and LOrientationf.

Mat4 operator* ( Mat4  const)

Quat * Matrix = matrix.

Quat operator* ( float  scalar)

Reimplemented from VBase4.

Reimplemented in LRotationf.

Quat operator*= ( Quat  const)
VBase4 operator*= ( float  scalar) [inherited]
Quat operator+ ( Quat const  other)
VBase4 operator+ ( VBase4 const  other) [inherited]

Reimplemented in Vec4, and Point4.

VBase4 operator+= ( VBase4 const  other) [inherited]
Quat operator- ( Quat const  other)
VBase4 operator- ( VBase4 const  other) [inherited]

Reimplemented in Vec4, and Point4.

Quat operator- ( )

Reimplemented from VBase4.

VBase4 operator-= ( VBase4 const  other) [inherited]
Quat operator/ ( float  scalar)

Reimplemented from VBase4.

Reimplemented in LRotationf.

VBase4 operator/= ( float  scalar) [inherited]
bool operator< ( VBase4 const  other) [inherited]

This performs a lexicographical comparison.

It's of questionable mathematical meaning, but sometimes has a practical purpose for sorting unique vectors, especially in an STL container. Also see compare_to().

bool operator== ( VBase4 const  other) [inherited]
operator[] ( int  i) [inherited]
float operator[] ( int  i) [inherited]
output ( ostream  )

Reimplemented from VBase4.

VBase4 project ( VBase4 const  onto) [inherited]

Returns a new vector representing the projection of this vector onto another one.

The resulting vector will be a scalar multiple of onto.

Reimplemented in Vec4, and Point4.

static Quat pureImaginary ( Vec3  const) [static]
pythonRepr ( ostream  out,
string  class_name 
) [inherited]

Reimplemented in Vec4, and Point4.

PyObject reduce ( PyObject  self) [inherited]

This special Python method is implement to provide support for the pickle module.

set ( float  x,
float  y,
float  z,
float  w 
) [inherited]
int setattr ( PyObject  self,
string  attr_name,
PyObject  assign 
) [inherited]

This is used to implement write masks.

Reimplemented in Vec4, and Point4.

setCell ( int  i,
float  value 
) [inherited]
setFromAxisAngle ( float  angle_deg,
Vec3 const  axis 
)

angle_deg is the angle about the axis in degrees.

axis must be normalized.

setFromAxisAngleRad ( float  angle_rad,
Vec3 const  axis 
)

angle_rad is the angle about the axis in radians.

axis must be normalized.

setFromMatrix ( Mat4 const  m)
setFromMatrix ( Mat3 const  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.

setHpr ( VBase3 const  hpr,
CoordinateSystem  cs 
)

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

(from Real-time Rendering, p.49)

setHpr ( VBase3 const  hpr)

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

(from Real-time Rendering, p.49)

setI ( float  i)
setitem ( int  i,
float  v 
) [inherited]
setJ ( float  j)
setK ( float  k)
setR ( float  r)
setW ( float  value) [inherited]
setX ( float  value) [inherited]
setY ( float  value) [inherited]
setZ ( float  value) [inherited]
static int size ( ) [static, inherited]

Returns 4: the number of components of a LVecBase4.

static VBase4 const unitW ( ) [static, inherited]

Returns a unit W vector.

Reimplemented in Vec4, and Point4.

static VBase4 const unitX ( ) [static, inherited]

Returns a unit X vector.

Reimplemented in Vec4, and Point4.

static VBase4 const unitY ( ) [static, inherited]

Returns a unit Y vector.

Reimplemented in Vec4, and Point4.

static VBase4 const unitZ ( ) [static, inherited]

Returns a unit Z vector.

Reimplemented in Vec4, and Point4.

VBase3 xform ( VBase3 const  v)

Transforms a 3-d vector by the indicated rotation.

VBase4 xform ( VBase4 const  v)

Transforms a 4-d vector by the indicated rotation.

static VBase4 const zero ( ) [static, inherited]

Returns a zero-length vector.

Reimplemented in Vec4, and Point4.

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties