Jump to content
  • Advertisement
Sign in to follow this  
Ultraseamus

Building an alignment matrix

This topic is 4526 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The alignment matrix aligns the model space Y axis with the specified axis vector (x,y,z) (which need not be normalized). The rotation is performed about the vector (a ^ b), where a is (0,1,0) and b is (x,y,z). x --> Specifies the X component of the axis of alignment. y --> Specifies the Y component of the axis of alignment. z --> Specifies the Z component of the axis of alignment. I am having some trouble building the rotation matrix that preforms this action, any help would be great, Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Is there any particular reason you're crossing the target vector with the cardinal Y axis to get your axis of rotation? Usually when you want to rotate a vector a (model space Y) onto a vector b (the target vector), the axis of rotation is chosen so as to be parallel to aXb.

Share this post


Link to post
Share on other sites
Well as i understand it i need to rotate the model space Y axis (0,1,0) onto target vector (x,y,z), so by crossing (0,1,0) with (x,y,z) that should produce the axis of rotation right? I think i got the solution to my problem in the end, but it seems the object i am rotating is off by a few degrees.

With (x,y,z) being (1,0,1) i started with crossing (0,1,0) with (1,0,1) and got (1,0,-1) which i believe should be my axis of rotation, and i used the dot product to find the angle between (0,1,0) and (1,0,1) which i got to be 90 degrees. I then normalized the vextor (1,0,-1). That is my logic, it probably does not all make sense, i am still new to this material, in the end i came up with the matrix:

((x*x)*(1-c)+c, (y*x)*(1-c)+(z*s), (x*z)*(1-c)-(y*s),0,
(x*y)*(1-c)-(z*s),(y*y)*(1-c)+c,(y*z)*(1-c)+(x*s),0,
(x*z)*(1-c)+(y*s),(y*z)*(1-c)-(x*s),(z*z)*(1-c)+c,0,
0,0,0,1)

where c is cos(90) and s is sin(90).

I am sure there are flaws in my process / math and if anyone could point them out i would be thankfull.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ultraseamus
Well as i understand it i need to rotate the model space Y axis (0,1,0) onto target vector (x,y,z), so by crossing (0,1,0) with (x,y,z) that should produce the axis of rotation right? I think i got the solution to my problem in the end, but it seems the object i am rotating is off by a few degrees.
Seems like you're mixing world and local space here, which won't work. The terminology can be a bit confusing, but what you want is the cross product of the model local up axis as expressed in world space, with the target vector (x,y,z). The up axis you're looking for should be the second row or column of the transformation matrix for the model. (The key idea here is that for the result to make sense, the two vectors in question need to be in the same space, in this case world space.)

That could probably be clearer, so let me know if it doesn't make sense.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!