Advertisement
KeithS

Trig_Blog_Sample_4

Aug 2nd, 2012
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <math.h>
  2. #include <cstdio>
  3. #include <unistd.h>
  4.  
  5. int main()
  6. {
  7.    
  8.  struct ship
  9.     {
  10.         float x_pos;
  11.         float y_pos;
  12.  
  13.        float spd;
  14.     };
  15.  
  16.     ship my_ship;
  17.     my_ship.spd = 10.0f;
  18.     my_ship.x_pos = 0.0f;
  19.     my_ship.y_pos = 0.0f;
  20.  
  21.     float angle = -0.785f;
  22.     float x_ratio = cosf(angle);
  23.     float y_ratio = sinf(angle);
  24.     float x_spd_comp = my_ship.spd * x_ratio;
  25.     float y_spd_comp = my_ship.spd * y_ratio;
  26.  
  27.     int cnt = 0;
  28.  
  29.     while(cnt < 250)
  30.     {
  31.         my_ship.x_pos += x_spd_comp;
  32.         my_ship.y_pos += y_spd_comp;
  33.         printf("Ship X Pos = %.2f,  Ship Y Pos = %.2f\n", my_ship.x_pos, my_ship.y_pos);
  34.         usleep(75000);
  35.         cnt++;
  36.     }
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement