
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

















coordinates – Player can move in any direction
-^ In a continuous environment position isrepresented by floating point numbers which getmapped to the nearest screen pixel at rendertime. •^ Changing position in a continuous environment,you do not have to limit yourself to adjacentscreen pixels. •^ A small number of pixels can be skippedbetween each screen redraw without sacrificingmotion fluidity.
void ai_Entity::BuildPathToTarget(void) {^ int nextCol = col;^ int netRow = row;^ Int deltaRow = endRow – row;^ int deltaCol = endCol – col;^ int stepCol, stepRow;^ int currentStep, fraction;
If (deltaRow < 0) stepRow = -1; else stepRow = 1; If (deltaCol < 0) stepCol = -1; else stepCol = 1; deltaRow = abs(deltaRow2); deltaCol = abs(deltaCol2); pathRow[currentStep] = nextRow; pathCol[currentStep] = nextCol; currentStep++ •^ Pick the direction with the longest axis
-^ Example 2-7. Bresenham algorithm •^ if (deltaCol > deltaRow) •^ { •^
fraction – deltaRow *2-deltaCol;
-^
while (nextCol != endCol)
-^
{
-^
if (fraction >=0)
-^
{
-^
nextRow =nextRow +stepRow;
-^
fraction =fraction –deltaCol;
-^
}
-^
nextCol=nextCol+stepCol;
-^
fraction=fraction +deltaRow;
-^
pathRow[curr
entStep]=nextRow;
-^
pathCol[currentStep]=nextCol;
-^
currentStep++;
-^
}
-^ } •^ else •^ { •^
fraction =deltaCol *2-deltaRow;
-^
while (nextRow !=endRow)
-^
{
-^
if (fraction >=0)
-^
{
-^
nextCol=nextCol+stepCol;
-^
fraction=fraction –deltaRow;
-^
}
-^
nextRow =nextRow +stepRow;
-^
fraction=fraction +deltaCol;
-^
pathRow[curr
entStep]=nextRow;
-^
pathCol[currentStep]=nextCol;
-^
currentStep++;
-^
}
-^ }
-^ Vehicles are identical •^ Pushed by applied thrust and can turn via activation ofturning forces •^ Steering forces are “bow thrusters” •^ A steering force is applied that will push the nose of thevehicle to the left/right •^ The LOS algorithm will control activation of the steeringforces so that predator is always kept heading towardsthe prey •^ The max speed and turning angle are limited due tolinear and angular drag forces that are calculated andapplied to each vehicle •^ Turning radius is a function of linear speed – the higherthe linear speed, the larger the turning radius – leads tosmoother, more natural paths.
York CS410 Winter 2007
-^ u^ and
v^ are
Vector
types
-^ Vector
has operations defined:
right
are boolean variables to indicate which steering force to turn on^ – Both initially
false
-^ Calculate the relative position vector betweenthe predator and prey in global, earth-fixedcoordinates. •^ VRotate2D converts the vector to the predator’slocal, body-fixed coordinates. •^ Result is stored in
u^ and then
u^ is normalized
York CS410 Winter 2007
-^ u^ is a unit vector pointing from thepredator directly towards the prey • Next few lines determine if the prey is tothe port side, the starboard side, or directlyin front of the predator • The vehicle always heads along the
-^ SetThrusters