1 /* 2 * GRacer 3 * 4 * Copyright (C) 1999 Takashi Matsuda <matsu@users.sourceforge.net> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of the 9 * License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 19 * USA 20 */ 21 22 #ifndef __GRACER_COURSE_H__ 23 #define __GRACER_COURSE_H__ 24 25 #include <stdio.h> 26 #include "gr_global.h" 27 #include "gr_vertex.h" 28 #include "gr_plane.h" 29 #include "gr_boundary.h" 30 #include "gr_memory.h" 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 #if 0 36 } 37 #endif 38 39 typedef enum { 40 GR_CLINE_REGION_C = 0, 41 GR_CLINE_REGION_A = 1, 42 GR_CLINE_REGION_B = 2, 43 44 GR_CLINE_PREV_A = GR_CLINE_REGION_A << 0, 45 GR_CLINE_PREV_B = GR_CLINE_REGION_B << 0, 46 GR_CLINE_PREV_C = GR_CLINE_REGION_C << 0, 47 48 GR_CLINE_CURRENT_A = GR_CLINE_REGION_A << 2, 49 GR_CLINE_CURRENT_B = GR_CLINE_REGION_B << 2, 50 GR_CLINE_CURRENT_C = GR_CLINE_REGION_C << 2, 51 52 GR_CLINE_A_TO_A = (GR_CLINE_PREV_A | GR_CLINE_CURRENT_A), 53 GR_CLINE_A_TO_B = (GR_CLINE_PREV_A | GR_CLINE_CURRENT_B), 54 GR_CLINE_A_TO_C = (GR_CLINE_PREV_A | GR_CLINE_CURRENT_C), 55 56 GR_CLINE_B_TO_A = (GR_CLINE_PREV_B | GR_CLINE_CURRENT_A), 57 GR_CLINE_B_TO_B = (GR_CLINE_PREV_B | GR_CLINE_CURRENT_B), 58 GR_CLINE_B_TO_C = (GR_CLINE_PREV_B | GR_CLINE_CURRENT_C), 59 60 GR_CLINE_C_TO_A = (GR_CLINE_PREV_C | GR_CLINE_CURRENT_A), 61 GR_CLINE_C_TO_B = (GR_CLINE_PREV_C | GR_CLINE_CURRENT_B), 62 GR_CLINE_C_TO_C = (GR_CLINE_PREV_C | GR_CLINE_CURRENT_C), 63 64 GR_CLINE_CURRENT_MASK = (GR_CLINE_CURRENT_A | 65 GR_CLINE_CURRENT_B | 66 GR_CLINE_CURRENT_C), 67 68 GR_CLINE_PREV_MASK = (GR_CLINE_PREV_A | 69 GR_CLINE_PREV_B | 70 GR_CLINE_PREV_C), 71 72 GR_CLINE_MASK = (GR_CLINE_CURRENT_MASK | GR_CLINE_PREV_MASK), 73 } GrCLineType; 74 75 #define gr_cline_current_region(r) \ 76 (((r) & GR_CLINE_CURRENT_MASK) >> 2) 77 78 #define gr_cline_prev_region(r) \ 79 ((r) & GR_CLINE_PREV_MASK) 80 81 typedef struct GrCLineInfo { 82 GrCLineType res; 83 struct { 84 GrVertexd pos; 85 int cline; 86 } current, prev; 87 88 float cross_ratio; 89 } GrCLineInfo; 90 91 typedef struct GrCMaterial { 92 float friction; 93 float exp; 94 float mu; 95 int flag; 96 } GrCMaterial; 97 98 typedef struct GrCSurface { 99 GrPlane plane; 100 int p[3]; 101 GrVertex v[3]; 102 GrVertex rv[3]; 103 int flag; 104 int mat; 105 } GrCSurface; 106 107 typedef struct GrCSegment { 108 GrBoundary *boundary; 109 int num_verts; 110 GrVertex *verts; 111 int num_surfs; 112 GrCSurface *surfs; 113 int flag; 114 GrVertex max, min; 115 } GrCSegment; 116 117 typedef struct GrControlLine { 118 GrVertex region_a[4]; 119 GrVertex rot_a[4]; 120 GrVertex region_b[4]; 121 GrVertex rot_b[4]; 122 int flag; 123 int segment; 124 float xmax, xmin; 125 float ymax, ymin; 126 } GrControlLine; 127 128 typedef struct GrGrid { 129 float x, y, dir; 130 int segment; 131 int flag; 132 } GrGrid; 133 134 typedef struct GrCourse { 135 GrRef ref; 136 137 char *title; 138 char *desc; 139 char *model; 140 char *timestamp; 141 142 int num_grids; 143 GrGrid *grids; 144 145 int num_clines; 146 GrControlLine *clines; 147 148 int num_mats; 149 GrCMaterial *mats; 150 151 int num_segs; 152 GrCSegment **segs; 153 } GrCourse; 154 155 typedef int (*GrCSurfaceCallback) (GrCourse *course, 156 int seg_no, 157 int surf_no, 158 void *data); 159 typedef int (*GrCSurfaceXYCallback) (GrCourse *course, 160 int seg_no, 161 int surf_no, 162 float z, 163 void *data); 164 165 GrCourse* gr_course_new_from_file (FILE *file); 166 GrCourse* gr_course_new_from_data (char *data); 167 GrCSurface* gr_course_find_surface (GrCourse *course, 168 float x, float y, 169 int segment_cur, 170 int *segment_ret); 171 172 void gr_course_write_file (GrCourse *course, FILE *file); 173 174 int gr_course_check_control_line (GrCourse *course, 175 GrCLineInfo *cinfo); 176 177 void gr_course_foreach_surface (GrCourse *course, 178 GrVertex *center, 179 float r, 180 GrCSurfaceCallback callback, 181 void *data); 182 183 void gr_course_foreach_surface_xy (GrCourse *course, 184 GrVertex *pos, 185 GrCSurfaceXYCallback callback, 186 void *data); 187 188 int gr_course_surface_check_inner (GrCSurface *surf, 189 GrVertex *p); 190 191 #ifdef __cplusplus 192 } 193 #endif 194 195 #endif /* __GRACER_COURSE_H__ */ 196