Sunday 23 November 2008

Notes from the Artical -"Designing a Realistic and Unified Agent Sensing Model" by Steve Rabni and Michael Delp

This entry focuses on developing a better Agent Sensing Model, more specifically, the agents vision.

Designing a Realistic and Unified Agent-Sensing Model - notes

With increased visual realism in modern day games, gamers expect to see game agents with the ability to sense the game world with greater fidelity and subtlety. Traditionally, this has been done in a very simplistic manner through a combination of view distance, view cones and line-of-sight testing. A similar approach is taken when applying agent hearing. A simple method of just testing against some pre-determined cut-off distance to check if a sound can be heard or not. Although these methods are simple and cheap ways to create agent sensing, they are rather transparent and can produce rather shallow game play. As an example, if the player is somewhere in front of the agent, the agent will perform a discrete distance check to see if the player can be seen. This creates a blind zone beyond the maximum distance the agent can see. Many players are now aware of this flaw and exploit it to their advantage by momentarily appearing within the agents sight range, then running away, effectively luring the agent away from it’s position.

            This method is going to enhance this basic sense/perception model by applying a handful of clever additions that will make the agents perception model appear much more life-like and realistic.

Basic Vision Model

The core model used for agent vision model in many modern day games comprises of three main techniques and calculations. These techniques – which are usually calculated in this order due to efficiency – are as follows; view distance, view cones and line of sight.

{Insert Picture}

 

The view distance calculation is a rather simple distance check. It is more efficient to use the squared distance in the test rather than the actual distance to avoid performing a square root calculation. For example, if an agent is standing position (0,0,0) can see 50 meters away and the player is at  (25, 30,0), we can take the dot product of the vector between the agent and player and compare this against the view distance squared. (The dot product of the vector between the two is 25^2 + 30^2 + 0^2 = 1525. 1525 compared to the squared view distance of 2500 means that player can be seen by the agent as 2500>1525). The distance can be squared as we are only after the relative distance.

            After this, the view cone check can be done. To do this the dot product between the agents normalised forward vector and the normalised vector that goes from the agent to the player. If the result from this calculation is greater than 0 then the player is within a 180degree view cone from the agent, if the result is more than0.5, the player is within the agents 120 degree view cone (cos 60 = 0.5). If only the 180degree cone is needed, we can optimize this by not normalising the vectors (which potentially eliminates two square root calculations).

            The line-of-sight test is usually the final check to perform, and is the most demanding of the three. A ray is fired from the agent to the player’s location. If the ray intersects an object before it reached the player, the agent cannot see the player. If bounding boxes are used for the geometry and other in game objects then this test can be optimised slightly.

It is these three core methods, outlined above, that lay the foundation for the agent’s vision model. These techniques will be expanded upon and improved to provide a better, more realistic model.

Augmenting the Vision Model Toolbox with Ellipses

The methods mentioned previously do not model realistic human or animal vision very well. View Cones in particular have several flaws.

  • Potentially the agent will not be able to see any other agents or entities that are right next to it.
  • The visual acuity is at it’s highest at the centre of the vision cone and degrades as the distance increases. Far vision is overestimated and the near vision is underestimated.
  • To avoid giving an agent a very good far vision, designers and developers tend to make the view distance unrealistically short.

 

One way that some developers have tried to get around this, is by using multiple vision cones in attempt to try and model something similar to human vision. The problem with this approach is that it can create large holes or blind spots in the agent’s vision.

{insert Picture}

On the left, the thin cone represents the centre of focus which reaches far into the distance. The wider cone gives a much broader view but has a short range. The circle around the agent detects any entities adjacent or behind the agent (this is used to mimic the fact that humans often have the ability to sense when someone is behind them). Note the blind spots produced at the intersection points of the two cones.

 

A simple way to solve this would be to represent the vision model using an ellipse. As can be seen by the picture, the ellipse offers up a solution with the “degradation of visual acuity with distance without leaving holes in the vision”. The ellipse is started behind the agent (again to model a humans ability to sense people behind them).

Ellipse Implementation

To be able to produce an accurate vision model using an ellipse, it is very important that we understand its components.

{insert picture}

Major axis length is 2a, minor axis length is 2b. F1 and F2 (focal points) are at +/- c from the ellipse centre and c^2 = a^2 – b^2.

Middle figure displays important fact about the ellipse. The distance from the 2 focal points to any point on the outside of the ellipse is 2a. To determine if something is within the ellipse, the focal point positions must be found.

For human vision, one end of the ellipse is placed at the agent’s eye and the view angle specified. A triangle is then formed from the view angle at the agent’s eye and the ends of the axis in the centre of the ellipse. Given that Theta is half the view angle and a is half view distance we find the equation of c given theta and a.

{insert equation}

            To find out if an entity can been seen by the agent, we simply have to take the entities distance from each of the focal points, add them together and check that they are less than the maximum viewing distance of 2a. Therefore all that is needed is two distance checks for each entity in question per agent. Note that squared distances cant be used in the equation as we have to add them together. This works for 3d and 2d. If height becomes important in the game, we will use 3d.

            Using this ellipse to model the vision is easy to calculate in not really much more expensive than the view cone method.

No comments: