Advertisement
Guest User

fcl box collision

a guest
Dec 12th, 2012
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <fcl/shape/geometric_shapes.h>
  2. #include <fcl/shape/geometric_shapes_utility.h>
  3. #include <fcl/narrowphase/narrowphase.h>
  4. #include <iostream>
  5. #include <fcl/collision.h>
  6. #include <boost/foreach.hpp>
  7.  
  8. using namespace std;
  9. using namespace fcl;
  10. using boost::shared_ptr;
  11.  
  12. int main(int argc, char** argv) {
  13.   shared_ptr<Box> box0(new Box(1,1,1));
  14.   shared_ptr<Box> box1(new Box(1,1,1));
  15. //  GJKSolver_indep solver;
  16.   GJKSolver_libccd solver;
  17.   Vec3f contact_points;
  18.   FCL_REAL penetration_depth;
  19.   Vec3f normal;
  20.  
  21.   Transform3f tf0, tf1;
  22.   tf0.setIdentity();
  23.   tf0.setTranslation(Vec3f(.9,0,0));
  24.   tf0.setQuatRotation(Quaternion3f(.6, .8, 0, 0));
  25.   tf1.setIdentity();
  26.  
  27.  
  28.  
  29.   bool res = solver.shapeIntersect(*box0, tf0, *box1, tf1, &contact_points, &penetration_depth, &normal);
  30.  
  31.   cout << "contact points: " << contact_points << endl;
  32.   cout << "pen depth: " << penetration_depth << endl;
  33.   cout << "normal: " << normal << endl;
  34.   cout << "result: " << res << endl;
  35.  
  36.   static const int num_max_contacts = std::numeric_limits<int>::max();
  37.   static const bool enable_contact = true;
  38.   fcl::CollisionResult result;
  39.   fcl::CollisionRequest request(num_max_contacts,
  40.                                 enable_contact);
  41.  
  42.  
  43.   CollisionObject co0(box0, tf0);
  44.   CollisionObject co1(box1, tf1);
  45.  
  46.   fcl::collide(&co0, &co1, request, result);
  47.   vector<Contact> contacts;
  48.   result.getContacts(contacts);
  49.  
  50.   cout << contacts.size() << " contacts found" << endl;
  51.   BOOST_FOREACH(Contact& contact, contacts) {
  52.     cout << "position: " << contact.pos << endl;
  53.   }
  54.  
  55.  
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement