Back to index

extremetuxracer  0.5beta
mirror_course.cpp
Go to the documentation of this file.
00001 /* 
00002  * PPRacer 
00003  * Copyright (C) 2004-2005 Volker Stroebel <volker@planetpenguin.de>
00004  *
00005  * Copyright (C) 1999-2001 Jasmin F. Patry
00006  * 
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  * 
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020  */
00021 
00022 #include "course_load.h"
00023 #include "course_render.h"
00024 #include "keyframe.h"
00025 #include "phys_sim.h"
00026 #include "course_quad.h"
00027 #include "track_marks.h"
00028 #include "game_config.h"
00029 #include "course_mgr.h"
00030 
00031 static bool mirrored = false;
00032 
00033 void mirror_course() 
00034 {
00035     int x, y, i;
00036     int idx1, idx2;
00037     float tmp;
00038     int tmp_terrain;
00039     pp::Vec3d tmp_vec;
00040     float *elevation;
00041     pp::Vec3d *nmls;
00042     int *terrain;
00043     Tree *tree_locs;
00044     int num_trees;
00045     Item *item_locs;
00046     int num_items;
00047     pp::Vec2d start_pt;
00048     int nx, ny;
00049     float course_width, course_length;
00050 
00051     get_course_dimensions( &course_width, &course_length );
00052     get_course_divisions( &nx, &ny );
00053     elevation = get_course_elev_data();
00054     terrain = get_course_terrain_data();
00055     nmls = get_course_normals();
00056     tree_locs = get_tree_locs();
00057     item_locs = get_item_locs();
00058 
00059     for ( y=0; y<ny; y++ ) {
00060        for ( x=0; x<nx/2; x++ ) {
00061            tmp = ELEV(x,y);
00062            ELEV(x,y) = ELEV(nx-1-x, y);
00063            ELEV(nx-1-x,y) = tmp;
00064 
00065            /* first column of texture values not used */
00066             idx1 = (x+1) + nx*(y);
00067             idx2 = (nx-1-x) + nx*(y);
00068            tmp_terrain = terrain[idx1];
00069            terrain[idx1] = terrain[idx2];
00070            terrain[idx2] = tmp_terrain;
00071 
00072             idx1 = (x) + nx*(y);
00073             idx2 = (nx-1-x) + nx*(y);
00074            tmp_vec = nmls[idx1];
00075            nmls[idx1] = nmls[idx2];
00076            nmls[idx2] = tmp_vec;
00077            nmls[idx1].x *= -1;
00078            nmls[idx2].x *= -1;
00079        }
00080     }
00081 
00082     num_trees = get_num_trees();
00083     for ( i=0; i<num_trees; i++) {
00084        tree_locs[i].ray.pt.x = course_width - tree_locs[i].ray.pt.x; 
00085        tree_locs[i].ray.pt.y = 
00086            find_y_coord( tree_locs[i].ray.pt.x,
00087                        tree_locs[i].ray.pt.z );
00088     }
00089 
00090     num_items = get_num_items();
00091     for ( i=0; i<num_items; i++) {
00092        item_locs[i].ray.pt.x = course_width - item_locs[i].ray.pt.x; 
00093        item_locs[i].ray.pt.y = 
00094            find_y_coord( item_locs[i].ray.pt.x,
00095                        item_locs[i].ray.pt.z );
00096     }
00097 
00098     fill_gl_arrays();
00099 
00100     reset_course_quadtree();
00101     if ( nx > 0 && ny > 0 ) {
00102        print_debug( DEBUG_QUADTREE, "mirroring quadtree" );
00103        init_course_quadtree( elevation, nx, ny, course_width/(nx-1), 
00104                            -course_length/(ny-1),
00105                            players[0].view.pos, 
00106                            getparam_course_detail_level() );
00107     }
00108 
00109     start_pt = get_start_pt();
00110     start_pt.x = course_width - start_pt.x;
00111     set_start_pt( start_pt );
00112 }
00113 
00114 void mirror_key_frame()
00115 {
00116     int i;
00117     float course_width, course_length;
00118     int num_frames;
00119     key_frame_t *frames;
00120 
00121     get_key_frame_data( &frames, &num_frames );
00122 
00123     get_course_dimensions( &course_width, &course_length );
00124 
00125     for ( i=0; i<num_frames; i++ ) {
00126        frames[i].yaw = - frames[i].yaw;
00127        frames[i].pos.x = course_width - frames[i].pos.x;
00128     }
00129 }
00130 
00131 void set_course_mirroring( bool state )
00132 {
00133     if ( mirrored != state ) {
00134        mirror_key_frame();
00135        mirror_course();
00136        init_track_marks();
00137     }
00138     mirrored = state;
00139     
00140 }
00141 
00142 bool get_course_mirroring( )
00143 {
00144     return mirrored;
00145 }