Best Practices - ZackWilde27/Z3dPy GitHub Wiki

Just some tips I thought I'd mention. This will continue to update.

Internal Camera

Setting the internal camera basically means calculating the view matrix. Anything involving matrixes gets costly, so it should be called as sparingly as possible.

Ideally, it should only be called when the camera moves, but implementing checks for that might decrease the speed further.

If you've got a static camera, you can call it once at the start and then leave it, but a movable camera needs to be updated at most once per frame.

Rotating Vectors

When rotating vectors by all 3 axis, the order of operations is:

RotateX -> RotateZ -> RotateY

Matrixes

Multiplying matrixes together is not nearly as costly as multiplying a matrix to a vector, so if you're using multiple matrixes, multiply them together before multiplying with the vector.

Meshes

While the culling routine makes sure that triangles facing away from the camera are removed immediately, it's still faster to not even deal with the tris in the first place.

For example, my flappy bird clone always shows the bird from one angle so...

image

image