1 /* glschool_alg.h, Copyright (c) 2005-2006 David C. Lambert <dcl@panix.com>
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
11 #ifndef __GLSCHOOL_ALG_H__
12 #define __GLSCHOOL_ALG_H__
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)])
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)])
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)])
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])
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])
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)])
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])
110 extern void initFishes(School *);
111 extern void initFish(Fish *, double *, double *);
113 extern void applyMovements(School *);
114 extern void applyFishMovements(Fish *, BBox *, double, double, double);
116 extern void freeSchool(School *);
117 extern School *initSchool(int, double, double, double, double, double, double, double, double, double, double, double);
119 extern void newGoal(School *);
120 extern void setBBox(School *, double, double, double, double, double, double);
122 extern void computeAccelerations(School *);
123 extern double computeNormalAndThetaToPlusZ(double *, double *);
124 int computeGroupVectors(School *, Fish *, double *, double *, double *);
126 #endif /* __GLSCHOOL_ALG_H__ */