This article shows how to create a spatial relationship that performs collision detection using Site Manager and the .NET API.
You should know the information in the following article:
Before you start, remember to:
Add the Ubisense references to your application
Add 2 objects of type 'Person' called 'Jon' and 'Juan'
Assign the representation of a person to the type 'Person'
Add an area to your database
Create a simple cell hierarchy
Create a new command line application and do the following:
Add a
Ubisense.USpatial.Monitor schema event
client with instance name
monitor_schema
Connect to your Geometry Cell
This guide shows you how to create a spatial relationship that monitors collisions between people.
After completing the basic setup above, add 2 new roles in the 'Geometry' tab of Site Manager. Name them 'Person_Object_Role' and 'Person_Subject_Role'. Both of these roles are going to have shapes relative to the type 'Person', so they will move around as the people move. The object role contains the subject role, so we need to define the shapes in the following ways. Firstly, define a new relative shape for the 'Person_Object_Role' as a cylinder slightly larger than the person, noting the bottom and top values:

Now define a new relative shape for the 'Person_Subject_Role' as a very small cylinder in the middle of the person, noting the bottom and top values. This ensures that the object role can contain the subject role as easily as possible:

Now add the relationship 'Person_Object_Role contains Person_Subject_Role' to the 'Monitored relations' section of the 'Geometry' tab of Site Manager. Do this by clicking on the 'Edit' button for either the 'Person_Object_Role Contains' relations or the 'Person_Subject_Role Contained by' relations.
We cannot use the Ubisense Map application to monitor this relationship because each
person plays the role of both object and subject. Therefore, the relationship 'Person_Object_Role
contains Person_Subject_Role' is always true for every person. We need to add a
simple monitoring application that ignores 'collisions' of people with
themselves. You should have created a
Ubisense.USpatial.Monitor schema event client
object
monitor_schema and connected to the
schema service at the Geometry Cell level.
Add an insert handler for the
Ubisense.USpatial.Monitor.Contains relation called
HandleCollision:
|
Define the collision handler as follows. Remember the row type for the
Ubisense.USpatial.Monitor.Contains relation is
Ubisense.USpatial.Interaction:
|
Use the simulator to make 2 people walk through each other to make your handler execute. If you defined the roles' shapes to be symmetrical about the middle of the person, your handler will execute once for each of the 2 people involved in the collision:

The example application simply prints out the names of the objects involved:

It is possible to make collision detection very accurate by extending what we have already done. You can add many 'Person_Subject_Role_x' roles to cover the edge of a person with very small shapes. You can add more 'Person_Object_Role_x' roles for each side of the person's shape, ensuring that each of the subject roles fits completely inside each of the object roles.
Finally, add monitored relations for each possibility of 'Person_Object_Role_x contains Person_Subject_Role_x'.
Other things you might want to add include:
Impassable walls playing an object role with an absolute shape
Unmovable objects playing an object role with an absolute shape
Movable objects playing an object role with relative shapes at the collision points, large enough to contain subject roles' shapes
Movable objects playing a subject role with many small relative shapes at the possible collision points