7 #include "imstkSphereToCapsuleCD.h" 8 #include "imstkCapsule.h" 9 #include "imstkCollisionUtils.h" 10 #include "imstkSphere.h" 14 SphereToCapsuleCD::SphereToCapsuleCD()
16 setRequiredInputType<Sphere>(0);
17 setRequiredInputType<Capsule>(1);
22 std::shared_ptr<Geometry> geomA,
23 std::shared_ptr<Geometry> geomB,
24 std::vector<CollisionElement>& elementsA,
25 std::vector<CollisionElement>& elementsB)
27 std::shared_ptr<Sphere> sphere0 = std::dynamic_pointer_cast<
Sphere>(geomA);
28 std::shared_ptr<Capsule> capsule1 = std::dynamic_pointer_cast<
Capsule>(geomB);
31 const double sphere0Radius = sphere0->getRadius();
33 const Vec3d capsule1Pos = capsule1->getPosition();
34 const Vec3d capsule1Axis = capsule1->getOrientation().toRotationMatrix().col(1).normalized();
35 const double capsule1HalfLength = capsule1->getLength() * 0.5;
36 const Vec3d diff1 = capsule1Axis * capsule1HalfLength;
37 const double capsule1Radius = capsule1->getRadius();
41 const Vec3d closestPt = CollisionUtils::closestPointOnSegment(sphere0Pos,
42 capsule1Pos - diff1, capsule1Pos + diff1, caseType);
46 Vec3d sphereAContactPt, sphereBContactPt;
47 Vec3d sphereAContactNormal, sphereBContactNormal;
49 if (CollisionUtils::testSphereToSphere(
50 sphere0Pos, sphere0Radius, closestPt, capsule1Radius,
51 sphereAContactPt, sphereAContactNormal,
52 sphereBContactPt, sphereBContactNormal,
56 elemA.dir = sphereAContactNormal;
57 elemA.pt = sphereAContactPt;
58 elemA.penetrationDepth = depth;
61 elemB.dir = sphereBContactNormal;
62 elemB.pt = sphereBContactPt;
63 elemB.penetrationDepth = depth;
65 elementsA.push_back(elemA);
66 elementsB.push_back(elemB);
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.
Vec3d getPosition(DataType type=DataType::PostTransform)
Get the local or global position (post transformed)
Represents a sphere via its position & radius.
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.