Jump to content
  • Advertisement

Archived

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

tripclaw

difference between angles (-180 to +180)

This topic is 5714 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 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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
the +180->-180 angles are only used for first person cameras for other cams use 0->360 as stated above

Share this post


Link to post
Share on other sites
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

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!