Steering Behaviors for Autonomous Agents - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Steering Behaviors for Autonomous Agents

Description:

A wall is a line segment (in 3D, a plane) with a normal pointing in the ... I DONT KNOW! distance = dotproduct (point, plane.normal) - plane.distance; EG: ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 23
Provided by: bdug1
Category:

less

Transcript and Presenter's Notes

Title: Steering Behaviors for Autonomous Agents


1
Steering Behaviors for Autonomous Agents
  • Bryan Duggan

2
Steering BehavioursContainment
  • A wall is a line segment (in 3D, a plane) with a
    normal pointing in the direction it is facing.
  • Wall avoidance steers to avoid potential
    collisions with a wall. It does this by
    projecting three "feelers" out in front of the
    vehicle and testing to see if any of them
    intersect with any walls in the game world.
  • This is similar to how cats and rodents use their
    whiskers to navigate their environment in the
    dark.
  • When the closest intersecting wall has been found
    (if there is one of course), a steering force is
    calculated.
  • This is deduced by calculating how far the feeler
    tip has penetrated through the wall and then by
    creating a force of that magnitude in the
    direction of the wall normal.

3
Containment in 3D?
  • A probe left
  • A probe right
  • A probe forwards
  • A probe up ?
  • A probe down ?
  • Do left right and forwards need to be
    recalculated relative to the ships direction?
  • Do up and down?
  • Calculate distance between a point and a plane

4
Calculate the distance
  • Why is this? I DONT KNOW!
  • distance dotproduct (point, plane.normal) -
    plane.distance
  • EG
  • The plane given by 0, 1, 0, 5
  • The point 10, 10, 10
  • Should give distance of 5

5
Aside Plane from points
  • plane p // plane to construct from a,b and c
    tvector a,b,c // points to build a plane from
  • // build normal vector tvector q,v
  • q.x b.x - a.x
  • v.x b.x - c.x
  • q.y b.y - a.y
  • v.x b.y - c.y
  • q.z b.y - a.y
  • v.x b.z - c.z
  • p.normal crossproduct (q,v)
  • normalize_vector (q.normal)
  • // calculate distance to origin
  • p.distance dotproduct (p.normal, a) // you
    could also use b or c

Why is this??
6
Basic algorithm
  • Create the feelers
  • Take the default look vector depth of the
    feeler
  • Rotate it to create left, right ( Y Axis - yaw),
    up and down (X Axis - pitch) feelers
  • Transform to world space ( the world transform)
  • Find out if each feeler penetrates the planes
  • n.p d
  • D3DXPlaneDotCoord
  • If lt 0, then it penetrates, so...
  • Calculate the distance
  • distance abs(dotproduct (point, plane.normal) -
    plane.distance)
  • Calculate the force
  • n distance
  • Do this for each feeler and sum the forces

7
  • D3DXVECTOR3 force D3DXVECTOR3(0, 0, 0)
  • D3DXPLANE worldPlane _gameEntity-gtgetWorld()-gtg
    etWorldPlane()
  • float distance 10
  • // Create 3 feelers
  • D3DXVECTOR3 feeler3
  • D3DXMATRIX rot
  • feeler1 D3DXVECTOR3(0, 0, 1) distance //
    Straight forward on the Z
  • // Rotate by -45
  • D3DXMatrixRotationY( rot, - D3DX_PI / 4)
  • D3DXVec3TransformCoord( feeler0, feeler1,
    rot)
  • // Rotate by 45
  • D3DXMatrixRotationY( rot, D3DX_PI / 4)
  • D3DXVec3TransformCoord( feeler2, feeler1,
    rot)
  • // Now transform into world space
  • for (int i 0 i lt 3 i )

8
  • // Check if any of the feelers penetrate the
    world plane
  • for (int i 0 i lt 3 i )
  • float invcos D3DXPlaneDotCoord( worldPlane,
    feeleri)
  • // If one of the feelers is behind the plane
  • if (invcos lt 0)
  • // Calculate the distance
  • D3DXVECTOR3 normal
  • normal.x worldPlane.a
  • normal.y worldPlane.b
  • normal.z worldPlane.c
  • float distance fabs(D3DXVec3Dot( feeleri,
    normal) - worldPlane.d)
  • // Calculate the force
  • D3DXVECTOR3 feelerForce
  • //D3DXVec3Normalize( feelerForce,
    (feeleri - _gameEntity-gtgetPosition()))
  • feelerForce normal distance
  • force feelerForce

9
Spherical containment?
  • Create the feelers
  • Take the default look vector depth of the
    feeler
  • Rotate it to create left, right ( Y Axis - yaw),
    up and down (X Axis - pitch) feelers
  • Transform to world space ( the world transform)
  • Find out if each feeler penetrates the sphere
  • Calculate the distance from the centre to the
    feeler
  • If gt radius then
  • Calculate the normal
  • (feeler centre) and normalise
  • Calculate the force
  • n (radius distance)
  • Do this for each feeler and sum the forces

10
(No Transcript)
11
  • // Check if any of the feelers penetrate the
    world sphere
  • for (int i 0 i lt 3 i )
  • float dist D3DXVec3Length( (centre -
    feeleri))
  • if (dist gt radius)
  • D3DXVECTOR3 normal
  • D3DXVec3Normalize( normal , (feeleri -
    centre ))
  • D3DXVECTOR3 feelerForce normal (radius -
    dist)
  • force feelerForce

12
Summing forces
  • Method 1
  • Sum them all together
  • Optionally scale by the max force (Truncated SUM)
  • Advantage
  • Simple to code
  • Disadvantages
  • Some forces are more important!
  • Containment, obstacle avoidance

13
Summing forces
  • Sum
  • Truncated Sum
  • Weighted Truncated Sum
  • Weighted Truncated Running Sum with
    Prioritization
  • Prioritized Dithering

14
Method 2
  • Weighted sums
  • Multiply each steering behavior with a weight,
  • Sum them all together
  • Then truncate the result to the maximum allowable
    steering force

15
Method 3
  • Weighted Truncated Running Sum with
    Prioritization
  • A good compromise between speed and accuracy
  • Involves calculating a prioritised weighted
    running total
  • Truncated after the addition of each force to
    make sure the magnitude of the steering force
    does not exceed the maximum available
  • Prioritised since some behaviors can be
    considered much more important than others
  • For example wall avoidance and obstacle avoidance
    have priority over wander, seek etc
  • The behaviors with the highest priority are
    processed first, the ones with the lowest, last.
  • After each force is accumulated, the force is
    tested to see if the force exceeds the max force

16
3 possibilities
  • If there is a surplus remaining, the new force is
    added to the running total.
  • If there is no surplus remaining, the method
    returns false. When this happens, Calculate
    returns the current value of steeringForce
    immediately and without considering any further
    active behaviors.
  • If there is still some steering force available,
    but the magnitude remaining is less than the
    magnitude of the new force, the new force is
    truncated to the remaining magnitude before it is
    added.

17
  • bool SteeringBehavioursaccumulateForce(D3DXVECTO
    R3 runningTot, D3DXVECTOR3 forceToAdd)
  • //calculate how much steering force the vehicle
    has used so far
  • float soFar D3DXVec3Length(runningTot)
  • //calculate how much steering force remains to
    be used by this vehicle
  • float remaining _gameEntity-gtgetMaxForce() -
    soFar
  • //return false if there is no more force left
    to use
  • if (remaining lt 0.0f)
  • return false
  • //calculate the magnitude of the force we want
    to add
  • float toAdd D3DXVec3Length(forceToAdd)
  • //if the magnitude of the sum of ForceToAdd and
    the running total
  • //does not exceed the maximum force available
    to this vehicle, just
  • //add together. Otherwise add as much of the
    ForceToAdd vector as
  • //possible without going over the max.
  • if (toAdd lt remaining)

Not in Matt Bucklands example code
18
Prioritized Dithering
  • From Reynolds paper
  • this method checks to see if the first priority
    behavior is going to be evaluated this simulation
    step, dependent on a preset probability.
  • If it is and the result is non-zero, the method
    returns the calculated force and no other active
    behaviors are considered.
  • If the result is zero or if that behavior has
    been skipped over due to its probability of being
    evaluated, the next priority behavior is
    considered and so on, for all the active behaviors

19
  • SVector2D SteeringBehaviorsCalculateDithered()
  • //reset the steering force
  • m_vSteeringForce.Zero()
  • //the behavior probabilities
  • const double prWallAvoidance 0.9
  • const double prObstacleAvoidance 0.9
  • const double prSeparation 0.8
  • const double prAlignment 0.5
  • const double prCohesion 0.5
  • const double prWander 0.8
  • if (On(wall_avoidance) RandFloat() gt
    prWallAvoidance)
  • m_vSteeringForce WallAvoidance(m_pVehicle-gtW
    orld()-gtWalls())
  • m_dWeightWallAvoidance /
    prWallAvoidance
  • if (!m_vSteeringForce.IsZero())
  • m_vSteeringForce.Truncate(m_pVehicle-gtMaxFor
    ce())
  • return m_vSteeringForce

20
  • if (On(obstacle_avoidance) RandFloat() gt
    prObstacleAvoidance)
  • m_vSteeringForce ObstacleAvoidance(m_pVehic
    le-gtWorld()-gtObstacles())
  • m_dWeightObstacleAvoidance
    / prObstacleAvoidance
  • if (!m_vSteeringForce.IsZero())
  • m_vSteeringForce.Truncate(m_pVehicle-gtMaxFor
    ce())
  • return m_vSteeringForce
  • if (On(separation) RandFloat() gt
    prSeparation)
  • m_vSteeringForce Separation(m_pVehicle-gtWor
    ld()-gtAgents())
  • m_dWeightSeparation /
    prSeparation
  • if (!m_vSteeringForce.IsZero())

21
Obstacle avoidance
  • Steers a vehicle to avoid obstacles lying in its
    path.
  • Any object that can be approximated by a circle
    or sphere
  • This is achieved by steering the vehicle so as to
    keep a rectangular area a detection box,
    extending forward from the vehicle free of
    collisions.
  • The detection box's width is equal to the
    bounding radius of the vehicle, and its length is
    proportional to the vehicle's current speed the
    faster it goes, the longer the detection box.

22
In 3D
  • The box becomes a cylinder
  • When implementing obstacle avoidance in three
    dimensions, use spheres to approximate the
    obstacles and a cylinder in place of the
    detection box. The math to check against a sphere
    is not that much different than that to check
    against a circle. Once the obstacles have been
    converted into local space, steps A and B are the
    same as you have already seen, and step C just
    involves checking against another axis.
Write a Comment
User Comments (0)
About PowerShow.com