Skip to main content
gamedev.net
🔒 Locked

Troublesome transform

Started by Promethium Oct 13, 2008 at 5:52 AM 1 replies 1k views
Original Post
Promethium
Promethium
I'm trying to align two points in space, while also rotating them so their local coordinates system match. This image illustrates what I'm trying to do: Free Image Hosting at www.ImageShack.us So, given two meshes (m1 and m2), two reference points (a1 and a2), and two local coordinate systems ([x1 y1 z1] and [x2 y2 z2]) I need to construct a matrix M that, when applied to m2, will move and rotate it so that a2 coincides with a1, and m2 is rotated opposite m1. This seems simple enough. What I have so far is

M = T(-a2) * R(x2, y2, z2) * R(-x1, y1, -z1) * T(a1)

(where T is a translation transformation, and R a rotation transformation). However, my problem is that this transformation only gives the desired result if z1 is aligned with the global Z axis. So, for example, given m1 and m2 centered on (0 0 0):

a1 = (0 50 -50)
x1 = (-1 0 0)
y1 = (0 1 0)
z1 = (0 0 -1)

a2 = (50 50 0)
x2 = (0 0 -1)
y2 = (0 1 0)
z2 = (1 0 0)

M = (  0 0    1 0
       0 1    0 0
      -1 0    0 0
       0 0 -100 0 )

which is the expected result, but swap a1, x1, y1, z1 for a2, x2, y2, z2 gives

M = (  0 0 1 0
       0 1 0 0
      -1 0 0 0
       0 0 0 0 )

which is not what I want. It seems to be the last rotation that is wrong. In the first example m2 (correctly) get the opposite rotation of m1, while in the second example m2 (incorrectly) get the same rotation as m1. So can anyone help me out here? Are my assumptions wrong? Am I missing a step? Am I barking up the completly wrong tree here?
apatriarca
apatriarca
You first have to translate your point in the origin, than to ‘reset’ the current orientation of the point (R(x2, y2, z2)-1=R(x2, y2, z2)T). You can than rotate the coordinate frame and translate the point. If you are using row vectors:

M = T(-a2) * R(x2, y2, z2)T * R(-x1, y1, -z1) * T(a1)
Promethium
Promethium
Quote:
Original post by apatriarca
You first have to translate your point in the origin, than to ‘reset’ the current orientation of the point (R(x2, y2, z2)-1=R(x2, y2, z2)T). You can than rotate the coordinate frame and translate the point. If you are using row vectors:

M = T(-a2) * R(x2, y2, z2)T * R(-x1, y1, -z1) * T(a1)


Man, I knew it was something simple... [smile] Actually, it was

M = T(-a2) * R(x2, y2, z2) * R(-x1, y1, -z1)T * T(a1)

Now it works beautifully!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.