Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing a matrix from right-handed to left-handed coordinate system

Tags:

math

graphics

I would like to change a 4x4 matrix from a right handed system where:
x is left and right, y is front and back and z is up and down

to a left-handed system where:
x is left and right, z is front and back and y is up and down.

For a vector it's easy, just swap the y and z values, but how do you do it for a matrix? enter image description here

like image 587
cmann Avatar asked Aug 11 '09 21:08

cmann


1 Answers

Let me try to explain it a little better. I need to export a model from Blender, in which the z axis faces up, into OpenGL, where the y axis faces up.

For every coordinate (x, y, z) it's simple; just swap the y and z values: (x, z, y).
Because I have swapped the all the y and z values, any matrix that I use also needs to be flipped so that it has the same effect.

After a lot of searching I've eventually found a solution at gamedev:

If your matrix looks like this:

{ rx, ry, rz, 0 }   { ux, uy, uz, 0 }   { lx, ly, lz, 0 }   { px, py, pz, 1 } 

To change it from left to right or right to left, flip it like this:

{ rx, rz, ry, 0 }   { lx, lz, ly, 0 }   { ux, uz, uy, 0 }   { px, pz, py, 1 } 
like image 56
cmann Avatar answered Sep 22 '22 15:09

cmann