Collision Environment
A CollisionEnvironment
is a game environment that manages characters and obstacles. A character is an agent that participates in the game that is played in the environment (for more information on Character
, click here). An obstacle is a physical object with a given geometric shape that is positioned in the environment (for more information on Obstacle
, click here). The environment can handle different collision types, each described by a CollisionKind
(for more information on CollisionKind
, click here). A simple example showing a few functionalities can be found here.
While a CollisionEnvironment
does not feature agents and entities, it has characters and obstacles. A character corresponds to an agent, and an obstacle corresponds to an entity. Characters can interact with obstacles, similar to how agents can interact with entities.
Creating an environment
A CollisionEnvironment
does not have a layer in the usual sense. The spatial extent of a CollisionEnvironment
can be specified explicitly via a bounding box. If no bounding box is defined, the spatial extent is defined dynamically based on the positions of the obstacles.
Initialization occurs as shown in the following code snippet.
var environment = new CollisionEnvironment<Player, Obstacle>();
If an explicit spatial extent is desired, it can be specified via a bounding box as follows:
environment.BoundingBox = new BoundingBox(new Position(0, 0), new Position(9, 9));
Here, the character type Player
implements IPlayer
and the obstacle type Obstacle
implements IObstacle
.
It is possible to load geometries to create a desired playground within environment
. The following two code snippets provide examples for generating geometries: a line string and a polygon.
var lineString = new LineString(new[] {
new Coordinate(5,5),
new Coordinate(8,8)
});
var polygon = new Polygon(new LinearRing(new[]
{
new Coordinate(1,1),
new Coordinate(2,3),
new Coordinate(3,3),
new Coordinate(1,1)
}));
![]() | Fig.1: Illustration of a possible CollisionEnvironment with a bounding box spanning the coordinates between and . The environment holds the obstacles generated in the two above code snippets. The red line represents lineString and the blue triangle represents polygon . |
---|
The two generated geometries can be inserted into the environment as follows.
environment.Insert(new Obstacle(), polygon);
environment.Insert(new Obstacle(), lineString);
The environment
consists of a graph (made up of nodes and edges) that holds inserted obstacles at their specified positions. A node is a RoutingPoint
and an edge is a Route
. A set of routing points can be arranged evenly (as shown in Fig.1) with a slight offset (as shown in Fig.2) in a grid structure.
TODO: Einstellungsparameter für Environment-Initialisierung finden und hier dokumentieren.
![]() | Fig.2: Illustration of a possible CollisionEnvironment with a spatial extent that was generated dynamically based on the positioning of the obstacles. The routing points that have a slight offset. The edges represent possible paths through the environment. The purple boxes represent obstacles. |
---|
The offset can be introduced as follows. Here, a total of 225
routing points are distributed homogeneously across the environment
with an offset per routing point of 0.05
. The resulting distribution of routing points can look like the set of routing points shown in Fig.2.
environment.RoutingPointsGenerator =
new HomogenousRoutingPointsGenerator(225, 0.05);
Alternatively to the homogeneous distributions shown in Fig.1 and Fig.2, a set of routing points that are distributed heterogeneously in space can be defined as follows. Here, a previously defined bounding box is divided into 20
sections and 5
routing points per section.
environment.RoutingPointsGenerator =
new SectionalRandomRoutingPointsGenerator(20, 5);
Note: In all cases, the modeller is responsible for the correct positioning of characters within the environment
. Therefore, it is advisable to position obstacles first (thereby generating the spatial extent of the environment) and then positioning characters such that they are situated within that spatial extent.
Interaction with/within the CollisionEnvironment
Add a character to the environment
To add a Player
to the environment
, the Insert()
method of the Environment
is used.
Position = RandomPosition();
Environment.Insert(this);
This example takes place in the initialization method of a character Player
. The character has a property Position
. This property is initialized with a random position that consists of a tuple . Once the character has a defined position, it can be placed on the Environment
by calling the environment's Insert(<object reference>)
method and passing a reference to the character.
Remove an existing object
Removing a character follows the same principle as adding it. The Remove(<object to remove>)
method is executed via the Environment
and the entity to be removed is specified.
Environment.Remove(<object to remove>);
Move an agent to another location
A Player
can call the Move(...)
method of a CollisionEnvironment
to move through the environment, as shown in the following code snippet.
Environment.Move(this, <bearing>, <distance>)
<bearing>
is a double between 0.0 and 360.0 that specifies the direction in which thePlayer
wants to move. Here, 0.0 means a direction that points north. The direction of a value that is larger than 0.0 is determined by turning in a clock-wise direction from the north-facing direction.<distance>
is a double that defines the number of units that thePlayer
wants to move in the direction specified by<bearing>
.
Note: The actual movement trajectory of a Player
depends on the properties of the Obstacle
objects (e.g., CollisionKind
) that the Player
might encounter on the desired path trajectory specified by <bearing>
and <distance>
. For more information on obstacles, please see (for more information on CollisionKind
, click here).
In addition to movement via the Move(...)
method, a route between two RoutingPoints
can be specified via the FindRoute(...)
method as follows.
var route = environment.FindRoute(character, goal).ToList();
This call returns a route, which is a list of Position
objects. The route specifies a path through the environment from the current position of character
to goal
.
Explore other characters and obstacles
A Player
can explore other characters and obstacles in the environment as shown in the following two code snippets.
var exploredCharacters = environment.ExploreCharacters(<source>, <geometry>, <predicate>)
var exploredObstacles = environment.ExploreObstacles(<geometry>, <predicate>)
ExploreCharacters(...)
returns a list of characters, where<source>
is the requesting character,<geometry>
is the spatial area of exploration, and<predicate>
is an optional filter criterion that can be set to filter the returned collection.ExploreCharacters(...)
returns a list of obstacles, where<geometry>
is the spatial area of exploration and<predicate>
is an optional filter criterion that can be set to filter the returned collection.
Exporting data for a Grid Environment
TODO
Character
A Character
is an active participant of the game that is played in a CollisionEnvironment
. It is described by the following properties:
ID
: AGuid
that uniquely identifies aCharacter
Position
: The current position, described by a tuple , of aCharacter
Extent
: The spatial extent of aCharacter
Furthermore, the following method is inherent to every Character
:
HandleCollision(ICharacter other)
: This method is called by aCharacter
upon collision withICharacter
(a collision between two characters). It returns aCollisionKind
that represents the action that theCharacter
should take as a result of the collision.
A CollisionKind
can be one of three actions:
Block
: ACharacter
blocksother
, i.e., acts like a obstacle for thatCharacter
Pass
: ACharacter
moves throughother
, i.e., continues along its original movement trajectoryRemove
: ACharacter
is removed from the environment due to the collision
Obstacle
IsRoutable(ICharacter)
: returns a boolean that states whetherICharacter
is a blocking object or can be passedHandleCollision(ICharacter)
: This method is called by anObstacle
whenICharacter
collides with it. It returns aCollisionKind
that represents the role that theObstacle
should play in the context of the movement behavior ofICharacter
.HandleExploration(ICharacter)
: This method handles the visibility check for theObstacle
by returning theVisibilityKind
of theObstacle
A VisibilityKind
describes whether an Obstacle
is Transparent
or Opaque
with respect to the vision of a Character
:
Transparent
: ACharacter
can see through theObstacle
Opaque
: ACharacter
cannot see through theObstacle