Gah! Right to Left Handed Conversion Driving Me Crazy

Started by
27 comments, last by Leo_E_49 18 years, 5 months ago
I have a 3D studio exporter which works fine, but my models are sideways because max is right handed and has y and z swapped. So, when exporting I swap y and z and negate z. This work fine for the model, but for the animation frames which are exported as translations and euler angles it doesn't seem to work. It seems to be a problem with the euler angles to which I am doing the same conversion. I have tried all permetations of converting the euler angles I can think of, but nothing is working. Any help as to what is going on here would be appreciated. Thanks
Advertisement
Hi Raeldor,

I usually try to avoid giving advice on things I don't have direct experience with, which includes converting animations between coordinate systems. But since no one's answered yet I thought I'd just ask if you could give a more detailed description of the coordinate systems involved. For example you could say (assuming you're looking from behind the model), 'my system has z up, y forward, and x right, and max has y up, z forward, and x left'. Or whatever. That might make it easier to offer a specific suggestion about how to convert between the two systems.
Quote:Original post by jyk
Hi Raeldor,

I usually try to avoid giving advice on things I don't have direct experience with, which includes converting animations between coordinate systems. But since no one's answered yet I thought I'd just ask if you could give a more detailed description of the coordinate systems involved. For example you could say (assuming you're looking from behind the model), 'my system has z up, y forward, and x right, and max has y up, z forward, and x left'. Or whatever. That might make it easier to offer a specific suggestion about how to convert between the two systems.


Thank you. Any advice right now would be good advice. DirectX seems to have X right, Y up and Z into the distance. Max has X right, Z up and Y into the distance. I have negated one the the axis to convert from right to left handed when exporting vertices and normals which seems to work fine, but taking the euler angles from the conversion and doing the same does not give the desired result.

At this time I am not really sure if it is my math or the idiosynchrocies (spelling?) of Max. I read in the help file for max that taking rotation values from the matrix gives you a left handed rotation where as the rest of max is right handed. How can they use left handed matrices on a right handed system? Besides when I do take the rotation values it looks exactly the same as the rotation values in the interface which are supposed to be right handed.

FYI, I am getting the rotation values down the hierarchy by multiplying the world matrix for the node by the inverse of it's parent. That seems to work ok.
Well, I don't think I have any more ideas - I just don't know enough about max or its format. But, here is a link to a series of articles (note the 'next time' link at the bottom) which appears to be related to the subject. It's several years old and I have no idea if it'll be useful, but who knows...
Quote:Original post by Raeldor

Thank you. Any advice right now would be good advice. DirectX seems to have X right, Y up and Z into the distance. Max has X right, Z up and Y into the distance. I have negated one the the axis to convert from right to left handed when exporting vertices and normals which seems to work fine, but taking the euler angles from the conversion and doing the same does not give the desired result.



Hi Raeldor, the issue is that you do not need to negate the Z axis in your conversion. As you say, the 3ds max Y axis points into the screen and the Z axis up, so swapping the Z and Y axis will make your Z point into the screen and Y up, the way directx likes it to be. You might also want to change the winding order of your triangles or you could change the cullmode. And don't forget to swap the axis on your normals and any transforms you export as well.

hope this helps,
svein
Quote:Original post by sveinm
Quote:Original post by Raeldor

Thank you. Any advice right now would be good advice. DirectX seems to have X right, Y up and Z into the distance. Max has X right, Z up and Y into the distance. I have negated one the the axis to convert from right to left handed when exporting vertices and normals which seems to work fine, but taking the euler angles from the conversion and doing the same does not give the desired result.



Hi Raeldor, the issue is that you do not need to negate the Z axis in your conversion. As you say, the 3ds max Y axis points into the screen and the Z axis up, so swapping the Z and Y axis will make your Z point into the screen and Y up, the way directx likes it to be. You might also want to change the winding order of your triangles or you could change the cullmode. And don't forget to swap the axis on your normals and any transforms you export as well.

hope this helps,
svein


Thank you. This seems to work for the geometry, but the rotation animations are still wrong somewhere. If I take my rotation information as euler angles, should I just be able to swap the axis in the same way, or is it more complicated than that?
Quote:Original post by Raeldor
Thank you. This seems to work for the geometry, but the rotation animations are still wrong somewhere. If I take my rotation information as euler angles, should I just be able to swap the axis in the same way, or is it more complicated than that?


My guess would be that you should be able to just swap the axis in the same way for your angles and it should work. However, if the animation used to work when the model was on its side (pre y/z swap), you will probably have to change the order you apply the rotations in, and possibly the sign of the angles as well. Sorry about this sounding pretty vague, but these things tend to be a bit confusing. Another thing I would recommend would be to make some simple animations, rotating around each of the axis to see which components you need to swap, and wether the signs are right etc. Also, don't forget to swap the y and z on your translations as well.

good luck,
svein
hi. swapping y with z for direct x and -y with z for opengl works fine for geometry, but it gets complicated when using textures and stuff. the method i use (for opengl, but it would work for directx too) is to apply a rotation and save it on the stack before all transformations in the scene, after you load the identity matrix. In opengl will be:
glLoadIdentity();
glRotatef(90.0, 1.0, 0, 0); //a rotation around the X axis, that brings up the Y axis)
glPushMatrix();
....
//al the transform code goes here
....
glPopMatrix();

hope it helps.
Quote:Original post by sveinm
Quote:Original post by Raeldor
Thank you. This seems to work for the geometry, but the rotation animations are still wrong somewhere. If I take my rotation information as euler angles, should I just be able to swap the axis in the same way, or is it more complicated than that?


My guess would be that you should be able to just swap the axis in the same way for your angles and it should work. However, if the animation used to work when the model was on its side (pre y/z swap), you will probably have to change the order you apply the rotations in, and possibly the sign of the angles as well. Sorry about this sounding pretty vague, but these things tend to be a bit confusing. Another thing I would recommend would be to make some simple animations, rotating around each of the axis to see which components you need to swap, and wether the signs are right etc. Also, don't forget to swap the y and z on your translations as well.

good luck,
svein


I finally got it to work, but it's not ideal. Instead of swapping the Y and Z, I instead negated the Z axis for all vertex and translation output. However to get the rotations to work I had to negate the X and Y portion or the euler angles. What is the logic behind this?

As I say it is not ideal, as now I have to rotate all my models when I import them. If I can figure out why I have to negate the XY of the rotations, maybe it will help fix the problems I am having when swapping YZ on the vertices.
Quote:Original post by Raeldor
I finally got it to work, but it's not ideal. Instead of swapping the Y and Z, I instead negated the Z axis for all vertex and translation output. However to get the rotations to work I had to negate the X and Y portion or the euler angles. What is the logic behind this?

As I say it is not ideal, as now I have to rotate all my models when I import them. If I can figure out why I have to negate the XY of the rotations, maybe it will help fix the problems I am having when swapping YZ on the vertices.


Not quite sure what the logic is behind negating the x and y portion of the euler angles are, but I can only assume that when you change the coordinate system around like that you need to change the sign of your rotations.

Anyways, if you're calculating your euler angles from the world transform of the node, you will need to swap the rows and columns of your matrix around before you calculate the euler angles as well, that is if you would like ot swap the y and z of your vertices around. Just swap row 1 and 2 and column 1 and 2 around before you calculate the euler angles, that way the transform should be in the same coordinate space as your vertices.

svein

This topic is closed to new replies.

Advertisement