difference between angles (-180 to +180)

Started by
2 comments, last by tripclaw 20 years, 12 months ago
Hi. I''m just a hobby game programmer but have recently run into a problem a few weeks ago that I can''t seem to work out. I have a delayed camera that rotates around my character, using the difference between the angles to smoothly rotate the camera around it. The problem is when I get to 180 and cross over into -180 the simple subtraction formula doesn''t work. Plus, if I have for example, -175 to +175 I don''t get the correct difference, it should be 10. Can anyone point me in the right direction on how I should be approaching this?
Advertisement
Why use -180 to 180? Why not just go from 0 to 360? If the angle ends up above 360, just subtract 360. If it ends up below zero, just add 360. Seems simple enough.

Of course, the same could be done with your method, but 0 to 360 seems simpler to me.

[edited by - micepick on April 19, 2003 11:10:09 AM]
the +180->-180 angles are only used for first person cameras for other cams use 0->360 as stated above
http://www.8ung.at/basiror/theironcross.html
Thank you guys so much ! You opened my eyes to the simple solution. After trying so many techniques I ended up only needing two lines right after I determin the difference:

If diffY > 180 Then diffY = diffY - 360
If diffY < -180 Then diffY = diffY + 360

This topic is closed to new replies.

Advertisement