Jump to content
  • Advertisement
Sign in to follow this  
reani

OpenGL opengl rotation

This topic is 4079 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

Hi, I'm looking for some help for a very tricky opengl rotation. Assume two coordinate systems, where the origin is the same. The first coordinate system is the standard opengl coordinate system(no rotation) and the second one is somehow rotated where have the defining coordinates. Now I want to rotate the first coordinate system to match with the second one. Theoretically it is clear to me that, first rotate the first x axis x1 to the second x axis x2. The second step is to rotate y1 to y2. I only need two rotations because the first rotation axis is a normal vector to both x axes. The implementation looks like: (x0, y0, z0) is the x-axis and (x1, y1, z1) is the y-axis of the second coordinate system //first rotation double angle = calcAngle( x0, y0, z0, 1.0, 0.0, 0.0 ); TArray<double> fcProd = crossProduct( x0, y0, z0, 1.0, 0.0, 0.0 ); glRotated( -angle, fcProd[0], fcProd[1], fcProd[2] ); //second rotation double angle2 = calcAngle( x1, y1, z1, 0.0, 1.0, 0.0 ); glRotated( -angle2, 1.0, 0.0, 0.0 ); The second rotation or the calculation seems to be right, but it isn't (I tried it in my program). It is very tricky to calculate the angle. Set x2 as the rotation axis is correct - otherwise the first rotation would be wrong. Can anybody figure out how the second angle should be calculated? Hope someone can help! It is not easy to describe, so feel free to ask if something is not understandable. Regards reani

Share this post


Link to post
Share on other sites
Advertisement
If you have both coordinate systems expressed as matrices you can calculate the difference using some matrix math. Your second matrix M2 might be expressed as M1 * Mx = M2 where Mx is the matrix difference you look for, so rearange the equation: Mx = M2 * M1-1.

If M1 is the identity matrix, it's simpler: Mx = M2.

Now extract the angles from Mx.

Share this post


Link to post
Share on other sites
thanks for the swift response, but what if I didn't express the coordinate systems as matrices? Only in coordinates. It would be a damn work to put the coordinates into a matrix.

regards
reani

Share this post


Link to post
Share on other sites
OK, I'm not an expert in matrix math but I'd try the following:

1. Select two points A and B and normalize the vectors.

2. Calculate the normal N of the plane defined by A and B: A x B (cross product)

3. From vector A and N calculate the perpendicular vector R: A x R (cross product)

4. Construct the rotation matrix from A, N and R (all normalized).

5. - 8. Repeat step 1 to 4 for the corresponding rotated points A' and B'.

Now you should end up in 2 matrices which you can use to get the euler angles from.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lord_Evil
If you have both coordinate systems expressed as matrices you can calculate the difference using some matrix math. Your second matrix M2 might be expressed as M1 * Mx = M2 where Mx is the matrix difference you look for, so rearange the equation: Mx = M2 * M1-1.

If M1 is the identity matrix, it's simpler: Mx = M2.

Now extract the angles from Mx.


I believe the correct rearranged version with Mx as the subject would be Mx = M1-1 * M2

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!