
Orbiter.h
By: a guest on
Jan 21st, 2011 | syntax:
C++ | size: 1.53 KB | views:
42 | expires: Never
#ifndef ORBITER_H
#define ORBITER_H
#include "../Defines.h"
class Orbiter
{
public:
Orbiter() {}
Orbiter(float t_x, float t_y){x = t_x;y=t_y;}
virtual ~Orbiter() {}
void ApplyGravity(float c_x, float c_y)
{
float difx = c_x-x;
float dify = c_y-y;
float f = 1/((difx*difx)+(dify*dify));
ax+= f*difx;
ay+= f*dify;
x+=ax;
y+=ay;
}
void ApplyForce(float f_x, float f_y)
{
ax+=f_x;ay+=f_y;
}
void Trace_Path(float f_x, float f_y, int iterations)
{
glColor4f(1.0,1.0,1.0,0.05);
glBegin(GL_LINE_STRIP);
float tempax, tempay,tempx,tempy;
tempax = ax;
tempay = ay;
tempx = x;
tempy = y;
for(int i = 0;i<iterations+2;i++)
{
//tempx+=tempax;
//tempy+=tempay;
glVertex2f(tempx,tempy);
float tempdifx = f_x-tempx;
float tempdify = f_y-tempy;
float tf = 1/((tempdifx*tempdifx)+(tempdify*tempdify));
tempax+= tf*tempdifx;
tempay+= tf*tempdify;
tempx+=tempax;
tempy+=tempay;
}
glEnd();
glColor4f(1.0,1.0,1.0,1.0);
}
float x,y;
float ax, ay;
protected:
private:
};
#endif // ORBITER_H