| 8 | { |
| 9 | |
| 10 | TEST(MRMesh, MeshIntersect) |
| 11 | { |
| 12 | Mesh sphere = makeUVSphere( 1, 8, 8 ); |
| 13 | |
| 14 | std::vector<MeshIntersectionResult> allFound; |
| 15 | auto callback = [&allFound]( const MeshIntersectionResult & found ) -> bool |
| 16 | { |
| 17 | allFound.push_back( found ); |
| 18 | return true; |
| 19 | }; |
| 20 | |
| 21 | Vector3f d{ 1, 2, 3 }; |
| 22 | rayMeshIntersectAll( sphere, { 2.0f * d, -d.normalized() }, callback ); |
| 23 | ASSERT_EQ( allFound.size(), 2 ); |
| 24 | for ( const auto & found : allFound ) |
| 25 | { |
| 26 | ASSERT_NEAR( found.proj.point.length(), 1.0f, 0.05f ); //our sphere is very approximate |
| 27 | } |
| 28 | |
| 29 | const auto isect1 = rayMeshIntersect( sphere, { Vector3f{ +0.1f, 0.f, 0.f }, Vector3f::plusX() }, -FLT_MAX, +FLT_MAX ); |
| 30 | EXPECT_TRUE( isect1 ); |
| 31 | EXPECT_NEAR( isect1.distanceAlongLine, 0.9f, 0.05f ); |
| 32 | EXPECT_NEAR( isect1.proj.point.x, +1.f, 0.05f ); |
| 33 | |
| 34 | const auto isect2 = rayMeshIntersect( sphere, { Vector3f{ -0.1f, 0.f, 0.f }, Vector3f::plusX() }, -FLT_MAX, +FLT_MAX ); |
| 35 | EXPECT_TRUE( isect2 ); |
| 36 | EXPECT_NEAR( isect2.distanceAlongLine, -0.9f, 0.05f ); |
| 37 | EXPECT_NEAR( isect2.proj.point.x, -1.f, 0.05f ); |
| 38 | } |
| 39 | |
| 40 | } //namespace MR |
nothing calls this directly
no test coverage detected