Angles and ship navigation

Talk about making games.

Angles and ship navigation

Postby BeyondtheTech » Thu Aug 18, 2005 8:30 pm

I'm having a serious problem with angles.

Suppose I'm traveling at 0 or 10 degrees (right), and I choose to go 270 or 350 degrees. The ship always chooses to go the long way around. My logic is faulty and doesn't seem to want to go the shorter angle, not that I can seem to determine it anyway.

What statements can I use to get the delta angle in plus or minus?

Thanks. I'm stumped.
User avatar
BeyondtheTech
 
Posts: 270
Joined: Wed Mar 30, 2005 6:34 am
Location: Edison, NJ
Score: 4 Give a positive score

Postby NyahKitty » Fri Aug 19, 2005 7:24 pm

I'm not that far along in writing code, but wouldn't you want a test loop that checks to see which would be the shortest route to the new heading?
Samples of my art can be found at:

http://www.HodgePodgeStudios.com
User avatar
NyahKitty
 
Posts: 65
Joined: Fri Jul 29, 2005 1:28 am
Score: 0 Give a positive score

Postby jazz_e_bob » Fri Aug 19, 2005 8:24 pm

Code: Select all
// which is the best direction to turn to get to new angle?

int bestRotationFor( double currentAngle, double newAngle )
{
  double toRight;
  double toLeft;
  double AL = myAngle;
  double AR = newAngle;
 
  if ( AR > AL )
  {
    toRight = AL + 360 - AR;
    toLeft = AR - AL;
  }
  else
  {
    toRight = AL - AR;
    toLeft = 360 - AL + AR;
  }


  if ( toRight < toLeft )
    return ROTATING_RIGHT;
  else
    return ROTATING_LEFT;
}
Controlling complexity is the essence of computer programming.
User avatar
jazz_e_bob
 
Posts: 742
Joined: Tue Jul 01, 2003 9:38 pm
Location: Bloke from Cockatoo Creek Australia
Score: 14 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest