View Full Version : Orientation Flip Problem when using $.Dir

01 January 2008, 04:35 PM
Hi Guys,

I am trying to write a simple tool that with orientate an object to sit on a surface and align to the surface normal, so the Zaxis aligns to the face normal. This is not a problem. I then want to be able to rotate that object around the local Z axis, so I can effectively control the direction that the local X axis points. I need this to be done using maxscript, so I can automatically orientate a large number of objects in both the z and x local axis... and hence the entire object.

The problem that I am having is that when I am orientating something using the obj.dir property, max seems to decide to flip the orientation of the x and y axis. I,e The Z axis always points correctly, but the X axis and Y axis can change.

To illustrate the problem, I have attached an image of a load of scattered teapots that I have told to point towards the sphere. i.e

for t in teapots do
t.dir = normalize ($Sphere01.pos - t.pos)

As you can see from the image, max changes its orientation of the x and y axis. I cannot figure out how to prevent, or detect this flip, making it impossible for me to reliably orientate Objects....

Does it have anything to do with the "getEulerMatAngleRatio" command... I dont really understand that section!

Any help preventing or detecting this change in orientation would be really helpful, cause I know I can then complete the rest of the orientation without too much difficulty!

Thanks for your time everyone!


01 January 2008, 10:56 AM

The solution was staring me in the face, but I got obsessed with trying to detect the flip. It is much easier to simply build the transformation matrix from scratch using the vectors that you have calculated, and then assign the new transformation matrix to the object.

This has very recently been demonstrated by Bobo in this forum post:

Bobo - Rebuild the matrix Example

I have included the Code here as well for completeness - example uses an intersect Ray

theHit = intersectRay theGround theRay
theZ = theHit.dir --this is the new Z axis oriented along the surface normal
theX = normalize theSourceObject.transform.row1 --this is the X axis from the source
theY = normalize (cross theX theZ) --this is the new Y perpendicular to both X and Z
--Now transform the object using the new X, Y and Z and set the position to the hit
theTargetObject.transform = matrix3 theX theY theZ theHit.pos

Cheers :)


CGTalk Moderation
01 January 2008, 10:56 AM
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.