PDA

View Full Version : How do you accurately calculate eularAngles to avoid flipped orientation?


wallworm
04-22-2012, 01:42 PM
One of my tools exports scenes/objects into a game engine. One of the problems I have encountered lately is that sometimes the orientation is incorrect. The engine requires eulerAngles… but sometimes the angles are simply “flipped”.

In the attached image, the Max scene is the original. The right is the exported scene in another program called Hammer. Notice that all of the teapots along the yellow hilight are inverted on multiple axises in the game editor.

http://area.autodesk.com/userdata/forum/p/paint_object_rotation.png

I normally haven’t had a problem with this by just using something like:

local theRotation = theModel.rotation as eulerAngles

But when I started experimenting with painting models in the scene with the Object Paint tools, I’ve found that this method of calculating is incorrect. As you can see, those I simply copied, moved and rotated exported correctly--but all those part of an object paint stroke (yellow hilight) have inaccurate rotations.

The questions:

1) How do I detect this incorrect orientation?
2) How do I resolve it? (I’ve tried multiplying the angles by -1 or subtracting 180 in various attempts to get at the issue but I’m not getting the desired results).

Again, like always, all help is appreciated.

denisT
04-22-2012, 02:09 PM
first of all you have to be sure that the max and your game engine have the same World Coordinate System.
second, you have to double check how the engine applies Euler Angles (the order of axis to set). The default max order is XYZ, but the order might be any and the result is different.

wallworm
04-22-2012, 02:15 PM
first of all you have to be sure that the max and your game engine have the same World Coordinate System.
second, you have to double check how the engine applies Euler Angles (the order of axis to set). The default max order is XYZ, but the order might be any and the result is different.

Denis... thanks for the response. Yes, the game engine and Max use the same coordinate system and XYZ order for most things (though there are some exceptions in this engine depending on the type of geometry... but that is irrelevent here).

Notice that the problem is that the rotations I've extracted are correct for models I've placed manually and/or copied/rotated manually. The incorrect rotations seem to be when I've painted those objects with the Object Paint tool in the Graphite toolbar. Suddenly, the rotations are entirely incorrect... even though... if I switch to local coordsys in Max and select a model I oriented to match one that is in the Paint stroke--their local XYZ aligns. But the one in the stroke reports a completely different set of numbers or the eulerAngles and is always flipped in my export.

denisT
04-22-2012, 03:02 PM
try to get rotation as:

local theRotation = theModel.transform.rotation as eulerAngles

is it the same as

theModel.transform.rotation as eulerAngles

in your case?

miauu
04-22-2012, 04:10 PM
Hi, Shawn!
Do you tried with resetXform modifier?

wallworm
04-22-2012, 06:41 PM
I did try once with Reset XForm (that was one of my first guesses) but it didn't seem to work. I also tried using theModel.transform.rotation instead of theModel.rotation ... but the results were identical.

It seems very odd... because the rotations are always correct when I manually move/rotate the objects... but the ones that are painted into the scene with Object Paint change things in some fashion that I cannot "cancel out".

wallworm
04-23-2012, 02:48 PM
I'm pretty sure I know the problem now. The Object Paint function automatically gives all objects a negative scale [-1,-1,-1].

So I have two questions:

1) How do I account for this? In other words, how would I output the rotation values of the object such that it was oriented as it is in the scene but as if it had a positive scale?

2) Why would Autodesk do it this way? I have always heard that you should never negatively scale things in Max. In fact, when looking up a solution I found Bobo stating just that (http://forums.cgsociety.org/archive/index.php/t-599564.html):


Of course, one should NEVER scale negatively in Max, but that's another story. ;)

denisT
04-23-2012, 02:54 PM
I'm pretty sure I know the problem now. The Object Paint function automatically gives all objects a negative scale [-1,-1,-1].

object paint... what tool is it? is it one of max built-in?

wallworm
04-23-2012, 03:01 PM
Object Paint is in the Graphite Modeling toolbar of Max 2011-2013. It's a really cool tool that really works well for some of the things I'm working on--except for this dilemma! :)

CGTalk Moderation
04-23-2012, 03:01 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.