Blender Matrix to OpenGL Matrix

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
Posts: 0
Joined: Wed Feb 06, 2013 6:27 pm

Blender Matrix to OpenGL Matrix

Post by Link2012 » Wed Feb 06, 2013 6:32 pm

My problem is, Blender uses Z for up and I use Y for up, so things get different when I export.

I created a custom exporter, this file format has a matrix for each mesh, the matrix contains all transformations and will just be multiplied with the modelview on OpenGL, so here the great problem comes, the matrix is a little different from how it should be on OpenGL because Blender uses Z for up.

So, there's any way to convert the Blender Matrix to OpenGL matrix? If yes, how?

Posts: 0
Joined: Thu Feb 14, 2013 2:52 am

Re: Blender Matrix to OpenGL Matrix

Post by robognome » Thu Feb 14, 2013 3:14 am

I dont know about opengl world coordinates but I think you just need to swap the y and z coordinates.

I know this sounds too easy but it works. However...

You should note that this converts the coordinate system from blender's right handed system to a left handed system with the z-axis positive direction toward the back camera. If you need to z axis positive coming toward the front-view camera then just negate the z-value (after swapping the axis).

Posts: 0
Joined: Sun Nov 07, 2010 11:30 pm
Location: Hamilton, New Zealand

Post by ldo » Fri Mar 08, 2013 9:19 am

Say Blender coords are (X, Y, Z), OpenGL are (X', Y', Z'). Then the coordinate orientations are:

Blender: X to right, Y away from you, Z up.

OpenGL: X' to right, Y' up, Z' towards you.


X' = X
Y' = Z
Z' = -Y

Post Reply