void racing_loop( scalar_t time_step ) { int width, height; player_data_t *plyr = get_player_data( local_player() ); bool_t joy_paddling = False; bool_t joy_braking = False; bool_t joy_charging = False; bool_t airborne; vector_t dir; scalar_t speed; scalar_t terrain_weights[NumTerrains]; int new_terrain = 0; int slide_volume; dir = plyr->vel; speed = normalize_vector(&dir); airborne = plyr->airborne; width = getparam_x_resolution(); height = getparam_y_resolution(); check_gl_error(); new_frame_for_fps_calc(); update_audio(); clear_rendering_context(); setup_fog(); /* Update braking */ plyr->control.is_braking = (bool_t) ( braking || joy_braking ); if ( airborne ) { new_terrain = (1<<NumTerrains); /* * Tricks */ if ( trick_modifier) { if (left_turn) { plyr->control.barrel_roll_left = True; } if (right_turn) { plyr->control.barrel_roll_right = True; } if (paddling) { plyr->control.front_flip = True; } if (plyr->control.is_braking) { plyr->control.back_flip = True; } //Par défaut ca fait un front flip if(!plyr->control.front_flip && !plyr->control.back_flip && !plyr->control.barrel_roll_right && !plyr->control.barrel_roll_left ) { plyr->control.back_flip = True; } #ifdef __APPLE__ TRDebugLog("tricks : %d",plyr->tricks); #endif } } else { get_surface_type(plyr->pos.x, plyr->pos.z, terrain_weights); if (terrain_weights[Snow] > 0) { new_terrain |= (1<<Snow); } if (terrain_weights[Rock] > 0) { new_terrain |= (1<<Rock); } if (terrain_weights[Ice] > 0) { new_terrain |= (1<<Ice); } } /* * Jumping */ calc_jump_amt( time_step ); if ( ( charging || joy_charging ) && !plyr->control.jump_charging && !plyr->control.jumping ) { plyr->control.jump_charging = True; charge_start_time = g_game.time; } if ( ( !charging && !joy_charging ) && plyr->control.jump_charging ) { plyr->control.jump_charging = False; plyr->control.begin_jump = True; } /* * Turning */ scalar_t iPhone_turn_fact=accelerometerTurnFact(); iPhone_turn_fact=accelerometerTurnFact(); /*left_turn and right_turn are informations useful for tricks*/ if (iPhone_turn_fact>TURN_FACTOR_LIMIT) { left_turn=false; right_turn=true; } else if (iPhone_turn_fact<-TURN_FACTOR_LIMIT) { left_turn=true; right_turn=false; } else left_turn = right_turn = false; plyr->control.turn_fact = iPhone_turn_fact; plyr->control.turn_animation = iPhone_turn_fact; /* * Paddling */ if ( ( paddling || joy_paddling ) && plyr->control.is_paddling == False ) { plyr->control.is_paddling = True; plyr->control.paddle_time = g_game.time; } /* * Play flying sound (__APPLE__ : and add Flying time to plyr->control.fly_total_time) */ if (new_terrain & (1<<NumTerrains)) { set_sound_volume("flying_sound", min(128, speed*2)); if (!(last_terrain & (1<<NumTerrains))) { play_sound( "flying_sound", -1 ); plyr->control.is_flying=true; plyr->control.fly_start_time = g_game.time; } } else { if (last_terrain & (1<<NumTerrains)) { plyr->control.is_flying=false; plyr->control.fly_end_time = g_game.time; if (plyr->control.fly_end_time-plyr->control.fly_start_time>FLYING_TIME_LIMIT) { plyr->control.fly_total_time += plyr->control.fly_end_time-plyr->control.fly_start_time; } halt_sound( "flying_sound" ); } } /* * Play sliding sound */ slide_volume = min( (((pow(plyr->control.turn_fact, 2)*128)) + (plyr->control.is_braking?128:0) + (plyr->control.jumping?128:0) + 20) * (speed/10), 128 ); if (new_terrain & (1<<Snow)) { set_sound_volume("snow_sound", slide_volume * terrain_weights[Snow]); if (!(last_terrain & (1<<Snow))) { play_sound( "snow_sound", -1 ); } } else { if (last_terrain & (1<<Snow)) { halt_sound( "snow_sound" ); } } if (new_terrain & (1<<Rock)) { //set_sound_volume("rock_sound", 128*pow((speed/2), 2) * terrain_weights[Rock]); int rockvol = slide_volume * 10 * terrain_weights[Rock]; if (rockvol > 400) rockvol = 400; set_sound_volume("rock_sound", rockvol); if (!(last_terrain & (1<<Rock))) { play_sound( "rock_sound", -1 ); } } else { if (last_terrain & (1<<Rock)) { halt_sound( "rock_sound" ); } } if (new_terrain & (1<<Ice)) { set_sound_volume("ice_sound", slide_volume * terrain_weights[Ice]); if (!(last_terrain & (1<<Ice))) { play_sound( "ice_sound", -1 ); } } else { if (last_terrain & (1<<Ice)) { halt_sound( "ice_sound" ); } } last_terrain = new_terrain; /* * gs */ bool roll = plyr->control.barrel_roll_left || plyr->control.barrel_roll_right; bool flip = plyr->control.front_flip || plyr->control.back_flip; if(roll && plyr->control.barrel_roll_factor == 0) { if(flip) { if(plyr->control.barrel_roll_left) add_new_bonus("Hyper heavy Jump", get_score_for_trick(HYPER_HEAVY_JUMP)); else add_new_bonus("Ray star hybrid Jump", get_score_for_trick(RAY_STAR_HYBRID_JUMP)); } else { if(plyr->control.barrel_roll_left) add_new_bonus("Roll Left", get_score_for_trick(ROLL_LEFT)); else add_new_bonus("Roll Right", get_score_for_trick(ROLL_RIGHT)); } } if(flip && plyr->control.flip_factor == 0) { if(roll) { if(plyr->control.back_flip) add_new_bonus("Saturn ice Fever", get_score_for_trick(SATURN_ICE_FEVER)); else add_new_bonus("Wild pinguin Show", get_score_for_trick(WILD_PINGUIN_SHOW)); } else { if(plyr->control.back_flip) add_new_bonus("Back Flip", get_score_for_trick(BACK_FLIP)); else add_new_bonus("Barlow's Wheel", get_score_for_trick(BARLOWS_WHEEL)); } } if (roll) { plyr->tricks+=1; plyr->control.barrel_roll_factor += ( plyr->control.barrel_roll_left ? -1 : 1 ) * 0.05 * time_step / 0.05; if ( (plyr->control.barrel_roll_factor > 1) || (plyr->control.barrel_roll_factor < -1) ) { plyr->control.barrel_roll_factor = 0; plyr->control.barrel_roll_left = plyr->control.barrel_roll_right = False; } } if (flip) { plyr->tricks+=1; plyr->control.flip_factor += ( plyr->control.back_flip ? -1 : 1 ) * 0.05 * time_step / 0.05; if ( (plyr->control.flip_factor > 1) || (plyr->control.flip_factor < -1) ) { plyr->control.flip_factor = 0; plyr->control.front_flip = plyr->control.back_flip = False; } } update_player_pos( plyr, time_step ); /* * Track Marks */ add_track_mark( plyr ); update_view( plyr, time_step ); setup_view_frustum( plyr, NEAR_CLIP_DIST, getparam_forward_clip_distance() ); draw_sky(plyr->view.pos); draw_fog_plane(); set_course_clipping( True ); set_course_eye_point( plyr->view.pos ); setup_course_lighting(); render_course(); draw_trees(); if ( getparam_draw_particles() ) { update_particles( time_step ); draw_particles( plyr ); } draw_tux(); draw_tux_shadow(); draw_hud( plyr ); draw_hud_training(plyr); reshape( width, height ); winsys_swap_buffers(); g_game.time += time_step; }
void racing_loop( scalar_t time_step ) { int width, height; player_data_t *plyr = get_player_data( local_player() ); bool_t joy_left_turn = False; bool_t joy_right_turn = False; scalar_t joy_turn_fact = 0.0; bool_t joy_paddling = False; bool_t joy_braking = False; bool_t joy_tricks = False; bool_t joy_charging = False; bool_t airborne; vector_t dir; scalar_t speed; scalar_t terrain_weights[NumTerrains]; int new_terrain = 0; int slide_volume; dir = plyr->vel; speed = normalize_vector(&dir); airborne = (bool_t) ( plyr->pos.y > ( find_y_coord(plyr->pos.x, plyr->pos.z) + JUMP_MAX_START_HEIGHT ) ); width = getparam_x_resolution(); height = getparam_y_resolution(); check_gl_error(); new_frame_for_fps_calc(); update_audio(); clear_rendering_context(); setup_fog(); /* * Joystick */ if ( is_joystick_active() ) { scalar_t joy_x; scalar_t joy_y; update_joystick(); joy_x = get_joystick_x_axis(); joy_y = get_joystick_y_axis(); if ( joy_x > 0.1 ) { joy_right_turn = True; joy_turn_fact = joy_x; } else if ( joy_x < -0.1 ) { joy_left_turn = True; joy_turn_fact = joy_x; } if ( getparam_joystick_brake_button() >= 0 ) { joy_braking = is_joystick_button_down( getparam_joystick_brake_button() ); } if ( !joy_braking ) { joy_braking = (bool_t) ( joy_y > 0.5 ); } if ( getparam_joystick_paddle_button() >= 0 ) { joy_paddling = is_joystick_button_down( getparam_joystick_paddle_button() ); } if ( !joy_paddling ) { joy_paddling = (bool_t) ( joy_y < -0.5 ); } if ( getparam_joystick_jump_button() >= 0 ) { joy_charging = is_joystick_button_down( getparam_joystick_jump_button() ); } if ( getparam_joystick_trick_button() >= 0 ) { joy_tricks = is_joystick_button_down( getparam_joystick_trick_button() ); } } /* Update braking */ plyr->control.is_braking = (bool_t) ( braking || joy_braking ); if ( airborne ) { new_terrain = (1<<NumTerrains); /* * Tricks */ if ( trick_modifier || joy_tricks ) { if ( left_turn || joy_left_turn ) { plyr->control.barrel_roll_left = True; } if ( right_turn || joy_right_turn ) { plyr->control.barrel_roll_right = True; } if ( paddling || joy_paddling ) { plyr->control.front_flip = True; } if ( plyr->control.is_braking ) { plyr->control.back_flip = True; } } } else { get_surface_type(plyr->pos.x, plyr->pos.z, terrain_weights); if (terrain_weights[Snow] > 0) { new_terrain |= (1<<Snow); } if (terrain_weights[Rock] > 0) { new_terrain |= (1<<Rock); } if (terrain_weights[Ice] > 0) { new_terrain |= (1<<Ice); } } /* * Jumping */ calc_jump_amt( time_step ); if ( ( charging || joy_charging ) && !plyr->control.jump_charging && !plyr->control.jumping ) { plyr->control.jump_charging = True; charge_start_time = g_game.time; } if ( ( !charging && !joy_charging ) && plyr->control.jump_charging ) { plyr->control.jump_charging = False; plyr->control.begin_jump = True; } /* * Turning */ if ( ( left_turn || joy_left_turn ) ^ (right_turn || joy_right_turn ) ) { bool_t turning_left = (bool_t) ( left_turn || joy_left_turn ); if ( joy_left_turn || joy_right_turn ) { plyr->control.turn_fact = joy_turn_fact; } else { plyr->control.turn_fact = (turning_left?-1:1); } plyr->control.turn_animation += (turning_left?-1:1) * 0.15 * time_step / 0.05; plyr->control.turn_animation = min(1.0, max(-1.0, plyr->control.turn_animation)); } else { plyr->control.turn_fact = 0; /* Decay turn animation */ if ( time_step < ROLL_DECAY_TIME_CONSTANT ) { plyr->control.turn_animation *= 1.0 - time_step/ROLL_DECAY_TIME_CONSTANT; } else { plyr->control.turn_animation = 0.0; } } /* * Paddling */ if ( ( paddling || joy_paddling ) && plyr->control.is_paddling == False ) { plyr->control.is_paddling = True; plyr->control.paddle_time = g_game.time; } /* * Play flying sound */ if (new_terrain & (1<<NumTerrains)) { set_sound_volume("flying_sound", min(128, speed*2)); if (!(last_terrain & (1<<NumTerrains))) { play_sound( "flying_sound", -1 ); } } else { if (last_terrain & (1<<NumTerrains)) { halt_sound( "flying_sound" ); } } /* * Play sliding sound */ slide_volume = min( (((pow(plyr->control.turn_fact, 2)*128)) + (plyr->control.is_braking?128:0) + (plyr->control.jumping?128:0) + 20) * (speed/10), 128 ); if (new_terrain & (1<<Snow)) { set_sound_volume("snow_sound", slide_volume * terrain_weights[Snow]); if (!(last_terrain & (1<<Snow))) { play_sound( "snow_sound", -1 ); } } else { if (last_terrain & (1<<Snow)) { halt_sound( "snow_sound" ); } } if (new_terrain & (1<<Rock)) { set_sound_volume("rock_sound", 128*pow((speed/2), 2) * terrain_weights[Rock]); if (!(last_terrain & (1<<Rock))) { play_sound( "rock_sound", -1 ); } } else { if (last_terrain & (1<<Rock)) { halt_sound( "rock_sound" ); } } if (new_terrain & (1<<Ice)) { set_sound_volume("ice_sound", slide_volume * terrain_weights[Ice]); if (!(last_terrain & (1<<Ice))) { play_sound( "ice_sound", -1 ); } } else { if (last_terrain & (1<<Ice)) { halt_sound( "ice_sound" ); } } last_terrain = new_terrain; /* * Tricks */ if ( plyr->control.barrel_roll_left || plyr->control.barrel_roll_right ) { plyr->control.barrel_roll_factor += ( plyr->control.barrel_roll_left ? -1 : 1 ) * 0.15 * time_step / 0.05; if ( (plyr->control.barrel_roll_factor > 1) || (plyr->control.barrel_roll_factor < -1) ) { plyr->control.barrel_roll_factor = 0; plyr->control.barrel_roll_left = plyr->control.barrel_roll_right = False; } } if ( plyr->control.front_flip || plyr->control.back_flip ) { plyr->control.flip_factor += ( plyr->control.back_flip ? -1 : 1 ) * 0.15 * time_step / 0.05; if ( (plyr->control.flip_factor > 1) || (plyr->control.flip_factor < -1) ) { plyr->control.flip_factor = 0; plyr->control.front_flip = plyr->control.back_flip = False; } } update_player_pos( plyr, time_step ); /* * Track Marks */ add_track_mark( plyr ); update_view( plyr, time_step ); setup_view_frustum( plyr, NEAR_CLIP_DIST, getparam_forward_clip_distance() ); draw_sky(plyr->view.pos); draw_fog_plane(); set_course_clipping( True ); set_course_eye_point( plyr->view.pos ); setup_course_lighting(); render_course(); draw_trees(); if ( getparam_draw_particles() ) { update_particles( time_step ); draw_particles( plyr ); } draw_tux(); draw_tux_shadow(); draw_hud( plyr ); reshape( width, height ); winsys_swap_buffers(); g_game.time += time_step; }
void game_over_loop( scalar_t time_step ) { player_data_t *plyr = get_player_data( local_player() ); int width, height; width = getparam_x_resolution(); height = getparam_y_resolution(); check_gl_error(); /* Check joystick */ if ( is_joystick_active() ) { update_joystick(); if ( is_joystick_continue_button_down() ) { set_game_mode( NEXT_MODE ); winsys_post_redisplay(); return; } } new_frame_for_fps_calc(); update_audio(); clear_rendering_context(); setup_fog(); update_player_pos( plyr, 0 ); update_view( plyr, 0 ); setup_view_frustum( plyr, NEAR_CLIP_DIST, getparam_forward_clip_distance() ); draw_sky(plyr->view.pos); draw_fog_plane(); set_course_clipping( True ); set_course_eye_point( plyr->view.pos ); setup_course_lighting(); render_course(); draw_trees(); if ( getparam_draw_particles() ) { draw_particles( plyr ); } draw_tux(); draw_tux_shadow(); set_gl_options( GUI ); ui_setup_display(); draw_game_over_text(); #ifndef __APPLE__ draw_hud( plyr ); #endif draw_hud_training(plyr); reshape( width, height ); winsys_swap_buffers(); }
void myinit() { glClearColor(0.0, 0.0, 0.0, 1.0); /*set the background color BLACK */ /*Clear the Depth & Color Buffers */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); /*---Create a light source----*/ glEnable(GL_LIGHTING); setup_light(); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient); glEnable(GL_NORMALIZE); /*Enable mornalization */ /*---Create quadratic objects---*/ if (sphere == NULL) { sphere = gluNewQuadric(); gluQuadricDrawStyle(sphere, GLU_FILL); gluQuadricNormals(sphere, GLU_SMOOTH); } if (cylind == NULL) { cylind = gluNewQuadric(); gluQuadricDrawStyle(cylind, GLU_FILL); gluQuadricNormals(cylind, GLU_SMOOTH); } if (disk == NULL) { disk = gluNewQuadric(); gluQuadricDrawStyle(disk, GLU_FILL); gluQuadricNormals(disk, GLU_SMOOTH); } /*-----Create Texture -----*/ make_check(); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glGenTextures(4, textName); glBindTexture(GL_TEXTURE_2D, textName[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TSIZE, TSIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkboard); /*-----Create another texture ----*/ Create_Texture_Star(); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glBindTexture(GL_TEXTURE_2D, textName[1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TSIZE, TSIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, star); brick_pattern(); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glBindTexture(GL_TEXTURE_2D, textName[2]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TSIZE, TSIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, brick); Create_Texture_Waterwave(); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glBindTexture(GL_TEXTURE_2D, textName[3]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TSIZE, TSIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, waterwave); /*----Set up fog conditions ---*/ glEnable(GL_FOG); /*enable fog fade */ setup_fog(); /*---- Compute cos(5.0) and sin(5.0) ----*/ cv = cos(5.0*PI / 180.0); sv = sin(5.0*PI / 180.0); /*---- Copy eye position ---*/ eye[0] = Eye[0]; eye[1] = Eye[1]; eye[2] = Eye[2]; }
void my_quit(unsigned char key, int ix, int iy) { double m, n; int i; float x[3], y[3], z[3]; if (key == 'q') { style = 0; self_ang = -90.0; glob_ang = 0.0; up_ang = 0.0; bld_ang = 10.0; float positions[3] = { 0.0, 0.0, 0.0 }; float temps[3] = { 0.0,0.0,0.0 }; double Eyes[3] = { 0.0, 0.0, 30.0 }, Focuss[3] = { 0.0, 0.0, 0.0 }, Vups[3] = { 0.0, 1.0, 0.0 }; float us[3][3] = { { 1.0,0.0,0.0 },{ 0.0,1.0,0.0 },{ 0.0,0.0,1.0 } }; float Fog_color[] = { 0.15, 0.20, 0.20, 0.50 }; for (int i = 0; i < 3; i++) { position[i] = positions[i]; temp[i] = temps[i]; Eye[i] = Eyes[i]; Focus[i] = Focuss[i]; Vup[i] = Vups[i]; fog_color[i] = Fog_color[i]; for (int j = 0; j < 3; j++) u[i][j] = us[i][j]; } setup_fog(); zoom = 1.0; eyeDx = 0.0; eyeDy = 0.0; eyeDz = 0.0; eyeAngx = 0.0; eyeAngy = 0.0; eyeAngz = 0.0; eye[0] = Eye[0]; eye[1] = Eye[1]; eye[2] = Eye[2]; } if (key == 'Q') exit(0); if (key == '0') { trun0++; if (trun0 % 2 != 0) glEnable(GL_LIGHT0); else glDisable(GL_LIGHT0); } if (key == '1') { trun1++; if (trun1 % 2 != 0) glEnable(GL_LIGHT1); else glDisable(GL_LIGHT1); } if (key == '3') { trun23++; if (trun23 % 2 != 0) { glEnable(GL_LIGHT2); glEnable(GL_LIGHT3); } else { glDisable(GL_LIGHT2); glDisable(GL_LIGHT3); } } if (key == '5') { trun45++; if (trun45 % 2 != 0) { glEnable(GL_LIGHT4); glEnable(GL_LIGHT5); } else { glDisable(GL_LIGHT4); glDisable(GL_LIGHT5); } } if (key == '9') position[1] += 1.0; if (key == '8') { position[0] += Step*cos(self_ang*PI / 180.0); position[2] -= Step*sin(self_ang*PI / 180.0); if (50 >= (position[0] + 5) && (position[0] + 5) >= 10) { if (40 >= (position[2] + 8) && (position[2] + 8) >= 17.5) { up_ang = 40; m = position[2] - 20; position[1] = m * 2 / 3; } else { up_ang = 0.0; position[1] = 0.0; } } else if (50 >= (position[0] + 5) && (position[0] + 5) >= 10) { if (40 >= (position[2] - 8) && (position[2] - 8) >= 17.5) { up_ang = 40; m = position[2] - 20; position[1] = m * 2 / 3; } else { up_ang = 0.0; position[1] = 0.0; } } else if (50 >= (position[0] - 5) && (position[0] - 5) >= 10) { if (40 >= (position[2] - 8) && (position[2] - 8) >= 17.5) { up_ang = 40; m = position[2] - 20; position[1] = m * 2 / 3; } else { up_ang = 0.0; position[1] = 0.0; } } else if (50 >= (position[0] - 5) && (position[0] - 5) >= 10) { if (40 >= (position[2] + 8) && (position[2] + 8) >= 17.5) { up_ang = 40; m = position[2] - 20; position[1] = m * 2 / 3; } else { up_ang = 0.0; position[1] = 0.0; } } else { up_ang = 0.0; position[1] = 0.0; } if (-20.0 >= (position[0] + 5) && (position[0] + 5) >= -35.0) { if (-20 >= (position[2] + 8) && (position[2] + 8) >= -35) { position[0] = temp[0]; position[2] = temp[2]; } else { temp[0] = position[0]; temp[2] = position[2]; } } else if (-20.0 >= (position[0] + 5) && (position[0] + 5) >= -35.0) { if (-20 >= (position[2] - 8) && (position[2] - 8) >= -35) { position[0] = temp[0]; position[2] = temp[2]; } else { temp[0] = position[0]; temp[2] = position[2]; } } else if (-20.0 >= (position[0] - 5) && (position[0] - 5) >= -35.0) { if (-20 >= (position[2] + 8) && (position[2] + 8) >= -35) { position[0] = temp[0]; position[2] = temp[2]; } else { temp[0] = position[0]; temp[2] = position[2]; } } else if (-20.0 >= (position[0] - 5) && (position[0] - 5) >= -35.0) { if (-20 >= (position[2] - 8) && (position[2] - 8) >= -35) { position[0] = temp[0]; position[2] = temp[2]; } else { temp[0] = position[0]; temp[2] = position[2]; } } else { temp[0] = position[0]; temp[2] = position[2]; } } else if (key == '2') { position[0] -= Step*cos(self_ang*PI / 180.0); position[2] += Step*sin(self_ang*PI / 180.0); if (50 >= (position[0] + 5) && (position[0] + 5) >= 10) { if (40 >= (position[2] + 8) && (position[2] + 8) >= 17.5) { up_ang = 40; m = position[2] - 20; position[1] = m * 2 / 3; } else { up_ang = 0.0; position[1] = 0.0; } } else if (50 >= (position[0] + 5) && (position[0] + 5) >= 10) { if (40 >= (position[2] - 8) && (position[2] - 8) >= 17.5) { up_ang = 40; m = position[2] - 20; position[1] = m * 2 / 3; } else { up_ang = 0.0; position[1] = 0.0; } } else if (50 >= (position[0] - 5) && (position[0] - 5) >= 10) { if (40 >= (position[2] - 8) && (position[2] - 8) >= 17.5) { up_ang = 40; m = position[2] - 20; position[1] = m * 2 / 3; } else { up_ang = 0.0; position[1] = 0.0; } } else if (50 >= (position[0] - 5) && (position[0] - 5) >= 10) { if (40 >= (position[2] + 8) && (position[2] + 8) >= 17.5) { up_ang = 40; m = position[2] - 20; position[1] = m * 2 / 3; } else { up_ang = 0.0; position[1] = 0.0; } } else { up_ang = 0.0; position[1] = 0.0; } if (-20.0 >= (position[0] + 5) && (position[0] + 5) >= -35.0) { if (-20 >= (position[2] + 8) && (position[2] + 8) >= -35) { position[0] = temp[0]; position[2] = temp[2]; } else { temp[0] = position[0]; temp[2] = position[2]; } } else if (-20.0 >= (position[0] + 5) && (position[0] + 5) >= -35.0) { if (-20 >= (position[2] - 8) && (position[2] - 8) >= -35) { position[0] = temp[0]; position[2] = temp[2]; } else { temp[0] = position[0]; temp[2] = position[2]; } } else if (-20.0 >= (position[0] - 5) && (position[0] - 5) >= -35.0) { if (-20 >= (position[2] + 8) && (position[2] + 8) >= -35) { position[0] = temp[0]; position[2] = temp[2]; } else { temp[0] = position[0]; temp[2] = position[2]; } } else if (-20.0 >= (position[0] - 5) && (position[0] - 5) >= -35.0) { if (-20 >= (position[2] - 8) && (position[2] - 8) >= -35) { position[0] = temp[0]; position[2] = temp[2]; } else { temp[0] = position[0]; temp[2] = position[2]; } } else { temp[0] = position[0]; temp[2] = position[2]; } } else if (key == '4') { self_ang += 10.0; } else if (key == '6') { self_ang -= 10.0; } /*------transform the EYE coordinate system ------*/ else if (key == ')') { style = 0; } else if (key == '!') { style = 1; } else if (key == '@') { style = 2; } else if (key == '#') { style = 3; } else if (key == '$') { style = 4; } else if (key == '-') { zoom += 0.1; } else if (key == '+') { zoom -= 0.1; } else if (key == 'u') { eyeDy += 0.5; /* move up */ for (i = 0; i<3; i++) eye[i] -= 0.5*u[1][i]; } else if (key == 'd') { eyeDy += -0.5; /* move down */ for (i = 0; i<3; i++) eye[i] += 0.5*u[1][i]; } else if (key == 'w') { eyeDx += -0.5; /* move left */ for (i = 0; i<3; i++) eye[i] += 0.5*u[0][i]; } else if (key == 'e') { eyeDx += 0.5; /* move right */ for (i = 0; i<3; i++) eye[i] -= 0.5*u[0][i]; } else if (key == 'n') { eyeDz += 0.5; /* zoom in */ for (i = 0; i<3; i++) eye[i] -= 0.5*u[2][i]; } else if (key == 'f') { eyeDz += -0.5; /* zoom out */ for (i = 0; i<3; i++) eye[i] += 0.5*u[2][i]; } else if (key == 'p') { /* pitching */ eyeAngx += 5.0; if (eyeAngx > 360.0) eyeAngx -= 360.0; y[0] = u[1][0] * cv - u[2][0] * sv; y[1] = u[1][1] * cv - u[2][1] * sv; y[2] = u[1][2] * cv - u[2][2] * sv; z[0] = u[2][0] * cv + u[1][0] * sv; z[1] = u[2][1] * cv + u[1][1] * sv; z[2] = u[2][2] * cv + u[1][2] * sv; for (i = 0; i<3; i++) { u[1][i] = y[i]; u[2][i] = z[i]; } } else if (key == 'P') { eyeAngx += -5.0; if (eyeAngx<0.0) eyeAngx += 360.0; y[0] = u[1][0] * cv + u[2][0] * sv; y[1] = u[1][1] * cv + u[2][1] * sv; y[2] = u[1][2] * cv + u[2][2] * sv; z[0] = u[2][0] * cv - u[1][0] * sv; z[1] = u[2][1] * cv - u[1][1] * sv; z[2] = u[2][2] * cv - u[1][2] * sv; for (i = 0; i<3; i++) { u[1][i] = y[i]; u[2][i] = z[i]; } } else if (key == 'h') { /* heading */ eyeAngy += 5.0; if (eyeAngy>360.0) eyeAngy -= 360.0; for (i = 0; i<3; i++) { x[i] = cv*u[0][i] - sv*u[2][i]; z[i] = sv*u[0][i] + cv*u[2][i]; } for (i = 0; i<3; i++) { u[0][i] = x[i]; u[2][i] = z[i]; } } else if (key == 'H') { eyeAngy += -5.0; if (eyeAngy<0.0) eyeAngy += 360.0; for (i = 0; i<3; i++) { x[i] = cv*u[0][i] + sv*u[2][i]; z[i] = -sv*u[0][i] + cv*u[2][i]; } for (i = 0; i<3; i++) { u[0][i] = x[i]; u[2][i] = z[i]; } } else if (key == 'r') { /* rolling */ eyeAngz += 5.0; if (eyeAngz>360.0) eyeAngz -= 360.0; for (i = 0; i<3; i++) { x[i] = cv*u[0][i] - sv*u[1][i]; y[i] = sv*u[0][i] + cv*u[1][i]; } for (i = 0; i<3; i++) { u[0][i] = x[i]; u[1][i] = y[i]; } } else if (key == 'R') { eyeAngz += -5.0; if (eyeAngz<0.0) eyeAngz += 360.0; for (i = 0; i<3; i++) { x[i] = cv*u[0][i] + sv*u[1][i]; y[i] = -sv*u[0][i] + cv*u[1][i]; } for (i = 0; i<3; i++) { u[0][i] = x[i]; u[1][i] = y[i]; } } else if (key == 't') glDisable(GL_FOG); else if (key == 'T') glEnable(GL_FOG); else if (key == 'o') turn_fog = 0; else if (key == 'O') turn_fog = 1; else if (key == 'l') glFogi(GL_FOG_MODE, GL_LINEAR); else if (key == 'j') glFogi(GL_FOG_MODE, GL_EXP); else if (key == 'J') glFogi(GL_FOG_MODE, GL_EXP2); else if (key == 'i') { fog_opacity += 2; setup_fog(); } else if (key == 'I') { fog_opacity -= 2; setup_fog(); } display(); }
void idle_func() { ds += 0.001; if (ds>1.0) ds = ds - 1.0; if (turn_fog == 1) { fog_color[0] += 0.001; fog_color[1] += 0.001; fog_color[2] += 0.001; if (lit4_diffuse[0] > 0.7) fog_color[0] *= -1.0; else if (lit4_diffuse[0] < 0.1) fog_color[0] *= -1.0; if (lit4_diffuse[1] > 0.7) fog_color[1] *= -1.0; else if (lit4_diffuse[1] < 0.1) fog_color[1] *= -1.0; if (lit4_diffuse[2] > 0.7) fog_color[2] *= -1.0; else if (lit4_diffuse[2] < 0.1) fog_color[2] *= -1.0; } else { fog_color[0] = 0.15; fog_color[1] = 0.20; fog_color[2] = 0.20; } bld_ang += 5.0; lit4_diffuse[0] += lit_color4[0]; lit4_diffuse[1] += lit_color4[1]; lit4_diffuse[2] += lit_color4[2]; lit5_diffuse[0] += lit_color5[0]; lit5_diffuse[1] += lit_color5[1]; lit5_diffuse[2] += lit_color5[2]; if (bld_ang>360.0) { bld_ang -= 360.0; } if (lit4_diffuse[0]>1.0) lit_color4[0] *= -1.0; else if (lit4_diffuse[0]<0.1) lit_color4[0] *= -1.0; if (lit4_diffuse[1]>1.0) lit_color4[1] *= -1.0; else if (lit4_diffuse[1]<0.1) lit_color4[1] *= -1.0; if (lit4_diffuse[2]>1.0) lit_color4[2] *= -1.0; else if (lit4_diffuse[2]<0.1) lit_color4[2] *= -1.0; if (lit5_diffuse[0]>1.0) lit_color5[0] *= -1.0; else if (lit5_diffuse[0]<0.1) lit_color5[0] *= -1.0; if (lit5_diffuse[1]>1.0) lit_color5[1] *= -1.0; else if (lit5_diffuse[1]<0.1) lit_color5[1] *= -1.0; if (lit5_diffuse[2]>1.0) lit_color5[2] *= -1.0; else if (lit5_diffuse[2]<0.1) lit_color5[2] *= -1.0; setup_light(); setup_fog(); display(); /* show the scene again */ }