RigidBodyPose
¶

Class for representing rigid body poses. 
psychopy.visual.
RigidBodyPose
(pos=(0.0, 0.0, 0.0), ori=(0.0, 0.0, 0.0, 1.0))[source]¶Class for representing rigid body poses.
This class is an abstract representation of a rigid body pose, where the position of the body in a scene is represented by a vector/coordinate and the orientation with a quaternion. Pose can be manipulated and interacted with using class methods and attributes. Rigid body poses assume a righthanded coordinate system (Z is forward and +Y is up).
Poses can be converted to 4x4 transformation matrices with getModelMatrix. One can use these matrices when rendering to transform the vertices of a model associated with the pose by passing them to OpenGL. Matrices are cached internally to avoid recomputing them if pos and ori attributes have not been updated.
Operators * and ~ can be used on RigidBodyPose objects to combine and invert poses. For instance, you can multiply (*) poses to get a new pose which is the combination of both orientations and translations by:
newPose = rb1 * rb2
Likewise, a pose can be inverted by using the ~ operator:
invPose = ~rb
Multiplying a pose by its inverse will result in an identity pose with no translation and default orientation where pos=[0, 0, 0] and ori=[0, 0, 0, 1]:
identityPose = ~rb * rb
Warning
This class is experimental and may result in undefined behavior.
pos (array_like) – Position vector [x, y, z] for the origin of the rigid body.
ori (array_like) – Orientation quaternion [x, y, z, w] where x, y, z are imaginary and w is real.
alignTo
(alignTo)[source]¶Align this pose to another point or pose.
This sets the orientation of this pose to one which orients the forward axis towards alignTo.
alignTo (array_like or LibOVRPose) – Position vector [x, y, z] or pose to align to.
at
¶Vector defining the forward direction (Z) of this pose.
bounds
¶Bounding box associated with this pose.
copy
()[source]¶Get a new RigidBodyPose object which copies the position and orientation of this one. Copies are independent and do not reference each others data.
Copy of this pose.
distanceTo
(v)[source]¶Get the distance to a pose or point in scene units.
v (RigidBodyPose or array_like) – Pose or point [x, y, z] to compute distance to.
Distance to v from this pose’s origin.
getModelMatrix
(inverse=False, out=None)[source]¶Get the present rigid body transformation as a 4x4 matrix.
Matrices are computed only if the pos and ori attributes have been updated since the last call to getModelMatrix. The returned matrix is an ndarray and rowmajor.
4x4 transformation matrix.
ndarray
Examples
Using a rigid body pose to transform something in OpenGL:
rb = RigidBodyPose((0, 0, 2)) # 2 meters away from origin
# Use `array2pointer` from `psychopy.tools.arraytools` to convert
# array to something OpenGL accepts.
mv = array2pointer(rb.modelMatrix)
# use the matrix to transform the scene
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadIdentity()
glMultTransposeMatrixf(mv)
# draw the thing here ...
glPopMatrix()
getNormalMatrix
(out=None)[source]¶Get the present normal matrix.
out (ndarray or None) – Optional 4x4 array to write values to. Values written are computed using 32bit float precision regardless of the data type of out.
4x4 normal transformation matrix.
ndarray
getOriAxisAngle
(degrees=True)[source]¶Get the axis and angle of rotation for the rigid body. Converts the orientation defined by the ori quaternion to and axisangle representation.
getViewMatrix
(inverse=False)[source]¶Convert this pose into a view matrix.
Creates a view matrix which transforms points into eye space using the current pose as the eye position in the scene. Furthermore, you can use view matrices for rendering shadows if light positions are defined as RigidBodyPose objects.
inverse (bool) – Return the inverse of the view matrix. Default is False.
4x4 transformation matrix.
ndarray
getYawPitchRoll
(degrees=True)[source]¶Get the yaw, pitch and roll angles for this pose relative to the Z world axis.
degrees (bool, optional) – Specify True
if angle is in degrees, or else it will be
treated as radians. Default is True
.
interp
(end, s)[source]¶Interpolate between poses.
Linear interpolation is used on position (Lerp) while the orientation has spherical linear interpolation (Slerp) applied taking the shortest arc on the hypersphere.
end (LibOVRPose) – End pose.
s (float) – Interpolation factor between interval 0.0 and 1.0.
Rigid body pose whose position and orientation is at s between this pose and end.
inverseModelMatrix
¶Inverse of the pose as a 4x4 model matrix (readonly).
inverted
()[source]¶Get a pose which is the inverse of this one.
This pose inverted.
isEqual
(other)[source]¶Check if poses have similar orientation and position.
other (RigidBodyPose) – Other pose to compare.
Returns True is poses are effectively equal.
modelMatrix
¶Pose as a 4x4 model matrix (readonly).
normalMatrix
¶The normal transformation matrix.
ori
¶Orientation quaternion (X, Y, Z, W).
pos
¶Position vector (X, Y, Z).
posOri
¶The position (x, y, z) and orientation (x, y, z, w).
setOriAxisAngle
(axis, angle, degrees=True)[source]¶Set the orientation of the rigid body using an axis and angle. This sets the quaternion at ori.
transform
(v, out=None)[source]¶Transform a vector using this pose.
v (array_like) – Vector to transform [x, y, z].
out (ndarray or None, optional) – Optional array to write values to. Must have the same shape as v.
Transformed points.
ndarray
transformNormal
(n)[source]¶Rotate a normal vector with respect to this pose.
Rotates a normal vector n using the orientation quaternion at ori.
n (array_like) – Normal to rotate (1D with length 3).
Rotated normal n.
ndarray
up
¶Vector defining the up direction (+Y) of this pose.