7 #include "imstkCapsuleToCapsuleCD.h" 8 #include "imstkCapsule.h" 9 #include "imstkCollisionUtils.h" 13 CapsuleToCapsuleCD::CapsuleToCapsuleCD()
15 setRequiredInputType<Capsule>(0);
16 setRequiredInputType<Capsule>(1);
21 std::shared_ptr<Geometry> geomA,
22 std::shared_ptr<Geometry> geomB,
23 std::vector<CollisionElement>& elementsA,
24 std::vector<CollisionElement>& elementsB)
26 std::shared_ptr<Capsule> capsule0 = std::dynamic_pointer_cast<
Capsule>(geomA);
27 std::shared_ptr<Capsule> capsule1 = std::dynamic_pointer_cast<
Capsule>(geomB);
30 const Vec3d capsule0Axis = capsule0->getOrientation().toRotationMatrix().col(1).normalized();
31 const double capsule0HalfLength = capsule0->getLength() * 0.5;
32 const Vec3d diff0 = capsule0Axis * capsule0HalfLength;
33 const double capsule0Radius = capsule0->getRadius();
35 const Vec3d capsule1Pos = capsule1->getPosition();
36 const Vec3d capsule1Axis = capsule1->getOrientation().toRotationMatrix().col(1).normalized();
37 const double capsule1HalfLength = capsule1->getLength() * 0.5;
38 const Vec3d diff1 = capsule1Axis * capsule1HalfLength;
39 const double capsule1Radius = capsule1->getRadius();
43 CollisionUtils::edgeToEdgeClosestPoints(
44 capsule0Pos - diff0, capsule0Pos + diff0,
45 capsule1Pos - diff1, capsule1Pos + diff1,
56 Vec3d sphereAContactPt, sphereBContactPt;
57 Vec3d sphereAContactNormal, sphereBContactNormal;
59 if (CollisionUtils::testSphereToSphere(
60 pt0, capsule0Radius, pt1, capsule1Radius,
61 sphereAContactPt, sphereAContactNormal,
62 sphereBContactPt, sphereBContactNormal,
66 elemA.dir = sphereAContactNormal;
67 elemA.pt = sphereAContactPt;
68 elemA.penetrationDepth = depth;
71 elemB.dir = sphereBContactNormal;
72 elemB.pt = sphereBContactPt;
73 elemB.penetrationDepth = depth;
75 elementsA.push_back(elemA);
76 elementsB.push_back(elemB);
Vec3d getPosition(DataType type=DataType::PostTransform)
Get the local or global position (post transformed)
void computeCollisionDataAB(std::shared_ptr< Geometry > geomA, std::shared_ptr< Geometry > geomB, std::vector< CollisionElement > &elementsA, std::vector< CollisionElement > &elementsB) override
Compute collision data for AB simultaneously.
Capsule geometry, default configuration is centered at origin with length running up and down the y a...
Direclty gives a point-direction contact as its collision data.