Skip to content

Commit eca3f8a

Browse files
committed
Docs: Basic pyrr stuff
1 parent 90f35d5 commit eca3f8a

File tree

1 file changed

+69
-3
lines changed

1 file changed

+69
-3
lines changed

docs/source/pyrrmath.rst

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,73 @@
22
Matrix and Vector math with pyrr
33
================================
44

5-
This section needs more work. Probably the most relevant types
6-
to start with is Matrix*, matrix*, Vector and vector.
5+
Pyrr has both a procedural and object oriented api.
76

8-
See `pyrr <https://pyrr.readthedocs.io/en/latest/>`__ docs.
7+
See `pyrr <https://pyrr.readthedocs.io/en/latest/>`__ for official docs.
8+
9+
.. Note:: We should probably add some more examples here. Feel free to
10+
make an issue or pull request on github.
11+
12+
Examples
13+
^^^^^^^^
14+
15+
Identity
16+
17+
.. code:: python
18+
19+
# procedural
20+
>> m = matrix44.create_identity()
21+
>> print(m)
22+
array([[ 1., 0., 0., 0.],
23+
[ 0., 1., 0., 0.],
24+
[ 0., 0., 1., 0.],
25+
[ 0., 0., 0., 1.]])
26+
27+
# object
28+
>> m = Matrix44.identity()
29+
>> print(m)
30+
array([[ 1., 0., 0., 0.],
31+
[ 0., 1., 0., 0.],
32+
[ 0., 0., 1., 0.],
33+
[ 0., 0., 0., 1.]])
34+
35+
Matrices produced by ``Matrix44`` are also just numpy arrays as the class extends ``numpy.ndarray``.
36+
We can pretty much use the APIs interchangeably unless we rely on a method in the class.
37+
They can both be passed right into shaders as matrix uniforms.
38+
39+
Rotation
40+
41+
.. code:: python
42+
43+
# Short version
44+
mat = Matrix44.from_eulers(Vector3(rotation))
45+
46+
# Long version
47+
rot_x = matrix44.create_from_x_rotation(rotation[0])
48+
rot_y = matrix44.create_from_y_rotation(rotation[1])
49+
rot_z = matrix44.create_from_z_rotation(rotation[2])
50+
mat = matrix44.multiply(x, y)
51+
mat = matrix44.multiply(mat, z)
52+
53+
Covert
54+
^^^^^^
55+
56+
.. code:: python
57+
58+
# mat4 to mat3
59+
mat3 = Matrix33.from_matrix44(mat)
60+
# mat3 to mat4
61+
mat4 = Matrix44.from_matrix33(mat)
62+
63+
64+
Common Mistakes
65+
^^^^^^^^^^^^^^^
66+
67+
Matrices and vectors are just numpy arrays. When multiplying matrices,
68+
use the ``mult`` method/function.
69+
70+
.. code:: python
71+
72+
mat = matrix44.mult(mat1, mat2)
73+
74+
Using the ``*`` operator would just make a product of the two arrays.

0 commit comments

Comments
 (0)