2
0

Functions_-_angledifference.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "raylib.h"
  2. #include <math.h>
  3. static float angledifference(float angle1, float angle2);
  4. int main(void)
  5. {
  6. // Initialization
  7. //--------------------------------------------------------------------------------------
  8. const int screenWidth = 800;
  9. const int screenHeight = 450;
  10. InitWindow(screenWidth, screenHeight, "raylib example.");
  11. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  12. //--------------------------------------------------------------------------------------
  13. // Main game loop
  14. while (!WindowShouldClose()) // Detect window close button or ESC key
  15. {
  16. // Update
  17. //----------------------------------------------------------------------------------
  18. //----------------------------------------------------------------------------------
  19. // Draw
  20. //----------------------------------------------------------------------------------
  21. BeginDrawing();
  22. ClearBackground(RAYWHITE);
  23. EndDrawing();
  24. //----------------------------------------------------------------------------------
  25. }
  26. // De-Initialization
  27. //--------------------------------------------------------------------------------------
  28. CloseWindow(); // Close window and OpenGL context
  29. //--------------------------------------------------------------------------------------
  30. return 0;
  31. }
  32. // takes radian iput! <0 is left is shorter else right turn is shorter.
  33. // When it outputs >3 you can asume it aligns with the target(2) angle.
  34. float angledifference(float angle1, float angle2){
  35. float difference = angle1 - angle2;
  36. while (difference < -PI){
  37. difference += (PI*2);
  38. }
  39. while (difference > PI){
  40. difference -= (PI*2);
  41. }
  42. return difference;
  43. }