/** * Returns 1 if the bird at height h collides with an object, 0 otherwise. */ int bird_collide(int h) { int ret = detect_collision(h, BIRD_POS+3) || detect_collision(h, BIRD_POS) || detect_collision(h+1, BIRD_POS+4) || detect_collision(h+1, BIRD_POS+3) || detect_collision(h+1, BIRD_POS); return ret; }
void Game::refresh() { if(level_reset_requested) reset_level_commit(); if(full_reset_requested) reset_all_commit(); for(auto it = actions.begin(); it != actions.end(); ) { if(--it->first == 0) { it->second(); actions.erase(it++); } else ++it; } for(auto it1 = entities.begin(); it1 != std::prev(entities.end()); ++it1) { for(auto it2 = it1; it2 != entities.end(); ++it2) { if(detect_collision((*it1)->hitbox(), (*it2)->hitbox())) (*it1)->collide_with(**it2); } } for(auto& entity : entities) if(entity) { bool should_destroy = entity->refresh(*this); if(should_destroy || !detect_collision(entity->hitbox(), current_game_area_hitbox())) entity.reset(); } for(auto it = entities_to_activate.begin(); it != entities_to_activate.end();) { if(!is_it_reachable((*it)->hitbox())) { auto erased_entity_iterator = it++; entities_to_activate.erase(erased_entity_iterator); } else if(detect_collision((*it)->hitbox(), current_game_area_hitbox())) { auto moved_entity_iterator = it++; entities.push_back(*moved_entity_iterator); entities_to_activate.erase(moved_entity_iterator); } else break; } for(auto& entity : entities_to_add) push_to_container(entity); entities.erase(std::remove(entities.begin(), entities.end(), nullptr), entities.end()); entities_to_add.clear(); }
// ball paddle collision handler void ball_paddle(sprite_t* s1, sprite_t* s2) { sprite_t* ball; sprite_t* paddle; unsigned int collision_direction; ball = s1->type == BALL_SPRITE ? s1 : s2; paddle = s1->type == PADDLE_SPRITE ? s1 : s2; sound_play_fast_invader(0); collision_direction = detect_collision(paddle, ball); if (collision_direction == NORTH_COLLISION && breakout_data.ball_speed_y > 0 ) //|| collision_direction == SOUTH_COLLISION ) { breakout_data.ball_speed_y = -breakout_data.ball_speed_y; breakout_data.ball_speed_x += breakout_data.paddle_speed_x / 8; // Make sure the ball is above the paddle to avoid multiple collition between the ball and the paddle ball->center_pos_y = paddle->center_pos_y - (paddle->size_y_div_2 + ball->size_y_div_2); } if (collision_direction == EAST_COLLISION || collision_direction == WEST_COLLISION ) { breakout_data.ball_in_play = false; sprite_release(&breakout_sprites_vector, ball); } }
// brick ball collision handler void brick_ball(sprite_t* s1, sprite_t* s2) { sprite_t* ball; sprite_t* brick; unsigned int collision_direction; ball = s1->type == BALL_SPRITE ? s1 : s2; brick = s1->type == BRICK_SPRITE ? s1 : s2; collision_direction = detect_collision(ball, brick); if (collision_direction == NORTH_COLLISION || collision_direction == SOUTH_COLLISION ) breakout_data.ball_speed_y = -breakout_data.ball_speed_y; if (collision_direction == EAST_COLLISION || collision_direction == WEST_COLLISION ) breakout_data.ball_speed_x = -breakout_data.ball_speed_x; ball_tick(ball); breakout_data.num_bricks--; if (breakout_data.num_bricks) { //sound_play_enemy_killed(); sound_play_shoot(); } else { sound_play_big_explosion(); } sprite_release(&breakout_sprites_vector, brick); }
int CMenu::CheckMouseOver() { int mouse_x, mouse_y; SDL_GetMouseState(&mouse_x, &mouse_y); SDL_Rect mouse = {mouse_x, mouse_y, 0, 0}; for(size_t i = 0; i < this->Buttons.size(); i++) { SDL_Rect button = this->Buttons[i]->norm->clip_rect; button.x = this->Buttons[i]->x; button.y = this->Buttons[i]->y; if(detect_collision(mouse, button)) { this->Buttons[i]->active = this->Buttons[i]->high; if(IsPressed(SDL_BUTTON_LEFT)) return this->Buttons[i]->id; } else { this->Buttons[i]->active = this->Buttons[i]->norm; } } return -1; }
void Game::push_to_container(std::shared_ptr<Entity> e) { if(!is_it_reachable(e->hitbox())) return; else if(detect_collision(current_game_area_hitbox(), e->hitbox())) entities.push_back(e); else entities_to_activate.insert(e); }
bool is_land_at(Game& game, Zespolona pozycja) { for(auto& entity : game.active_entities()) { if(dynamic_cast<Land*>(entity.get())) { bool land = detect_collision(entity->hitbox(), AxisAlignedBoundingBox(pozycja - Zespolona(10, 10), pozycja + Zespolona(10, 10))); if(land) return true; } } return false; }
// Checks if the snake has bitten itself bool playerSnake::touched_self(){ // Locate position of the head SDL_Rect locHead = mparts_locations.at(0); SDL_Rect part; // Now check if the head has collided with other elements of the body for(int i = 1; i < mparts_locations.size(); i ++){ part = mparts_locations.at(i); if(detect_collision(locHead, part) == true){ return true; } } return false; }
// If true, player is dead. int is_player_dead( EntityClass* player_ship ) { for( int i = 0; i < enemy_num; i++ ) { if( enemies[i].row != 0 ) { if( detect_collision( player_ship, &enemies[i] ) == 1 ) { return 1; } } } return 0; }
void check_collisions() { for( int i = 0; i < max_enemies; i++ ) { for( int j = 0; j < projectile_num; j++ ) { if( detect_collision( &enemies[i], &projectiles[j] ) == 1 ) { enemies[i] = enemies[max_enemies+1]; projectiles[j] = projectiles[max_projectiles+1]; kills++; break; } } } }
/** Calculate non bonded forces between a pair of particles. @param p1 pointer to particle 1. @param p2 pointer to particle 2. @param d vector between p1 and p2. @param dist distance between p1 and p2. @param dist2 distance squared between p1 and p2. */ inline void add_non_bonded_pair_force(Particle *p1, Particle *p2, double d[3], double dist, double dist2) { IA_parameters *ia_params = get_ia_param(p1->p.type,p2->p.type); double force[3] = { 0., 0., 0. }; double torque1[3] = { 0., 0., 0. }; double torque2[3] = { 0., 0., 0. }; int j; /***********************************************/ /* bond creation and breaking */ /***********************************************/ #ifdef COLLISION_DETECTION if (collision_params.mode > 0) detect_collision(p1,p2); #endif /*affinity potential*/ #ifdef AFFINITY add_affinity_pair_force(p1,p2,ia_params,d,dist,force); #endif FORCE_TRACE(fprintf(stderr, "%d: interaction %d<->%d dist %f\n", this_node, p1->p.identity, p2->p.identity, dist)); /***********************************************/ /* thermostat */ /***********************************************/ #ifdef DPD /* DPD thermostat forces */ if ( thermo_switch & THERMO_DPD ) add_dpd_thermo_pair_force(p1,p2,d,dist,dist2); #endif /** The inter dpd force should not be part of the virial #ifdef INTER_DPD add_inter_dpd_pair_force(p1,p2,ia_params,d,dist,dist2); #endif /***********************************************/ /* non bonded pair potentials */ /***********************************************/ calc_non_bonded_pair_force(p1,p2,ia_params,d,dist,dist2,force,torque1,torque2); /***********************************************/ /* short range electrostatics */ /***********************************************/ #ifdef ELECTROSTATICS if (coulomb.method == COULOMB_DH) add_dh_coulomb_pair_force(p1,p2,d,dist,force); if (coulomb.method == COULOMB_RF) add_rf_coulomb_pair_force(p1,p2,d,dist,force); #endif /*********************************************************************/ /* everything before this contributes to the virial pressure in NpT, */ /* but nothing afterwards */ /*********************************************************************/ #ifdef NPT for (j = 0; j < 3; j++) if(integ_switch == INTEG_METHOD_NPT_ISO) nptiso.p_vir[j] += force[j] * d[j]; #endif /***********************************************/ /* semi-bonded multi-body potentials */ /***********************************************/ /* Directional LJ */ #ifdef LJ_ANGLE /* This is a multi-body forces that changes the forces of 6 particles */ add_ljangle_force(p1, p2, ia_params, d, dist); #endif /***********************************************/ /* long range electrostatics */ /***********************************************/ #ifdef ELECTROSTATICS /* real space coulomb */ double q1q2 = p1->p.q*p2->p.q; switch (coulomb.method) { #ifdef P3M case COULOMB_ELC_P3M: { if (q1q2) { p3m_add_pair_force(q1q2,d,dist2,dist,force); // forces from the virtual charges // they go directly onto the particles, since they are not pairwise forces if (elc_params.dielectric_contrast_on) ELC_P3M_dielectric_layers_force_contribution(p1, p2, p1->f.f, p2->f.f); } break; } case COULOMB_P3M_GPU: case COULOMB_P3M: { #ifdef NPT if (q1q2) { double eng = p3m_add_pair_force(q1q2,d,dist2,dist,force); if(integ_switch == INTEG_METHOD_NPT_ISO) nptiso.p_vir[0] += eng; } #else if (q1q2) p3m_add_pair_force(q1q2,d,dist2,dist,force); #endif break; } #endif case COULOMB_MMM1D: if (q1q2) add_mmm1d_coulomb_pair_force(q1q2,d,dist2,dist,force); break; case COULOMB_MMM2D: if (q1q2) add_mmm2d_coulomb_pair_force(q1q2,d,dist2,dist,force); break; #ifdef EWALD_GPU case COULOMB_EWALD_GPU: if (q1q2) add_ewald_gpu_coulomb_pair_force(p1,p2,d,dist,force); break; #endif default: break; } #endif /*ifdef ELECTROSTATICS */ /***********************************************/ /* long range magnetostatics */ /***********************************************/ #ifdef DIPOLES /* real space magnetic dipole-dipole */ switch (coulomb.Dmethod) { #ifdef DP3M case DIPOLAR_MDLC_P3M: //fall trough case DIPOLAR_P3M: { #ifdef NPT double eng = dp3m_add_pair_force(p1,p2,d,dist2,dist,force); if(integ_switch == INTEG_METHOD_NPT_ISO) nptiso.p_vir[0] += eng; #else dp3m_add_pair_force(p1,p2,d,dist2,dist,force); #endif break; } #endif /*ifdef DP3M */ default: break; } #endif /* ifdef DIPOLES */ /***********************************************/ /* add total nonbonded forces to particle */ /***********************************************/ for (j = 0; j < 3; j++) { p1->f.f[j] += force[j]; p2->f.f[j] -= force[j]; #ifdef ROTATION p1->f.torque[j] += torque1[j]; p2->f.torque[j] += torque2[j]; #endif } }
// Touched the mouse? bool playerSnake::touched_mouse(mouse myMouse){ SDL_Rect mouseLoc =myMouse.get_pos(); SDL_Rect head = mparts_locations.at(0); return detect_collision(mouseLoc, head); }
void keyboard(unsigned char key, int x, int y) { float ypozr,typos1; ypozr=ypoz*3.14/180; switch (key) { case 27: exit(0); break; case 99: if(camera<4) { camera++; } else { camera=0; } break; case 't': int fi; fi=detect_collision(1); if(matrix[tz][tx].type==5) { if(tz==t1z && tx==t1x) { txpos=matrix[t2z][t2x].x1+1; tzpos=matrix[t2z][t2x].z1+1; } else { txpos=matrix[t1z][t1x].x1+1; tzpos=matrix[t1z][t1x].z1+1; } } case 'w': if(camera==4) { if(matrix[sel_i+1][sel_j].type!=1) { sel_i=sel_i+1; } } break; case 'a': if(camera==4) { if(matrix[sel_i][sel_j-1].type!=1) { sel_j=sel_j-1; } } break; case 's': if(camera==4) { if(matrix[sel_i-1][sel_j].type!=1) { sel_i=sel_i-1; } } break; case 'd': if(camera==4) { if(matrix[sel_i][sel_j+1].type!=1) { sel_j=sel_j+1; } } break; case '1': if(camera==3) { zoom=zoom+0.05; } break; case '2': if(camera==3) { zoom=zoom-0.05; } break; case 'r': speed=2.5; break; case ' ': float uy=4.0; float g=4.0; float temp,time=0.1; temp=frangle; frangle=60.0; jump=1; int typ=3; while(typ==3 && uy>1) { time=0.1; while(1) { typos1=uy*time-(g*time*time)/2; tzpos=tzpos+0.06*cos(ypozr)*vel*speed; txpos=txpos+0.06*sin(ypozr)*vel*speed; typos=typos1+typos; display(); col_prev=detect_collision(0); // printf("%f %d %f\n",matrix[tz][tx].height,matrix[tz][tx].type,h-1); if(matrix[tz][tx].type==2 || matrix[tz][tx].type==4) { if(typos<h-1) { tzpos=tzpos-0.06*cos(ypozr)*vel*speed; txpos=txpos-0.06*sin(ypozr)*vel*speed; detect_collision(1); typos=typos-typos1; break; } } else if(matrix[tz][tx].height>typos1) { if(matrix[tz][tx].type!=1) typos=typos-typos1; // printf("%d %d %f %f\n",tx,tz,matrix[tx][tz].height,typos1); break; } typos=typos-typos1; time=time+0.05; } typ=col_prev; uy=uy-1.0; } jump=0; /* for(float time=0.1;time<2.0;time=time+0.1) { typos1=uy*time-(4.0*time*time)/2; tzpos=tzpos+0.12*cos(ypozr)*vel*speed; txpos=txpos+0.12*sin(ypozr)*vel*speed; typos=typos1+typos; display(); typos=typos-typos1; }*/ // col_prev=detect_collision(0); if(col_prev==1) { display(); printf("GAME-OVER-JUMP\n"); sleep(2); exit(0); } frangle=temp; break; } }
void keyboard1(int key, int x, int y) { float ypozr; ypozr=ypoz*3.14/180; if(frangle>20.0) { flag=-1.0*flag; } if(frangle<-20.0) { flag=-1.0*flag; } switch (key) { case GLUT_KEY_LEFT: ypoz=ypoz+5; if (ypoz>360) ypoz=0; glutPostRedisplay(); break; case GLUT_KEY_UP: vel=1.0; frangle=frangle+3.0*flag*speed; tzpos=tzpos+0.08*cos(ypozr)*speed; txpos=txpos+0.08*sin(ypozr)*speed; int col; col=detect_collision(1); if(col==1) { fall(); } if(move==0 && col_prev==0 && h>1.0) { frangle=frangle-3.0*flag*speed; tzpos=tzpos-0.08*cos(ypozr)*speed; txpos=txpos-0.08*sin(ypozr)*speed; col=detect_collision(1); } col_prev=col; //printf("%f %f\n",tzpos,txpos); break; case GLUT_KEY_DOWN: vel=-1.0; speed=1.0; frangle=frangle-3.0*flag; // tzpos=tzpos+0.08; tzpos=tzpos-0.08*cos(ypozr); txpos=txpos-0.08*sin(ypozr); int col1; if(col1==1) { fall(); } col1=detect_collision(1); if(move==0 && col_prev==0 && h>1.0) { frangle=frangle+3.0*flag; // tzpos=tzpos+0.08; tzpos=tzpos+0.08*cos(ypozr); txpos=txpos+0.08*sin(ypozr); col=detect_collision(1); } col_prev=col; break; case GLUT_KEY_RIGHT: ypoz=ypoz-5; if (ypoz<-360) ypoz=0; glutPostRedisplay(); break; } }
bool Game::is_it_reachable(const AxisAlignedBoundingBox& box) const { return detect_collision(AxisAlignedBoundingBox(Zespolona(0, std::numeric_limits<double>::infinity()), Zespolona(level_width(), pozycja_gracza().imag() - 400)), box); }
// called if timer event // id is the id of the timer; you can schedule as many timer events as you want in the callback setup section of glut_setup void my_TimeOut(int id) { double accel, vel, y2; //temporary values for comparisons //BIG for loop for updating particle coordinates with physics for (int aa = 0; aa < 25; aa++) { //Exit if shape hasn't been made yet if (list_of_shapes[aa].p_ptr == NULL) { break; } else { //rectangles dropping if (aa % 2 == 0) { current = ANIMATION_SPEED/1000.0; // get current time change (converted from milliseconds to seconds) //Update particle values using equations from lecture for (int g = 0; g < 4; g++) { accel = list_of_shapes[aa].p_ptr[g].force / list_of_shapes[aa].p_ptr[g].mass; vel = list_of_shapes[aa].p_ptr[g].velocity; //printf("%f - v\n", vel); //DEBUG y2 = list_of_shapes[aa].p_ptr[g].y; list_of_shapes[aa].p_ptr[g].velocity = vel + (accel * current); list_of_shapes[aa].p_ptr[g].y = y2 + (vel * current) + ( (accel*0.5) * (current*current)); } //Update y coordinate of object's center list_of_shapes[aa].curr_y = (list_of_shapes[aa].p_ptr[2].y + list_of_shapes[aa].p_ptr[0].y)/2.0; //check for collisions for (int j = 0; j < 25; j++) { //Don't check for collisions with itself or nonexistant objects if (j == aa || list_of_shapes[j].p_ptr == NULL) continue; //Distance between two shapes double distance = detect_collision(list_of_shapes[aa], list_of_shapes[j]); //printf("%f distance between shape %d and %d\n", distance, aa, j); //DEBUG //Only go in if statement if current object is still in motion if (distance < 0.03 && list_of_shapes[aa].p_ptr[0].force != 0.0) { //DEBUG //printf("%f, %f\n", abs(list_of_shapes[aa].old_vel2 - list_of_shapes[aa].p_ptr[0].velocity), list_of_shapes[aa].difference); //IF object keeps colliding with a surface with the same velocity than it should stop moving //Animation becomes more realistic if ( abs(list_of_shapes[aa].old_vel2 - list_of_shapes[aa].p_ptr[0].velocity) == list_of_shapes[aa].difference && list_of_shapes[j].curr_y < list_of_shapes[aa].curr_y) { //printf("COllision!!\n"); //DEBUG for (int r = 0; r < 4; r++) { //stop shape from moving list_of_shapes[aa].p_ptr[r].velocity = 0.0; list_of_shapes[aa].p_ptr[r].force = 0.0; } } else //Slow down object due to collision { list_of_shapes[aa].difference = abs(list_of_shapes[aa].old_vel2 - list_of_shapes[aa].p_ptr[0].velocity); for (int r = 0; r < 4; r++) { list_of_shapes[aa].p_ptr[r].velocity *= -.75; //Send object at top of collision upwards if (list_of_shapes[aa].curr_y > list_of_shapes[j].curr_y) { list_of_shapes[aa].p_ptr[r].y += ((0.03-distance)*.9); list_of_shapes[aa].curr_y += ((0.03-distance)*.9); } else //Send object at bottom of collision downwards { list_of_shapes[aa].p_ptr[r].y -= ((0.03-distance)*.9); list_of_shapes[aa].curr_y -= ((0.03-distance)*.9); } } } list_of_shapes[aa].old_vel2 = list_of_shapes[aa].p_ptr[0].velocity; } } double offset; for (int g = 0; g < 4; g++) { //Collision detection with the bottom if (list_of_shapes[aa].p_ptr[g].y < 0.0) { offset = abs((0.0 - list_of_shapes[aa].p_ptr[g].y)); //This stops shapes from bouncing on the ground when they should've stopped moving if (abs(list_of_shapes[aa].p_ptr[g].velocity) == list_of_shapes[aa].old_vel) { for (int r = 0; r < 4; r++) { //printf("STOPPED\n"); //DEBUG //stop shape from moving list_of_shapes[aa].p_ptr[r].velocity = 0.0; list_of_shapes[aa].p_ptr[r].force = 0.0; } break; } else { for (int r = 0; r < 4; r++) { //switch velocity sign and decreases by 75% due to collision with floor list_of_shapes[aa].p_ptr[r].velocity *= -.75; list_of_shapes[aa].p_ptr[r].y += offset; } break; } //printf("vel - %f\n", list_of_shapes[aa].p_ptr[g].velocity); //DEBUG list_of_shapes[aa].old_vel = list_of_shapes[aa].p_ptr[g].velocity; } } } else if (aa % 2 == 1) //Circles with PHYSICS { //Update particle values current = ANIMATION_SPEED/1000.0; // get current time change (convert milliseconds to seconds) //Update particles according to equations from lecture for (int g = 0; g < 12; g++) { accel = list_of_shapes[aa].p_ptr[g].force / list_of_shapes[aa].p_ptr[g].mass; // printf("%f\n", accel); //DEBUG vel = list_of_shapes[aa].p_ptr[g].velocity; y2 = list_of_shapes[aa].p_ptr[g].y; list_of_shapes[aa].p_ptr[g].velocity = vel + (accel * current); list_of_shapes[aa].p_ptr[g].y = y2 + (vel * current) + ( (accel*0.5) * (current*current)); } //Update y coordinate of object's center list_of_shapes[aa].curr_y = list_of_shapes[aa].p_ptr[0].y; //check for collisions for (int j = 0; j < 25; j++) { //Don't check for collisions with itself or nonexistant objects if (j == aa || list_of_shapes[j].p_ptr == NULL) continue; //Distance between two shapes double distance = detect_collision(list_of_shapes[aa], list_of_shapes[j]); //Only go in if statement if current object is still in motion if (distance < 0.03 && list_of_shapes[aa].p_ptr[0].force != 0.0) { //printf("vel - %f\n", list_of_shapes[aa].p_ptr[0].velocity); //DEBUG //IF object keeps colliding with a surface with the same velocity than it should stop moving //Animation becomes more realistic if ( abs(list_of_shapes[aa].old_vel2 - list_of_shapes[aa].p_ptr[0].velocity) == list_of_shapes[aa].difference && list_of_shapes[j].curr_y < list_of_shapes[aa].curr_y) { //printf("COllision!!\n"); //DEBUG for (int r = 0; r < 12; r++) { //stop shape from moving list_of_shapes[aa].p_ptr[r].velocity = 0.0; list_of_shapes[aa].p_ptr[r].force = 0.0; } } else //Slow down object due to collision { list_of_shapes[aa].difference = abs(list_of_shapes[aa].old_vel2 - list_of_shapes[aa].p_ptr[0].velocity); for (int r = 0; r < 12; r++) { list_of_shapes[aa].p_ptr[r].velocity *= -.75; //Send object at top of collision upwards if (list_of_shapes[aa].curr_y > list_of_shapes[j].curr_y) { list_of_shapes[aa].p_ptr[r].y += ((0.03-distance)*.9); list_of_shapes[aa].curr_y += ((0.03-distance)*.9); } else //Send object at bottom of collision downwards { list_of_shapes[aa].p_ptr[r].y -= ((0.03-distance)*.9); list_of_shapes[aa].curr_y -= ((0.03-distance)*.9); } } } list_of_shapes[aa].old_vel2 = list_of_shapes[aa].p_ptr[0].velocity; } } double offset; for (int g = 0; g < 12; g++) { //Collision detection with the bottom if (list_of_shapes[aa].p_ptr[g].y <= 0.0) { offset = abs((0.0 - list_of_shapes[aa].p_ptr[g].y)); //This stops shapes from bouncing on the ground when it should've stopped moving if (abs(list_of_shapes[aa].p_ptr[g].velocity) == list_of_shapes[aa].old_vel) { for (int r = 0; r < 12; r++) { //printf("STOPPED\n"); //DEBUG //stop shape from moving list_of_shapes[aa].p_ptr[r].velocity = 0.0; list_of_shapes[aa].p_ptr[r].force = 0.0; } break; } else { for (int r = 0; r < 12; r++) { //switch velocity sign and decrease by 75% due to collision with floor list_of_shapes[aa].p_ptr[r].velocity *= -.75; list_of_shapes[aa].p_ptr[r].y += offset; } break; } list_of_shapes[aa].old_vel = list_of_shapes[aa].p_ptr[g].velocity; } } } } }// END of for loop // clear the buffer glClear(GL_COLOR_BUFFER_BIT) ; //Animate shapes to drop down to botton of screen Tetris style for (int aa = 0; aa < 25; aa++) { //If shape doesn't exist then don't animate it if (list_of_shapes[aa].p_ptr == NULL) { break; } else { //animate rectangles if (aa % 2 == 0) { glColor3f(0,0,1) ; // Blue rectangles //Draw changes made by simulated gravity glBegin(GL_QUADS); for(int g= 0; g < 4; g++) { glVertex2d(list_of_shapes[aa].p_ptr[g].x, list_of_shapes[aa].p_ptr[g].y); } glEnd(); } else { glColor3f(1,0,0) ; //Red circles //Draw changes made by simulated gravity glBegin(GL_TRIANGLE_FAN); for(int x= 0; x < 12; x++) { glVertex2d(list_of_shapes[aa].p_ptr[x].x, list_of_shapes[aa].p_ptr[x].y); } glEnd(); } } } // buffer is ready; show me the money! glutSwapBuffers(); glutTimerFunc(ANIMATION_SPEED, my_TimeOut, 0);// schedule next timer event, according to ANIMATION_SPEED }