#include #include #include #include #include //#include #define PI 3.14159265359 SDL_Surface* screen; const int screen_width = 640; const int screen_height = 480; const int ball_radius = 20; int x = 46, y = 17, delta_x = 2, delta_y = 1, energy_loss = 0; void error(void) { // I guess shit went wrong. printf("Oh No!/n"); exit(0); } void draw_circle(float x, float y, float r) { glBegin(GL_TRIANGLE_FAN); glVertex2f(x, y); int i; for (i=0; i<64; i++) { float theta = 2*PI*i/63; float nx = x + cosf(theta)*r, ny = y + sinf(theta)*r; glVertex2f(nx, ny); } glEnd(); } void draw_screen(void) { if (SDL_MUSTLOCK(screen) && SDL_LockSurface(screen) < 0) return; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Sets the view to be orthographic glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, screen_width, screen_height, 0, 0, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor4f(1.0, 0.0, 0.0, 1.0); /* glBegin(GL_QUADS); glVertex2f(0.2, 0.2); glVertex2f(0.2, 0.5); glVertex2f(0.5, 0.5); glVertex2f(0.5, 0.2); glEnd(); */ /*Wall bounce*/ x=x+delta_x; if (x>(screen_width-(2*ball_radius))){ delta_x *= -1;}; if (x< 0){ delta_x *= -1 ;}; if (delta_y == 0){delta_y=1;}; y=y+delta_y; if (delta_y>= 0){delta_y = sqrt(2*.2*(y));}; if (delta_y< 0){delta_y = -1 * sqrt(2*.2*(y));}; //printf("delta y is%d\n",delta_y ); //printf("y is%d\n",y ); if (y>(screen_height-(2*ball_radius))){ delta_y *= -1;}; if (y< 0){ delta_y *= -2 ; energy_loss += 1 ;}; //y += energy_loss; draw_circle(x, y, ball_radius); /*Gravity*/ //delta_y = sqrt(2*.8*y); SDL_GL_SwapBuffers(); if (SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); SDL_Flip(screen); } int main(int argc, char** argv) { //if (argc != 2) // error(); if (SDL_Init(SDL_INIT_VIDEO) < 0) error(); const SDL_VideoInfo* info = SDL_GetVideoInfo(); if (info == NULL) error(); // screen_width = info->current_w; // screen_height = info->current_h; int videoFlags = 0; videoFlags = SDL_OPENGL; /* Enable OpenGL in SDL */ videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */ videoFlags |= SDL_HWPALETTE; /* Store the palette in hardware */ // videoFlags |= SDL_RESIZABLE; /* Enable window resizing */ // videoFlags |= SDL_FULLSCREEN; // Limits framerate to whatever the vrefresh rate is. SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); screen = SDL_SetVideoMode(screen_width, screen_height, 32, videoFlags); if (screen == NULL) error(); glClearColor(0.1, 0.1, 0.1, 1.0); // Set sky color. glDisable(GL_DEPTH_TEST); glEnable(GL_COLOR_MATERIAL); /* int numcells = atoi(argv[1]); //set number of processes if (numcells == 1) error(); //prevent one process from being used if (numcells % 2) numcells--; // make even if odd */ while (1) { draw_screen(); SDL_Event ev; while (SDL_PollEvent(&ev)) { if (ev.type == SDL_QUIT || (ev.type == SDL_KEYDOWN && ev.key.keysym.sym == 27)) { SDL_Quit(); return 0; } } } }