By David M. Bourg, Glenn Seemann
Price: $39.95 USD
£28.50 GBP
Cover | Table of Contents | Colophon
if (predatorX > preyX)
predatorX--;
else if (predatorX < preyX)
predatorX++;
if (predatorY > preyY)
predatorY--;
else if (predatorY < preyY)
predatorY++;
if (preyX > predatorX)
preyX++;
else if (preyX < predatorX)
preyX--;
if (preyY > predatorY)
preyY++;
else if (preyY < predatorY)
preyY--;
ControlData {
double turnRight;
double turnLeft;
double stepForward;
double stepBackward;
};
Pattern[0].turnRight = 0;
Pattern[0].turnLeft = 0;
Pattern[0].stepForward = 2;
Pattern[0].stepBackward = 0;
Pattern[1].turnRight = 0;
Pattern[1].turnLeft = 0;
Pattern[1].stepForward = 2;
Pattern[1].stepBackward = 0;
Pattern[2].turnRight = 10;
Pattern[2].turnLeft = 0;
Pattern[2].stepForward = 0;
Pattern[2].stepBackward = 0;
Pattern[3].turnRight = 10;
Pattern[3].turnLeft = 0;
Pattern[3].stepForward = 0;
Pattern[3].stepBackward = 0;
Pattern[4].turnRight = 0;
Pattern[4].turnLeft = 0;
Pattern[4].stepForward = 2;
Pattern[4].stepBackward = 0;
Pattern[5].turnRight = 0;
Pattern[5].turnLeft = 0;
Pattern[5].stepForward = 2;
Pattern[5].stepBackward = 0;
Pattern[6].turnRight = 0;
Pattern[6].turnLeft = 10;
Pattern[6].stepForward = 0;
Pattern[6].stepBackward = 0;
.
.
.
void InitializePathArrays(void)
{
int i;
for (i=0;i<kMaxPathLength;i++)
{
pathRow[i] = --1;
pathCol[i] = --1;
}
}
http://www.oreilly.com/catalog/ai).
void DoUnitAI(int i)
{
int j;
Vector Fs;
Vector Pfs;
Vector r, u;
double U, A, B, n, m, d;
// begin Flock AI
Fs.x = Fs.y = Fs.z = 0;
Pfs.x = 0;
Pfs.y = Units[i].fLength / 2.0f;
if(Swarm)
{
for(j=1; j<_MAX_NUM_UNITS; j++)
{
if(i!=j)
{
r = Units[i].vPosition -
Units[j].vPosition;
u = r;
u.Normalize();
A = 2000;
B = 10000;
n = 1;
m = 2;
d = r.Magnitude()/
Units[i].fLength;
U = -A/pow(d, n) +
B/pow(d, m);
Fs += VRotate2D(
-Units[i].fOrientation,
U * u);
}
}
}
Units[i].Fa = Fs;
Units[i].Pa = Pfs;
// end Flock AI
}