This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Orbiter.h

By: a guest on Jan 21st, 2011  |  syntax: C++  |  size: 1.53 KB  |  views: 42  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #ifndef ORBITER_H
  2. #define ORBITER_H
  3.  
  4. #include "../Defines.h"
  5. class Orbiter
  6. {
  7.     public:
  8.         Orbiter() {}
  9.         Orbiter(float t_x, float t_y){x = t_x;y=t_y;}
  10.         virtual ~Orbiter() {}
  11.         void ApplyGravity(float c_x, float c_y)
  12.         {
  13.             float difx = c_x-x;
  14.             float dify = c_y-y;
  15.             float f = 1/((difx*difx)+(dify*dify));
  16.             ax+= f*difx;
  17.             ay+= f*dify;
  18.             x+=ax;
  19.             y+=ay;
  20.         }
  21.         void ApplyForce(float f_x, float f_y)
  22.         {
  23.             ax+=f_x;ay+=f_y;
  24.         }
  25.         void Trace_Path(float f_x, float f_y, int iterations)
  26.         {
  27.             glColor4f(1.0,1.0,1.0,0.05);
  28.             glBegin(GL_LINE_STRIP);
  29.                 float tempax, tempay,tempx,tempy;
  30.                 tempax = ax;
  31.                 tempay = ay;
  32.                 tempx = x;
  33.                 tempy = y;
  34.                 for(int i = 0;i<iterations+2;i++)
  35.                 {
  36.                     //tempx+=tempax;
  37.                     //tempy+=tempay;
  38.                     glVertex2f(tempx,tempy);
  39.                     float tempdifx = f_x-tempx;
  40.                     float tempdify = f_y-tempy;
  41.                     float tf = 1/((tempdifx*tempdifx)+(tempdify*tempdify));
  42.                     tempax+= tf*tempdifx;
  43.                     tempay+= tf*tempdify;
  44.                     tempx+=tempax;
  45.                     tempy+=tempay;
  46.                 }
  47.             glEnd();
  48.             glColor4f(1.0,1.0,1.0,1.0);
  49.         }
  50.         float x,y;
  51.         float ax, ay;
  52.     protected:
  53.     private:
  54. };
  55.  
  56. #endif // ORBITER_H
clone this paste RAW Paste Data