Hi sysande,

In this kind of situation it is important to have a system in your program for getting useful information in a simple fashion. While you can run brute-force calculations to find the absolute coordinates of an obstacle compared with your crowd of people, it seems that you'll want them all added to the same parent node (if not the root). I would imagine this as a world node that represents the bounds of your scene (floor and perhaps walls and ceiling), and then you add your crowd entities and obstacles to this node. At this point, your scene becomes far more simple to read data from; all distances and collisions can be checked with the relative translations held in the H3DNode. An added benefit of this is that you can position/rotate/scale the whole world without having to rearrange your crowd environment. If you do need them to have different environments (perhaps checking from a hierarchy of obstacles) then you need to calculate the object's absolute matrix and the absolute matrix of the obstacle you're checking against, so that your values are in the same dimensions.

You can use the h3dGetNodeTransform function to get the transformation data of a H3DNode. With this, you have the Cartesian coordinates of each object you wish to check for collisions. There is also the node's axis-aligned bounding box information via h3dGetNodeAABB if you need, although this is not required for simple distance-checking (you would just need a radius value instead).

Once you have the x/y/z of the entity and the obstacle, you can find the distance with a little help from Pythagoras:

**Code:**

float px, py, pz; //entity's x/y/z position

float ox, oy, oz; //obstacle's x/y/z position

h3dGetNodeTransform(_entityNode, &px, &py, &pz, 0, 0, 0, 0, 0, 0); //we only need translation data

h3dGetNodeTransform(_obstacleNode, &ox, &oy, &oz, 0, 0, 0, 0, 0, 0);

float dx = px - ox; //find the difference between the two points

float dy = py - oy;

float dz = pz - oz;

float distSq = (dx*dx + dy*dy + dz*dz); //gives the squared distance between the two points

This is a verbose way of getting the raw data you need, finding the difference between the two points and then finding that value as a straight line. Of course if the entities are walking on a flat floor then you won't need to include the y values in the calculations. You can of course find the square root of the distSq value, but this is relatively intensive and not required if you just want to check for collisions.

If you want to find when a collision occurs, you can define the radius of each object; then the check is quite simply

**Code:**

//pRadius = entity's radius

//oRadius = obstacle's radius

if (distSq < pRadius*pRadius + oRadius*oRadius)

{

//collision occurred

}

Again, you don't need to square the radii if you square-rooted the distance.

The above information assumes perfectly spherical collisions, and accurate collision checking for different kinds of shapes is a very deep topic. For example, you may want to use radial checking as above for your characters but instead have a bounding-box check for collisions with a wall. In this case, it is not the distance that matters but the x/z position in relation to the obstacle. This again assumes a perfectly flat pair of edges, and any differently shaped objects will not collide properly (an axis-aligned bounding box won't behave in the expected manner if the node is rotated). Perhaps the simplest way of checking this would be by finding the point-to-plane distance, which is relatively complicated but is explained nicely here

http://mathinsight.org/distance_point_plane.