Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Blackstream

Question on Rotation

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

Hello, I was reading the 3d tutorials, and I came across a problem. First of all, I understand (I think) these formulas sin(a+b) = sin(a) * cos(b) + sin(b) * cos(a) cos(a+b) = cos(a) * cos(b) - sin(a) * sin(b) (Correct me if I have these wrong) Now, the tutorials say that to rotate a 3d point, you simply do that 3 times, one for each axis, the code (out of one tutorial) looks something like this rotated.x = orig.x; rotated.y = cos(x)*orig.y - sin(x)*orig.z; rotated.z = sin(x)*orig.y + cos(x)*orig.z; rotated.x = cos(y)*rotated.x - sin(y)*rotated.y; rotated.y = sin(y)*rotated.x + cos(y)*rotated.y; rotated.z = rotated.z; rotated.x = cos(z)*rotated.x - sin(z)*rotated.z; rotated.y = rotated.y; rotated.z = sin(z)*rotated.x + cos(z)*rotated.z; Now, the y axis rotation makes sense, it is just like rotating a 2d point, but the x axis doesn''t, to me. Shouldn''t the formula''s be reversed? As in... rotated.x = orig.x; rotated.y = sin(x)*orig.z + cos(x)*orig.y; rotated.z = cos(x)*orig.z - sin(x)*orig.y; I''m all confused... -Blackstream "Just you wait until I buy a compiler! Then I will make buggy programs that I am allowed to distribute"

Share this post


Link to post
Share on other sites
Advertisement
The first formulas are OK... i think. What can be wrong in them is the sign (that depends whether you`re using righ-handed or left-handed systems). If you`re still not to sure try crosschecking with other 3d tutorials (for example 3DICA).
One other thing, free compilers were already invented. Try DJGPP, one off the bests.

Share this post


Link to post
Share on other sites
Actually the matrices should be the same for both left-handed and right-handed systems. What does matter is how the matrices are designed to be used, either:

V1Rot = V1*Matrix1

or

V2Rot = Matrix2*V2

The difference between these two matrices are minimal. Matrix1 = Matrix2T. V1 and V1Rot are row vectors while V2 and V2Rot are column vectors.



- WitchLord

Share this post


Link to post
Share on other sites
Thanks for the help. Um, I didn''t quite follow you Witchlord, I bearly understand 3D math, unfortunately, and just the sines and cosines, none of the matrices or anything. I know I''m not going any further with this until I''ve had a little more math.

About the free compilers, I am aware of their existance, and I actually almost got DJGPP. The only problem is that DJGPP is for DOS and I am trying to focus on Windows and DirectX at the moment. There are some free compilers for windows as well, but I think I''ll just get Visual C++. Thanks anyways, though.

Actually, I do have a DOS compiler that isn''t an introductory compiler or anything. It''s Turbo C++ 4.0 for DOS, although I will admit, it isn''t as good as DGJPP because it is only 640k of RAM accessable.

-Blackstream

"Just you wait until I buy a compiler! Then I will make buggy programs that I am allowed to distribute"

Share this post


Link to post
Share on other sites
Oops, I should have mixed in matrices. You didn''t use them in your post so I don''t know where that comes from. Ignore that for now

What my previous post was about was to correct wolverine. The rotation formulas _are_ the same for both left-handed and right-handed systems.

If you don''t know already a left handed system is where the x-axis is to the right the y-axis is up and the z-axis points away from you (or into the screen for 3D graphics).
For the right-hand system the z-axis points towards you.

Now for your rotation formulas. You must know in which direction a positive angle rotates the coordinate. When looking down the negative x-axis the positive angle is defined from the y-axis to the z-axis. When looking down the negative y-axis the positive angle is from the z-axis to the x-axis. And finally when looking down the negative z-axis the positive angle is from the x-axis to the y-axis.

x => y -> z
y => z -> x
z => x -> y

With that in mind you can verify your formulas by inserting an angle of 90 degrees and check that they in fact rotate the way described above. (cos 90 = 0, sin 90 = 1)

From this I see that the formula for rotating about the y-axis is wrong it should be:

rotated.x = cos(z)*rotated.x + sin(z)*rotated.z;
rotated.y = rotated.y;
rotated.z = -sin(z)*rotated.x + cos(z)*rotated.z;

The others are correct.

I hope this clears it up, if it doesn''t ask again because I can get a bit technical at times.



- WitchLord

Share this post


Link to post
Share on other sites

  • 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!