public void TestRayTwoBoxesWithTransformRotation() { // Insertion var tree = new NativeBVHTree(64, Allocator.Persistent); var transform = RigidTransform.identity; transform.rot = quaternion.Euler(45, 0, 0); var expectedIndex = tree.InsertLeaf(BoxCollider.Create(new float3(1, 2, 1), new float3(1, 1, 3)), transform: transform); tree.InsertLeaf(BoxCollider.Create(new float3(1, 2, 1), new float3(1, 1, 3))); //TODO rotation // Raycast var rayResult = new NativeList <int>(64, Allocator.Temp); var ray = new NativeBVHTree.Ray { origin = new float3(-1, 1, 0), direction = new float3(10, 0, 10), minDistance = 0, maxDistance = 20 }; tree.RaycastQuery(ray, rayResult); // Debug NativeBVHDebugDrawer.LastTree = tree; NativeBVHDebugDrawer.LastTreeHits = rayResult.ToArray(); NativeBVHDebugDrawer.LastRay = ray; // Assert Assert.AreEqual(1, rayResult.Length, "Expected only one hit"); Assert.AreEqual(expectedIndex, rayResult[0], "Expected first leaf to be hit"); }
public void TestRayTwoBoxes() { // Insertion var tree = new NativeBVHTree(64, Allocator.Persistent); tree.InsertLeaf(BoxCollider.Create(new float3(1, 1, 1), new float3(1, 1, 2))); tree.InsertLeaf(BoxCollider.Create(new float3(4, 4, 4), new float3(3, 3, 3))); // Raycast var rayResult = new NativeList <int>(64, Allocator.Temp); var ray = new NativeBVHTree.Ray { origin = new float3(-1, 1, 0), direction = new float3(10, 0, 10), minDistance = 0, maxDistance = 20 }; tree.RaycastQuery(ray, rayResult); // Debug NativeBVHDebugDrawer.LastTree = tree; NativeBVHDebugDrawer.LastTreeHits = rayResult.ToArray(); NativeBVHDebugDrawer.LastRay = ray; // Assert Assert.AreEqual(1, rayResult.Length, "Expected only one hit"); }