1 /* billmove.h 2 ** 3 ** includefile: physics of the billard system to calculate timestep 4 ** Copyright (C) 2001 Florian Berger 5 ** Email: harpin_floh@yahoo.de, florian.berger@jk.uni-linz.ac.at 6 ** 7 ** This program is free software; you can redistribute it and/or modify 8 ** it under the terms of the GNU General Public License Version 2 as 9 ** published by the Free Software Foundation; 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., 675 Mass Ave, Cambridge, MA 02139, USA. 19 ** 20 */ 21 22 #ifndef BILLMOVE_H 23 #define BILLMOVE_H 24 25 #include "vmath.h" 26 27 typedef VMvect myvec; 28 29 30 #define USE_ADV_BORDER 31 //#undef USE_ADV_BORDER 32 #define BILLMOVE_SINGLE_PRECISION 33 //#undef BILLMOVE_SINGLE_PRECISION 34 35 36 #ifndef USE_ADV_BORDER 37 38 #define BorderType OldBorderType 39 #define BALL_WALL_DIST(b,w) fabs(vec_mul(vec_diff(b.r,w.r),w.n)) 40 #define BALL_WALL_DIST_I(b,w) vec_mul(vec_diff(b.r,w.r),w.n) 41 42 #else 43 44 #define BorderType AdvBorderType 45 #define BALL_WALL_DIST_I(b,w) ball_advborder_dist(&(b),&(w)) 46 #define BALL_WALL_DIST(b,w) fabs(ball_advborder_dist(&(b),&(w))) 47 48 #endif 49 50 #define BALL_BALL_DIST(b1,b2) vec_abs(vec_diff(b1.r,b2.r)) 51 52 53 #ifdef BILLMOVE_SINGLE_PRECISION 54 typedef float BMfloat; /* floating point type for billard physics */ 55 #else 56 typedef double BMfloat; /* floating point type for billard physics */ 57 #endif 58 59 60 enum gameType { GAME_8BALL, GAME_9BALL, GAME_CARAMBOL, GAME_SNOOKER }; 61 62 63 typedef struct{ 64 BMfloat m; // mass [kg] 65 BMfloat I; // massentraegheitsmom [kg*m^2] 66 BMfloat d; // diameter [m] 67 myvec r; // position [m] 68 myvec v; // speed [m/s] 69 myvec w; // rotation speed and axe [rad./s] in table coords 70 myvec b[3]; // x,y,z base of ball in table coords 71 int nr; // 0=white, ... 72 int in_game; // ball in game 73 int in_fov; // ball in field of view - used internally 74 int in_hole; // ball still in game but already versenkt 75 myvec * path; // path of ball 76 int pathsize; // number of reserved path points 77 int pathcnt; // counter of path points 78 } BallType; 79 80 typedef struct{ 81 int nr; 82 enum gameType gametype; 83 BallType * ball; 84 } BallsType; 85 86 typedef struct{ 87 myvec r; // pos 88 myvec n; // normal vector 89 } OldBorderType; 90 91 typedef struct{ 92 int pnr; // 4=arc 3=triangle 2=line 1=point 93 myvec r1; // pos 94 myvec r2; // pos 95 myvec r3; // pos (tangent vec for arc) 96 myvec n; // normal vector 97 double mu; // friction const 98 double loss0; // const loss per hit (0th order in speed) 99 double loss_max; // max loss 100 double loss_wspeed; // width of higher order loss curve 101 } AdvBorderType; 102 103 typedef struct{ 104 myvec pos; // pos 105 myvec aim; // position to aim for ai-player 106 BMfloat r; // radius of hole (wall-coll free zone) 107 } HoleType; 108 109 typedef struct{ 110 int nr; 111 BorderType * border; 112 int holenr; 113 HoleType * hole; 114 } BordersType; 115 116 117 void BM_reset_move_info(void); 118 119 int BM_get_balls_out_half(void); 120 int BM_get_balls_out_full(void); 121 int BM_get_balls_out_total(void); // halves and full (no black or white) 122 int BM_get_balls_out_all(void); // all balls inclusive black and white 123 int BM_get_white_out(void); 124 int BM_get_ball_out(int nr); 125 int BM_get_nth_ball_out(int n); 126 int BM_get_min_ball_out(void); 127 int BM_get_1st_ball_hit(void); 128 int BM_get_non_strafraum_wall_hit_before_1st_ball( int (* in_strafraum)(VMvect) ); 129 int BM_get_nth_ball_hit(int n); 130 int BM_get_nth_ball_hit_by_ind(int ind, int n); 131 VMvect BM_get_1st_ball_hit_pos(void); 132 int BM_get_balls_hit(void); 133 int BM_get_balls_hit_last(); 134 int BM_get_walls_hit_last(); 135 double BM_get_balls_hit_strength_last(); 136 void BM_get_balls_hit_strength_last_index(int index, double * strength, double * toffs); 137 double BM_get_walls_hit_strength_last(); 138 void BM_get_walls_hit_strength_last_index(int index, double * strength, double * toffs); 139 140 BallType * BM_get_ball_by_nr( int nr, BallsType *pballs ); 141 142 int proceed_dt(BallsType *balls, BordersType *borders, BMfloat dt); 143 144 #ifdef USE_ADV_BORDER 145 BMfloat ball_advborder_dist( BallType *b, BorderType *w ); 146 #endif 147 148 void BM_add2path( BallType *pball ); 149 void BM_clearpath( BallType *pball ); 150 151 #endif /* BILLMOVE_H */ 152