PsyOps

RotationUpdate

Jan 5th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. private byte adjust(PlayerPositionEvent OldBotPos, ushort newX, ushort newY)
  2. {
  3.  
  4. //setting info to variables (i can take this out later)
  5. ushort new_bot_x = newX;
  6. ushort new_bot_y = newY;
  7. ushort old_bot_x = OldBotPos.MapPositionX;
  8. ushort old_bot_y = OldBotPos.MapPositionY;
  9.  
  10. // Formula to extract an angle
  11. double angle = Math.Atan((double)(new_bot_y - old_bot_y) / (double)(new_bot_x - old_bot_x)) * (180.0 / 3.14159);
  12. byte rot = 0;
  13.  
  14. // with formula we get 0-90 degrees for each quadrant
  15. // here we simply find out which quadrant it is and add the proper increment to make it rotation 0-39
  16. if (new_bot_x > old_bot_x)
  17. {
  18. if (new_bot_y > old_bot_y)// Lower Right
  19. rot = (byte)Math.Floor((angle / 9) + 10);
  20. else if (new_bot_y < old_bot_y)// Top Right
  21. rot = (byte)Math.Floor((90 + angle) / 9);
  22. }
  23. else if (new_bot_x < old_bot_x)
  24. {
  25. if (new_bot_y > old_bot_y)// Lower Left
  26. rot = (byte)Math.Floor(((90 + angle) / 9) + 20);
  27. else if (new_bot_y < old_bot_y)// Top Left
  28. rot = (byte)Math.Floor((angle / 9) + 30);
  29. }
  30. return rot;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment