==============================================================================
| 60 | |
| 61 | //============================================================================== |
| 62 | void testBasicInterface(const std::shared_ptr<CollisionDetector>& cd) |
| 63 | { |
| 64 | if (cd->getType() != "bullet") { |
| 65 | dtwarn << "Aborting test: distance check is not supported by " |
| 66 | << cd->getType() << ".\n"; |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | auto simpleFrame1 = SimpleFrame::createShared(Frame::World()); |
| 71 | |
| 72 | auto shape1 = std::make_shared<SphereShape>(1.0); |
| 73 | simpleFrame1->setShape(shape1); |
| 74 | |
| 75 | auto group1 = cd->createCollisionGroup(simpleFrame1.get()); |
| 76 | |
| 77 | EXPECT_EQ(group1->getNumShapeFrames(), 1u); |
| 78 | |
| 79 | collision::RaycastOption option; |
| 80 | option.mEnableAllHits = false; |
| 81 | |
| 82 | collision::RaycastResult result; |
| 83 | EXPECT_FALSE(result.hasHit()); |
| 84 | |
| 85 | RayHit rayHit; |
| 86 | |
| 87 | result.clear(); |
| 88 | simpleFrame1->setTranslation(Eigen::Vector3d(5.0, 0.0, 0.0)); |
| 89 | cd->raycast( |
| 90 | group1.get(), |
| 91 | Eigen::Vector3d(-2, 0, 0), |
| 92 | Eigen::Vector3d(2, 0, 0), |
| 93 | option, |
| 94 | &result); |
| 95 | EXPECT_FALSE(result.hasHit()); |
| 96 | |
| 97 | result.clear(); |
| 98 | simpleFrame1->setTranslation(Eigen::Vector3d(0.0, 0.0, 0.0)); |
| 99 | cd->raycast( |
| 100 | group1.get(), |
| 101 | Eigen::Vector3d(-2, 0, 0), |
| 102 | Eigen::Vector3d(2, 0, 0), |
| 103 | option, |
| 104 | &result); |
| 105 | ASSERT_TRUE(result.hasHit()); |
| 106 | ASSERT_EQ(result.mRayHits.size(), 1u); |
| 107 | rayHit = result.mRayHits[0]; |
| 108 | EXPECT_TRUE(equals(rayHit.mPoint, Eigen::Vector3d(-1, 0, 0))); |
| 109 | EXPECT_TRUE(equals(rayHit.mNormal, Eigen::Vector3d(-1, 0, 0))); |
| 110 | EXPECT_DOUBLE_EQ(rayHit.mFraction, 0.25); |
| 111 | |
| 112 | result.clear(); |
| 113 | simpleFrame1->setTranslation(Eigen::Vector3d(0.0, 0.0, 0.0)); |
| 114 | simpleFrame1->setTranslation(Eigen::Vector3d(0.0, 0.0, 0.0)); |
| 115 | cd->raycast( |
| 116 | group1.get(), |
| 117 | Eigen::Vector3d(2, 0, 0), |
| 118 | Eigen::Vector3d(-2, 0, 0), |
| 119 | option, |
no test coverage detected