So I've been playing around with OpenGL and then like in another thread I've opened, I made some simple transform function to make objects draw correctly given their positions and rotations.

It is all fun and games until I get to trying to use the whole 3 axis for rotation.

To cut it short, the order of the rotations matter because the matrix mul is not commutative so depending on your implementation, if you rotate x, y, z, say, you will have a different result than rotating z, y, x when you are rotated any amount in the y axis, in the extreme you are rotated 90 deg around y and the z axis rotation becomes equal to the x axis rotation.

I'm using a simplification of Anton's funcs, and they seem to be equal to the implementations in GLM too (tho GLM let's you define some macro and have slightly different impls).

My question is how to fix this, if possible. This is the rotation func I'm using and works pretty well except z rotation:

/* mat4 array layout 0 4 8 12 1 5 9 13 2 6 10 14 3 7 11 15 */ mat4 rotate_xyz_deg( const mat4& m, vec3 deg ) { float sx = sine(deg.x); float cx = cosine(deg.x); float sy = sine(deg.y); float cy = cosine(deg.y); float sz = sine(deg.z); float cz = cosine(deg.z); mat4 mx = { 1, 0, 0, 0, 0, cx, sx, 0, 0, -sx, cx, 0, 0, 0, 0, 1 }; mat4 my = { cy, 0, -sy, 0, 0, 1, 0, 0, sy, 0, cy, 0, 0, 0, 0, 1 }; mat4 mz = { cz, -sz, 0, 0, sz, cz, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; return mz * (my * (mx * m)); }