OpenGLContext.quaternion
Simple module providing a quaternion class for manipulating rotations easily.
Note: all angles are assumed to be specified in radians.
Note: this is an entirely separate implementation from the PyOpenGL
quaternion class. This implementation assumes that Numeric python
will be available, and provides only those methods and helpers
commonly needed for manipulating rotations.
Functions
Classes
class Quaternion(
object
):
Quaternion object implementing those methods required
to be useful for OpenGL rendering (and not many others)
internal
__init__(
self
,
elements
= [1, 0, 0, 0]
)
The initializer is a four-element array,
w, x,y,z -- all elements should be doubles/floats
the default values are those for a unit multiplication
quaternion.
__mul__(
self
,
other
)
Multiply this quaternion by another quaternion,
generating a new quaternion which is the combination of the
rotations represented by the two source quaternions.
Other is interpreted as taking place within the coordinate
space defined by this quaternion.
Alternately, if "other" is a matrix, return the dot-product
of that matrix with our matrix (i.e. rotate the coordinate)
__repr__(
self
)
Return a human-friendly representation of the quaternion
Currently this representation is as an axis plus rotation (in radians)
delta(
self
,
other
)
Return the angle in radians between this quaternion and another.
Return value is a positive angle in the range 0-pi representing
the minimum angle between the two quaternion rotations.
From code by Halldor Fannar on the 3D game development algos list
inverse(
self
)
Construct the inverse of this (unit) quaternion
Quaternion conjugate is (w,-x,-y,-z), inverse of a quaternion
is conjugate / length**2 (unit quaternion means length == 1)
matrix(
self
,
dtype
= 'f'
,
inverse
= False
)
Get a rotation matrix representing this rotation
- dtype
- specifies the result-type of the matrix, defaults to 'f' in order to match real-world precision of matrix operations in video cards
- inverse
- if True, calculate the inverse matrix for the quaternion