Jump to content
  • Advertisement


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


Rotation/Angle Calculation

This topic is 5403 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 all, I have a class that needs to take the following information: - Starting Point - Length - Rotation along X, Y and Z Axis and calculate the point at the end of the line. I remember learning how to do something similar 2D, but I can''t recall how I did it. I''ve been fighting with the problem all afternoon (in my head as well as in code). Any help would be incredibly, greatly, wonderfully appreciated. Thanks ahead of time. - Alex Broadwin - Domini Noctum Games - My Journal - The All-Knowing One

Share this post

Link to post
Share on other sites
Well, using matrices, you could rotate a matrix by X, then Y, then Z (or in another order). Which would give you a matrix that you can just multiply by the length (which is a
x length vector in some specific direction) ...

Or you could use the much more 'usefull' quaterions, which for me was easier to get pointing where i wanted them. (simply axis, and angle around axis). But this depends on what exactly you were doing...

Quick way I'd try it (dunno how your angles come together, but watch out for gimbal lock if you do it like this) Saying that length is in X-axis, your starting vector would be:
V.X = Length
V.Y = 0
V.Z = 0

Then Rotate by X,Y and Z angles one after the other

(Vector O is old vector, Vector V is new vector)
Rotate around X axis by Angle A
V.X = O.X
V.Y = Cos(A)*O.Y - Sin(A)*O.Z
V.Z = Cos(A)*O.Z + Sin(A)*O.Y

Rotate around Y axis by Angle A
(remember that O should now be the V from the previous step)
V.X = Cos(A)*O.X - Sin(A)*O.Z
V.Y = O.Z
V.Z = Cos(A)*O.Z + Sin(A)*O.X

Rotate around Z axis by Angle A
(Again O = old V)
V.X = Cos(A)*O.X - Sin(A)*O.Y
V.Y = Cos(A)*O.Y + Sin(A)*O.X
V.Z = O.Z

Finally, add the starting Point vector (S)
V.X = O.X + S.X
V.Y = O.Y + S.Y
V.Z = O.Z + S.Z

[edited by - PyroSA on February 27, 2004 2:41:30 AM]

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!