#include #include #include #include #include using namespace std; //fstream output("data.txt",ios::out); double dt = 0.05; // this is the time step float coeF = 0.5; float verysmall = 0.001; float totaltime = 0.0; float gravity = 0.1; GLfloat near = 0.1,far = 20.0; GLfloat startdispz = -1.0; const float DEG2RAD = 3.14159/180; class ball { private: // ax acceleration in x, px position in x, vx velocity in x double ax,ay,az,px,py,pz,vx,vy,vz,size; public: ball() { px=0.0;py=0.0; } ball(double dummyvx, double dummyvy,double dummyvz) { px=0; py=0.1; pz=0; size=0.1; vx=dummyvx; vy=dummyvy; vz=dummyvz; ay=gravity; } double getpx(){return px;} double getpy(){return py;} double getpz(){return pz;} double getvx(){return vx;} double getvy(){return vy;} double getvz(){return vz;} double getballsize(){return size;} double getspeed(){return sqrt(py*py + px*px + pz*pz);} void evolve() { //cout << "vy" << vy << "\n"; vy += (-gravity*dt); // equation for the y component of v px += vx*dt; py += vy*dt; pz += vz*dt; // equations for all 3 components of p totaltime += dt; // update total time //output << totaltime << " " << px << " " << py << " " << pz << "\n"; //cout << totaltime << " " << py << " " << pz << "\n"; //terminate when we hit the ground i.e pz < 0 if(py < size) { py = size; vy = -vy*coeF; //cout << "The ball has hit the ground\n"; //vx=0; vy=0; vz=0; //output.close(); //exit(0); } } }; // ball start at origin with velocity vector as in the constructor ball golfball(0.0, 0.4, 0.8); void init(void) { glClearColor(1.0,1.0,1.0,0.0); } void drawCircle(float Radius, int numPoints) { glBegin( GL_LINE_LOOP ); for( int i=0; i