File: mirror_course.cpp

package info (click to toggle)
ppracer 0.3.1-11
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 9,916 kB
  • ctags: 3,049
  • sloc: cpp: 24,190; sh: 3,544; tcl: 2,450; makefile: 612; lisp: 87
file content (145 lines) | stat: -rw-r--r-- 3,770 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* 
 * PPRacer 
 * Copyright (C) 2004-2005 Volker Stroebel <volker@planetpenguin.de>
 *
 * Copyright (C) 1999-2001 Jasmin F. Patry
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#include "course_load.h"
#include "course_render.h"
#include "keyframe.h"
#include "phys_sim.h"
#include "course_quad.h"
#include "track_marks.h"
#include "game_config.h"
#include "course_mgr.h"

static bool mirrored = false;

void mirror_course() 
{
    int x, y, i;
    int idx1, idx2;
    float tmp;
    int tmp_terrain;
    pp::Vec3d tmp_vec;
    float *elevation;
    pp::Vec3d *nmls;
    int *terrain;
    Tree *tree_locs;
    int num_trees;
    Item *item_locs;
    int num_items;
    pp::Vec2d start_pt;
    int nx, ny;
    float course_width, course_length;

    get_course_dimensions( &course_width, &course_length );
    get_course_divisions( &nx, &ny );
    elevation = get_course_elev_data();
    terrain = get_course_terrain_data();
    nmls = get_course_normals();
    tree_locs = get_tree_locs();
    item_locs = get_item_locs();

    for ( y=0; y<ny; y++ ) {
	for ( x=0; x<nx/2; x++ ) {
	    tmp = ELEV(x,y);
	    ELEV(x,y) = ELEV(nx-1-x, y);
	    ELEV(nx-1-x,y) = tmp;

	    /* first column of texture values not used */
            idx1 = (x+1) + nx*(y);
            idx2 = (nx-1-x) + nx*(y);
	    tmp_terrain = terrain[idx1];
	    terrain[idx1] = terrain[idx2];
	    terrain[idx2] = tmp_terrain;

            idx1 = (x) + nx*(y);
            idx2 = (nx-1-x) + nx*(y);
	    tmp_vec = nmls[idx1];
	    nmls[idx1] = nmls[idx2];
	    nmls[idx2] = tmp_vec;
	    nmls[idx1].x *= -1;
	    nmls[idx2].x *= -1;
	}
    }

    num_trees = get_num_trees();
    for ( i=0; i<num_trees; i++) {
	tree_locs[i].ray.pt.x = course_width - tree_locs[i].ray.pt.x; 
	tree_locs[i].ray.pt.y = 
	    find_y_coord( tree_locs[i].ray.pt.x,
			  tree_locs[i].ray.pt.z );
    }

    num_items = get_num_items();
    for ( i=0; i<num_items; i++) {
	item_locs[i].ray.pt.x = course_width - item_locs[i].ray.pt.x; 
	item_locs[i].ray.pt.y = 
	    find_y_coord( item_locs[i].ray.pt.x,
			  item_locs[i].ray.pt.z );
    }

    fill_gl_arrays();

    reset_course_quadtree();
    if ( nx > 0 && ny > 0 ) {
	print_debug( DEBUG_QUADTREE, "mirroring quadtree" );
	init_course_quadtree( elevation, nx, ny, course_width/(nx-1), 
			      -course_length/(ny-1),
			      players[0].view.pos, 
			      getparam_course_detail_level() );
    }

    start_pt = get_start_pt();
    start_pt.x = course_width - start_pt.x;
    set_start_pt( start_pt );
}

void mirror_key_frame()
{
    int i;
    float course_width, course_length;
    int num_frames;
    key_frame_t *frames;

    get_key_frame_data( &frames, &num_frames );

    get_course_dimensions( &course_width, &course_length );

    for ( i=0; i<num_frames; i++ ) {
	frames[i].yaw = - frames[i].yaw;
	frames[i].pos.x = course_width - frames[i].pos.x;
    }
}

void set_course_mirroring( bool state )
{
    if ( mirrored != state ) {
	mirror_key_frame();
	mirror_course();
	init_track_marks();
    }
    mirrored = state;
    
}

bool get_course_mirroring( )
{
    return mirrored;
}