1 /* glschool_alg.h, Copyright (c) 2005-2006 David C. Lambert <dcl@panix.com> 2 * 3 * Permission to use, copy, modify, distribute, and sell this software and its 4 * documentation for any purpose is hereby granted without fee, provided that 5 * the above copyright notice appear in all copies and that both that 6 * copyright notice and this permission notice appear in supporting 7 * documentation. No representations are made about the suitability of this 8 * software for any purpose. It is provided "as is" without express or 9 * implied warranty. 10 */ 11 #ifndef __GLSCHOOL_ALG_H__ 12 #define __GLSCHOOL_ALG_H__ 13 14 typedef struct { 15 double mins[3]; 16 double maxs[3]; 17 } BBox; 18 19 #define BBOX_XMIN(b) ((b)->mins[0]) 20 #define BBOX_YMIN(b) ((b)->mins[1]) 21 #define BBOX_ZMIN(b) ((b)->mins[2]) 22 #define BBOX_MINS(b) ((b)->mins) 23 #define BBOX_IMIN(b, i) ((b)->mins[(i)]) 24 25 #define BBOX_XMAX(b) ((b)->maxs[0]) 26 #define BBOX_YMAX(b) ((b)->maxs[1]) 27 #define BBOX_ZMAX(b) ((b)->maxs[2]) 28 #define BBOX_MAXS(b) ((b)->maxs) 29 #define BBOX_IMAX(b, i) ((b)->maxs[(i)]) 30 31 #define BBOX_IMID(b, i) (((b)->maxs[(i)] + (b)->mins[(i)])/2.0) 32 #define BBOX_IRANGE(b, i) ((b)->maxs[(i)] - (b)->mins[(i)]) 33 34 typedef struct { 35 double pos[3]; 36 double vel[3]; 37 double accel[3]; 38 double oldVel[3]; 39 double magic[3]; 40 double avgVel[3]; 41 } Fish; 42 43 #define FISH_POS(f) ((f)->pos) 44 #define FISH_X(f) ((f)->pos[0]) 45 #define FISH_Y(f) ((f)->pos[1]) 46 #define FISH_Z(f) ((f)->pos[2]) 47 48 #define FISH_VEL(f) ((f)->vel) 49 #define FISH_VX(f) ((f)->vel[0]) 50 #define FISH_VY(f) ((f)->vel[1]) 51 #define FISH_VZ(f) ((f)->vel[2]) 52 53 #define FISH_ACC(f) ((f)->accel) 54 #define FISH_MAGIC(f) ((f)->magic) 55 #define FISH_OLDVEL(f) ((f)->oldVel) 56 #define FISH_AVGVEL(f) ((f)->avgVel) 57 #define FISH_IPOS(f, i) ((f)->pos[(i)]) 58 #define FISH_IVEL(f, i) ((f)->vel[(i)]) 59 #define FISH_IACC(f, i) ((f)->accel[(i)]) 60 #define FISH_IMAGIC(f, i) ((f)->magic[(i)]) 61 #define FISH_IOLDVEL(f, i) ((f)->oldVel[(i)]) 62 #define FISH_IAVGVEL(f, i) ((f)->avgVel[(i)]) 63 64 typedef struct { 65 int nFish; 66 double maxVel; 67 double minVel; 68 double distExp; 69 double momentum; 70 double accLimit; 71 double minRadius; 72 double minRadiusExp; 73 double avoidFact; 74 double matchFact; 75 double centerFact; 76 double targetFact; 77 double distComp; 78 double goal[3]; 79 double boxMids[3]; 80 double boxRanges[3]; 81 BBox theBox; 82 Fish *theFish; 83 } School; 84 85 #define SCHOOL_NFISH(s) ((s)->nFish) 86 #define SCHOOL_MAXVEL(s) ((s)->maxVel) 87 #define SCHOOL_MINVEL(s) ((s)->minVel) 88 #define SCHOOL_DISTEXP(s) ((s)->distExp) 89 #define SCHOOL_MOMENTUM(s) ((s)->momentum) 90 #define SCHOOL_ACCLIMIT(s) ((s)->accLimit) 91 #define SCHOOL_MINRADIUS(s) ((s)->minRadius) 92 #define SCHOOL_MINRADIUSEXP(s) ((s)->minRadiusExp) 93 #define SCHOOL_MATCHFACT(s) ((s)->matchFact) 94 #define SCHOOL_AVOIDFACT(s) ((s)->avoidFact) 95 #define SCHOOL_CENTERFACT(s) ((s)->centerFact) 96 #define SCHOOL_TARGETFACT(s) ((s)->targetFact) 97 #define SCHOOL_DISTCOMP(s) ((s)->distComp) 98 #define SCHOOL_GOAL(s) ((s)->goal) 99 #define SCHOOL_IGOAL(s,i) ((s)->goal[(i)]) 100 #define SCHOOL_BBMINS(s) ((s)->bbox.mins) 101 #define SCHOOL_BBMAXS(s) ((s)->bbox.maxs) 102 #define SCHOOL_BBMIDS(s) ((s)->boxMids) 103 #define SCHOOL_IMID(s,i) ((s)->boxMids[(i)]) 104 #define SCHOOL_BBRANGES(s) ((s)->boxRanges) 105 #define SCHOOL_IRANGE(s,i) ((s)->boxRanges[(i)]) 106 #define SCHOOL_BBOX(s) ((s)->theBox) 107 #define SCHOOL_FISHES(s) ((s)->theFish) 108 #define SCHOOL_IFISH(s,i) ((s)->theFish[i]) 109 110 extern void glschool_initFishes(School *); 111 extern void glschool_initFish(Fish *, double *, double *); 112 113 extern void glschool_applyMovements(School *); 114 /* extern void applyFishMovements(Fish *, BBox *, double, double, double); */ 115 116 extern void glschool_freeSchool(School *); 117 extern School *glschool_initSchool(int, double, double, double, double, double, double, double, double, double, double, double); 118 119 extern void glschool_newGoal(School *); 120 extern void glschool_setBBox(School *, double, double, double, double, double, double); 121 122 extern void glschool_computeAccelerations(School *); 123 extern double glschool_computeNormalAndThetaToPlusZ(double *, double *); 124 int glschool_computeGroupVectors(School *, Fish *, double *, double *, double *); 125 126 #endif /* __GLSCHOOL_ALG_H__ */ 127