Jump to content
  • Advertisement
Sign in to follow this  

Trig in 3D Rotations?

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

Say I was going to rotate a 3D field...like a fighting arena, on its y axis. I know that the matrix for y rotations involves trigonomic functions...but for that to happen, you need a right triangle and a reference angle. My question is: if it's not clearly a triangle...and it's something like a character, or an entire level....how you do determine its reference angle, and the size and location of the triangle?

Share this post

Link to post
Share on other sites
Define everything by points, say the midpoint of a character, the middle of a level etc. Once you have everything as a point, you can find the angles between them (3 points defines a triangle). I usually use the origin (0,0) as the reference point, so the other 2 are just the objects:



Need A-O-B. Law of Cosines:
AB2 = AO2 + BO2 - 2 * AO * BO * cos(A-O-B)

Where AO = sqr(62 + 12)
BO = sqr(32 + 32)
AB = sqr(32 + 22)
(distance formula to find distance between points)
(don't forget this still works with 3 dimensions: dist=sqr(x2+y2+z2)!

cos(A-O-B) = AB2 -AO2 - BO2/-2 * AO * BO

And voila! You have your angle!
...I hate trig.

If I got that wrong, someone please correct me. It's been awhile! [lol]

Share this post

Link to post
Share on other sites
The relation to a right triangle can be seen by rotating the coordinate axes, i.e. (1,0,0), (0,1,0) and (0,0,1). What happens to (1,0,0) tells you what the first column should be assuming it is a matrix times a vector. So a rotation by t around the z axis take (1,0,0) to (cos(t),sin(t)) and (0,1,0) to (-sin(t),cos(t)).

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!