Skip to content

Coding guide maths

Péter Kardos edited this page Jul 7, 2017 · 11 revisions

Maths conventions

Coordinate spaces:

Handedness X Y Z
World Right Right Forward Up
Camera Left Right Up Forward
NDC Left Right [-1; 1] Up [-1; 1] Forward [0; 1]

Matrix layout:
SSE: row-major
Packed: row-major
Shader: row-major
Never explicitly specify layout in shaders!
Do not index matrices in a way that depends on layout (i.e. vector of first 4 elements in memory)!

Multiplication order:
The vector is followed by the matrix:

vector' = vector*MATRIX1*MATRIX2*MATRIX3
This way, the order in which transforms are applied aligns with left-to-right reading. Matrix functions are automatically configured to generate such matrices.

Quaternions:
Mathematical quaternion multiplication is used, thus *q = q2\*q1* denotes the rotation q1 followed by the rotation q2.

Our matrices look like...
<math>\alpha</math>

Clone this wiki locally