Matrix and Vector math with pyrr¶
Pyrr has both a procedural and object oriented api.
See pyrr for official docs.
Note
We should probably add some more examples here. Feel free to make an issue or pull request on github.
Examples¶
Identity
# procedural
>> m = matrix44.create_identity()
>> print(m)
array([[ 1., 0., 0., 0.],
[ 0., 1., 0., 0.],
[ 0., 0., 1., 0.],
[ 0., 0., 0., 1.]])
# object
>> m = Matrix44.identity()
>> print(m)
array([[ 1., 0., 0., 0.],
[ 0., 1., 0., 0.],
[ 0., 0., 1., 0.],
[ 0., 0., 0., 1.]])
Matrices produced by Matrix44
are also just numpy arrays as the class extends numpy.ndarray
.
We can pretty much use the APIs interchangeably unless we rely on a method in the class.
They can both be passed right into shaders as matrix uniforms.
Rotation
# Short version
mat = Matrix44.from_eulers(Vector3(rotation))
# Long version
rot_x = matrix44.create_from_x_rotation(rotation[0])
rot_y = matrix44.create_from_y_rotation(rotation[1])
rot_z = matrix44.create_from_z_rotation(rotation[2])
mat = matrix44.multiply(x, y)
mat = matrix44.multiply(mat, z)
Type conversion¶
# mat4 to mat3
mat3 = Matrix33.from_matrix44(mat)
# mat3 to mat4
mat4 = Matrix44.from_matrix33(mat)