Skip to content
Snippets Groups Projects
Commit 0680201b authored by panjia1983's avatar panjia1983
Browse files

more document in readme.md

parent a8e47743
No related branches found
No related tags found
No related merge requests found
...@@ -138,6 +138,49 @@ PenetrationDepthResult result; ...@@ -138,6 +138,49 @@ PenetrationDepthResult result;
penetrationDepth(o1, o2,request, result); penetrationDepth(o1, o2,request, result);
``` ```
FCL supports broadphase collision/distance between two groups of objects and can avoid the n square complexity. For collision, broadphase algorithm can return all the collision pairs. For distance, it can return the pair with the minimum distance. FCL uses a CollisionManager structure to manage all the objects involving the collision or distance operations.
```cpp
// Initialize the collision manager for the first group of objects.
// FCL provides various different implementations of CollisionManager.
// Generally, the DynamicAABBTreeCollisionManager would provide the best performance.
BroadPhaseCollisionManager* manager1 = new DynamicAABBTreeCollisionManager();
// Initialize the collision manager for the second group of objects.
BroadPhaseCollisionManager* manager2 = new DynamicAABBTreeCollisionManager();
// To add objects into the collision manager, using BroadPhaseCollisionManager::registerObject() function to add one object
std::vector<CollisionObject*> objects1 = ...
for(std::size_t i = 0; i < objects1.size(); ++i)
manager1->registerObject(objects1[i]);
// Another choose is to use BroadPhaseCollisionManager::registerObjects() function to add a set of objects
std::vector<CollisionObject*> objects2 = ...
manager2->registerObjects(objects2);
// In order to collect the information during broadphase, CollisionManager requires two settings:
// a) a callback to collision or distance;
// b) an intermediate data to store the information generated during the broadphase computation
// For a), FCL provides the default callbacks for both collision and distance.
// For b), FCL uses the CollisionData structure for collision and DistanceData structure for distance. CollisionData/DistanceData is just a container including both the CollisionRequest/DistanceRequest and CollisionResult/DistanceResult structures mentioned above.
CollisionData collision_data;
DistanceData distance_data;
// Setup the managers, which is related with initializing the broadphase acceleration structure according to objects input
manager1->setup();
manager2->setup();
// Examples for various queries
// 1. Collision query between two object groups and get collision numbers
manager2->collide(manager1, &collision_data, defaultCollisionFunction);
int n_contact_num = collision_data.result.numContacts();
// 2. Distance query between two object groups and get the minimum distance
manager2->distance(manager1, &distance_data, defaultDistanceFunction);
double min_distance = distance_data.result.min_distance;
// 3. Self collision query for group 1
manager1->collide(&collision_data, defaultCollisionFunction);
// 4. Self distance query for group 1
manager1->distance(&distance_data, defaultDistanceFunction);
// 5. Collision query between one object in group 1 and the entire group 2
manager2->collide(objects1[0], &collision_data, defaultCollisionFunction);
// 6. Distance query between one object in group 1 and the entire group 2
manager2->distance(objects1[0], &distance_data, defaultDistanceFunction);
```
For more examples, please refer to the test folder: For more examples, please refer to the test folder:
- test_fcl_collision.cpp: provide examples for collision test - test_fcl_collision.cpp: provide examples for collision test
- test_fcl_distance.cpp: provide examples for distance test - test_fcl_distance.cpp: provide examples for distance test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment