Defining a Collision Group

Overview

To define a collision group, the following steps are required:

Step

Action

1

Within the variable declaration, define some collision objects. The collision objects are the objects that will be added to the collision group:

VAR
      //a Sphere function block
      fbSphere : COD.FB_Sphere;
      //an OBB function block
      fbOBB1 : COD.FB_OBB;
      //another OBB function block
      fbOBB2 : COD.FB_OBB;
END_VAR

In addition to these objects, some other support variables may be required.

2

Within the variable declaration, define an instance of a collision group object:

VAR//a collision group instance
      fbGroup : COD.FB_CollisionGroup;
END_VAR

3

Call the method fbGroup.AddCollisionObject(…) of the group to add the desired collision objects. You can save the index of an object added to the group reading the return value of AddCollisionObject.

//add fbSphere to the group
udiSphereIndex := fbGroup.AddCollisionObject(
      i_ifCollisionObject := fbSphere,
      q_xError => xError, 
      q_etResult => etResult, 
      q_sResultMsg=> sResultMsg
   );

//check diagnostics here
IF xError THEN
      //do something to handle the errorEND_IF

//add fbOBB1 to the group
udiOBB1Index := fbGroup.AddCollisionObject(
      i_ifCollisionObject := fbOBB1,
      q_xError => xError, 
      q_etResult => etResult, 
      q_sResultMsg=> sResultMsg
   );

//check diagnostics here//add fbOBB2 to the group
udiOBB2Index := fbGroup.AddCollisionObject(
      i_ifCollisionObject := fbOBB2,
      q_xError => xError, 
      q_etResult => etResult, 
      q_sResultMsg=> sResultMsg
   );

//check diagnostics here
NOTE:
  • If all the calls of AddCollisionObject have been successful, the property fbGroup.udiNumberOfCollisionObjects shows the correct number of objects stored within the group. In this example, it is fbGroup.udiNumberOfCollisionObjects = 3.

  • The collision objects do not need to be configured (for example, fbSphere.xConfigured = TRUE) at the time they are added to a collision group.

  • Each collision object added to the list is then accessible from the property fbGroup.raifCollisionObjects as a COD.IF_CollisionObject interface according to the order of insertion in the group.

4

You can use the index value returned on a call of AddCollisionObject to access the right interface from fbGroup.raifCollisionObjects.

5

If you need to reconfigure a group, you can call the method fbGroup.Reset(…) of the collision group to remove the objects from the group and then start a new configuration.

6

Perform an update of the group before using the group in a collision or distance query.

To do so, the following steps must be followed:

  • If required, reconfigure the single collision objects and verify that they are properly configured; this means that xConfigured = TRUE for each object in the list.

  • If one or more collision objects have been reconfigured, call the method fbGroup.Update(…) as follows:

    fbGroup.Update(
          q_xError => xError,
          q_etResult => etResult,
          q_sResultMsg=> sResultMsg
    );

7

You can verify fbGroup.xUpdated = TRUE, to verify if the last Update call has been successful. This is a mandatory condition in order to be able to perform a collision or distance query on a group.

NOTE:
  • If at least one successful update has been performed and no modifications have been performed on the listed objects, there is no need to perform a new Update call.

  • It is possible to define overlapping objects within the same group. This does not generate the detection of a self-collision while calling the collision and distance query functions.

  • The same collision object instance can be added to multiple groups in the same way. It is possible to get a single object from an existing group and use it individually for the collision and distance queries.