==============================================================================
| 564 | |
| 565 | //============================================================================== |
| 566 | void testBoxBox( |
| 567 | const std::shared_ptr<CollisionDetector>& cd, double tol = 1e-12) |
| 568 | { |
| 569 | auto simpleFrame1 = SimpleFrame::createShared(Frame::World()); |
| 570 | auto simpleFrame2 = SimpleFrame::createShared(Frame::World()); |
| 571 | |
| 572 | ShapePtr shape1(new BoxShape(Eigen::Vector3d(1.0, 1.0, 1.0))); |
| 573 | ShapePtr shape2(new BoxShape(Eigen::Vector3d(0.5, 0.5, 0.5))); |
| 574 | simpleFrame1->setShape(shape1); |
| 575 | simpleFrame2->setShape(shape2); |
| 576 | |
| 577 | Eigen::Vector3d pos1 = Eigen::Vector3d(0.0, 0.0, -0.5); |
| 578 | Eigen::Vector3d pos2 = Eigen::Vector3d(0.0, 0.5, 0.25); |
| 579 | simpleFrame1->setTranslation(pos1); |
| 580 | simpleFrame2->setTranslation(pos2); |
| 581 | |
| 582 | auto group1 = cd->createCollisionGroup(simpleFrame1.get()); |
| 583 | auto group2 = cd->createCollisionGroup(simpleFrame2.get()); |
| 584 | auto groupAll = cd->createCollisionGroup(group1.get(), group2.get()); |
| 585 | |
| 586 | EXPECT_EQ(group1->getNumShapeFrames(), 1u); |
| 587 | EXPECT_EQ(group2->getNumShapeFrames(), 1u); |
| 588 | EXPECT_EQ( |
| 589 | groupAll->getNumShapeFrames(), |
| 590 | group1->getNumShapeFrames() + group2->getNumShapeFrames()); |
| 591 | |
| 592 | collision::CollisionOption option; |
| 593 | collision::CollisionResult result; |
| 594 | |
| 595 | result.clear(); |
| 596 | EXPECT_TRUE(group1->collide(group2.get(), option, &result)); |
| 597 | |
| 598 | result.clear(); |
| 599 | EXPECT_TRUE(groupAll->collide(option, &result)); |
| 600 | |
| 601 | Eigen::Vector3d min = Eigen::Vector3d(-0.25, 0.25, 0.0); |
| 602 | Eigen::Vector3d max = Eigen::Vector3d(0.25, 0.5, 0.0); |
| 603 | |
| 604 | const auto numContacts = result.getNumContacts(); |
| 605 | |
| 606 | const auto checkNumContacts = (numContacts <= 4u); |
| 607 | EXPECT_TRUE(checkNumContacts); |
| 608 | if (!checkNumContacts) |
| 609 | std::cout << "# of contants: " << numContacts << "\n"; |
| 610 | |
| 611 | for (const auto& contact : result.getContacts()) { |
| 612 | const auto& point = contact.point; |
| 613 | |
| 614 | const auto result = checkBoundingBox(min, max, point, tol); |
| 615 | EXPECT_TRUE(result); |
| 616 | |
| 617 | if (!result) |
| 618 | std::cout << "point: " << point.transpose() << "\n"; |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | //============================================================================== |
| 623 | TEST_F(Collision, BoxBox) |
no test coverage detected