Jump to content


- - - - -

Transform Matrix from 3ds max to right-handed


8 replies to this topic

#1 SnprBoB86

    Valued Member

  • Members
  • PipPipPip
  • 112 posts

Posted 22 July 2006 - 03:46 AM

Is there a way I can convert a model exported from 3ds max (positive X to the right, positive Y into the distance, and positive Z up) to a standard right-handed model (positive X to the right, positive Y up, and positive Z towards the camera) using a matrix?

I know how to do this by manipulating each vertex manually, but how can I do it with a matrix?

Thanks a lot!

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4968 posts
  • LocationBellevue, WA

Posted 22 July 2006 - 04:47 AM

It's easy. You'll want to multiply each vertex by a 3x3 matrix. Now the rule for matrices is that when you multiply one by the vector <1, 0, 0> you get a vector equal to the first column of the matrix; multiplying by <0, 1, 0> gives you the second column; and multiplying by <0, 0, 1> gives you the third column. So all you have to do is figure out what you want those three vectors (in the 3DS Max coordinate system) to come out as in your coordinate system. Then constructing the appropriate matrix is easy. In this case:

<1, 0, 0> (in 3DS Max) --> <1, 0, 0> in your coordinates
<0, 1, 0> --> <0, 0, -1>
<0, 0, 1> --> <0, 1, 0>

So the appropriate matrix would be
[ 1 0 0 ]
[ 0 0 1 ]
[ 0 -1 0 ]
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 SnprBoB86

    Valued Member

  • Members
  • PipPipPip
  • 112 posts

Posted 23 July 2006 - 04:25 AM

I had to use

[ 1 0 0 ]
[ 0 0 1 ]
[ 0 1 0 ]

and reverse the cull order, but it works great! Thanks!
Brandon Bloom
http://brandonbloom.name

#4 Faelenor

    Member

  • Members
  • PipPip
  • 44 posts

Posted 24 July 2006 - 05:41 PM

3dsmax coordinate system is already right handed, so you shouldn't have to reverse the face vertex order. You just have to do a 90 degree rotation around the x axis to convert your objects. The matrix Reedbeta gave you does this rotation.

The matrix you are using is not good. It will just interchange y and z, which is not good (it's a reflection, and that's why you had to reverse the face vertex order)

And by the way, the usual standard is: x axis points left, y axis points up, z points forward.

#5 Reedbeta

    DevMaster Staff

  • Administrators
  • 4968 posts
  • LocationBellevue, WA

Posted 24 July 2006 - 10:37 PM

Faelenor said:

the usual standard is: x axis points left, y axis points up, z points forward.

That doesn't sound like the standard coordinate system to me...I think SnprBob86 has it right. x -> right, y -> up, z -> backward for OpenGL (the camera points along the negative z axis in eye space). Direct3D uses a left-handed system that has x -> right, y -> up, and z -> forward.

So, SnprBob86's matrix is correct for D3D, as long as he hasn't set up D3D's projection matrix to flip the Z axis (as some people do, to get a right-handed system in D3D).
reedbeta.com - developer blog, OpenGL demos, and other projects

#6 Faelenor

    Member

  • Members
  • PipPip
  • 44 posts

Posted 25 July 2006 - 02:27 PM

Reedbeta said:

That doesn't sound like the standard coordinate system to me...I think SnprBob86 has it right. x -> right, y -> up, z -> backward for OpenGL (the camera points along the negative z axis in eye space). Direct3D uses a left-handed system that has x -> right, y -> up, and z -> forward.

Well, it depends. From the camera's point of view, you are right. But usualy, objects, especially characters, are modeled with their z axis pointing towards. That was the case everywhere I worked. You just have to take the z axis of the object to know in which direction it's facing. But well, maybe that's not the standard, but it's probably more convenient for AI.

Reedbeta said:

So, SnprBob86's matrix is correct for D3D, as long as he hasn't set up D3D's projection matrix to flip the Z axis (as some people do, to get a right-handed system in D3D).

He explicitely wanted a right handed system, so he's obviously wrong!

#7 pha3z

    New Member

  • Members
  • Pip
  • 2 posts

Posted 21 November 2008 - 01:16 AM

Faelenor said:

3dsmax coordinate system is already right handed, so you shouldn't have to reverse the face vertex order.

That is true for the UI and for MaxScript. But you need to be careful about how you are accessing the values. This is taken from MaxScript Help Doc:

Quote

<node>.transform : Matrix3 -- node's main transformation matrix
Rotation in the internal transformation matrices is left-handed in contradiction to the 3ds Max user interface and MAXScript. Take care when mixing rotation derived from these matrices and rotation used in rotation-related functions or from rotation properties.


#8 Reedbeta

    DevMaster Staff

  • Administrators
  • 4968 posts
  • LocationBellevue, WA

Posted 21 November 2008 - 01:40 AM

Thanks pha3z, but this thread is over two years old. ;)
reedbeta.com - developer blog, OpenGL demos, and other projects

#9 pha3z

    New Member

  • Members
  • Pip
  • 2 posts

Posted 21 November 2008 - 02:32 AM

Hey Reed,

These threads come up on google searches. I won't be the last person to visit them. ;) I'll leave a trail for those who come after me.

BTW, Here's an awesome page that demistifies all the confusion between the way matrices are stored and translated in OpenGL vs. DirectX.

http://www.mindcontr...rix-layout.html





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users