pyglet.math
Matrix and Vector math.
This module provides Vector and Matrix objects, including Vec2, Vec3,
Vec4, Mat3, and Mat4. Most common matrix and vector operations are
supported. Helper methods are included for rotating, scaling, and
transforming. The Mat4 includes class methods
for creating orthographic and perspective projection matrixes.
Matrices behave just like they do in GLSL: they are specified in column-major order and multiply on the left of vectors, which are treated as columns.
All objects are immutable and hashable.
- class Mat3
A 3x3 Matrix.
Mat3 is an immutable 3x3 Matrix, which includes most common operators.
A Matrix can be created with a list or tuple of 9 values. If no values are provided, an “identity matrix” will be created (1.0 on the main diagonal). Because Mat3 objects are immutable, all operations return a new Mat3 object.
Note
Matrix multiplication is performed using the “@” operator.
-
a:
float Alias for field number 0
-
b:
float Alias for field number 1
-
c:
float Alias for field number 2
-
d:
float Alias for field number 3
-
e:
float Alias for field number 4
-
f:
float Alias for field number 5
-
g:
float Alias for field number 6
-
h:
float Alias for field number 7
-
i:
float Alias for field number 8
-
a:
- class Mat4
A 4x4 Matrix.
Mat4is an immutable 4x4 Matrix object with most common operators. This includes class methods for creating orthogonal and perspective projection matrixes, which can be used directly by OpenGL.You can create a Matrix with 16 initial values (floats), or no values at all. If no values are provided, an “identity matrix” will be created (1.0 on the main diagonal).
Mat4objects are immutable, so all operations will return a new Mat4 object.Note
Matrix multiplication is performed using the “@” operator.
-
a:
float Alias for field number 0
-
b:
float Alias for field number 1
-
c:
float Alias for field number 2
-
d:
float Alias for field number 3
-
e:
float Alias for field number 4
-
f:
float Alias for field number 5
-
g:
float Alias for field number 6
-
h:
float Alias for field number 7
-
i:
float Alias for field number 8
-
j:
float Alias for field number 9
-
k:
float Alias for field number 10
-
l:
float Alias for field number 11
-
m:
float Alias for field number 12
-
n:
float Alias for field number 13
-
o:
float Alias for field number 14
-
p:
float Alias for field number 15
-
a:
- class Quaternion
Quaternion.
Quaternions are 4-dimensional complex numbers, useful for describing 3D rotations.
-
w:
float Alias for field number 0
-
x:
float Alias for field number 1
-
y:
float Alias for field number 2
-
z:
float Alias for field number 3
-
w:
- class Vec2
A two-dimensional vector represented as an X Y coordinate pair.
Vec2 is an immutable 2D Vector, including most common operators. As an immutable type, all operations return a new object.
Note
The Python
lenoperator returns the number of elements in the vector. For the vector length, use the length() method.Note
Python’s
sum()requires the first item to be aVec2.After that, you can mix
Vec2-liketupleandVec2instances freely in the iterable.If you do not, you will see a
TypeErrorabout being unable to add atupleand aint.-
x:
float Alias for field number 0
-
y:
float Alias for field number 1
-
x:
- class Vec3
A three-dimensional vector represented as X Y Z coordinates.
Vec3 is an immutable 3D Vector, including most common operators. As an immutable type, all operations return a new object.
Note
The Python
lenoperator returns the number of elements in the vector. For the vector length, use the length() method.-
x:
float Alias for field number 0
-
y:
float Alias for field number 1
-
z:
float Alias for field number 2
-
x:
- class Vec4
A four-dimensional vector represented as X Y Z W coordinates.
Vec4 is an immutable 4D Vector, including most common operators. As an immutable type, all operations return a new object.
Note
The Python ``len` operator returns the number of elements in the vector. For the vector length, use the length() method.
-
w:
float Alias for field number 3
-
x:
float Alias for field number 0
-
y:
float Alias for field number 1
-
z:
float Alias for field number 2
-
w: