// Determine whether this box contains, intersects, or is disjoint from // the given frustum. public ContainmentType Contains(BoundingFrustumD frustum) { // Convert this bounding box to an equivalent BoundingFrustum, so we can rely on BoundingFrustum's // implementation. Note that this is very slow, since BoundingFrustum builds various data structures // for this test that it caches internally. To speed it up, you could convert the box to a frustum // just once and re-use that frustum for repeated tests. BoundingFrustumD temp = ConvertToFrustum(); return(temp.Contains(frustum)); }
// Determine whether the given frustum contains, intersects, or is disjoint from // the given oriented box. public static ContainmentType Contains(BoundingFrustumD frustum, ref MyOrientedBoundingBoxD obox) { return(frustum.Contains(obox.ConvertToFrustum())); }
public void OverlapAllFrustum <T>(ref BoundingFrustumD frustum, List <T> elementsList, List <bool> isInsideList, Vector3 projectionDir, float projectionFactor, float ignoreThr, uint requiredFlags, bool clear = true) { if (clear) { elementsList.Clear(); isInsideList.Clear(); } if (_root == NullNode) { return; } using (m_rwLock.AcquireSharedUsing()) { Stack <int> stack = GetStack(); stack.Push(_root); //BoundingBox bbox = BoundingBoxHelper.InitialBox; //BoundingBoxHelper.AddFrustum(ref frustum, ref bbox); while (stack.Count > 0) { int nodeId = stack.Pop(); if (nodeId == NullNode) { continue; } DynamicTreeNode node = _nodes[nodeId]; //if (node.Aabb.Intersects(bbox)) { ContainmentType result; frustum.Contains(ref node.Aabb, out result); if (result == ContainmentType.Contains) { int baseCount = stack.Count; stack.Push(nodeId); while (stack.Count > baseCount) { int nodeIdToAdd = stack.Pop(); DynamicTreeNode nodeToAdd = _nodes[nodeIdToAdd]; if (nodeToAdd.IsLeaf()) { if (nodeToAdd.Aabb.ProjectedArea(projectionDir) * projectionFactor > ignoreThr) { uint flags = GetUserFlag(nodeIdToAdd); if ((flags & requiredFlags) == requiredFlags) { elementsList.Add(GetUserData <T>(nodeIdToAdd)); isInsideList.Add(true); } } } else { if (nodeToAdd.Child1 != NullNode) { stack.Push(nodeToAdd.Child1); } if (nodeToAdd.Child2 != NullNode) { stack.Push(nodeToAdd.Child2); } } } } else if (result == ContainmentType.Intersects) { if (node.IsLeaf()) { if (node.Aabb.ProjectedArea(projectionDir) * projectionFactor > ignoreThr) { uint flags = GetUserFlag(nodeId); if ((flags & requiredFlags) == requiredFlags) { elementsList.Add(GetUserData <T>(nodeId)); isInsideList.Add(false); } } } else { stack.Push(node.Child1); stack.Push(node.Child2); } } } } PushStack(stack); } }
public void OverlapAllFrustumAny <T>(ref BoundingFrustumD frustum, List <T> elementsList, bool clear = true) { if (clear) { elementsList.Clear(); } if (_root == NullNode) { return; } using (m_rwLock.AcquireSharedUsing()) { Stack <int> stack = GetStack(); stack.Push(_root); //BoundingBox bbox = BoundingBoxHelper.InitialBox; //BoundingBoxHelper.AddFrustum(ref frustum, ref bbox); while (stack.Count > 0) { int nodeId = stack.Pop(); if (nodeId == NullNode) { continue; } DynamicTreeNode node = _nodes[nodeId]; //if (node.Aabb.Intersects(bbox)) { ContainmentType result; frustum.Contains(ref node.Aabb, out result); if (result == ContainmentType.Contains) { int baseCount = stack.Count; stack.Push(nodeId); while (stack.Count > baseCount) { int nodeIdToAdd = stack.Pop(); DynamicTreeNode nodeToAdd = _nodes[nodeIdToAdd]; if (nodeToAdd.IsLeaf()) { T el = GetUserData <T>(nodeIdToAdd); elementsList.Add((T)el); } else { if (nodeToAdd.Child1 != NullNode) { stack.Push(nodeToAdd.Child1); } if (nodeToAdd.Child2 != NullNode) { stack.Push(nodeToAdd.Child2); } } } } else if (result == ContainmentType.Intersects) { if (node.IsLeaf()) { T el = GetUserData <T>(nodeId); elementsList.Add((T)el); } else { stack.Push(node.Child1); stack.Push(node.Child2); } } } } PushStack(stack); } }
// Checks if specified bounding box is in actual bounding frustum // IMPORTANT: If you observe bad result of this test, check how you transform your bounding box. // Don't use BoundingBox.Transform. Instead transform box manualy and then create new box. public bool IsInFrustum(ref BoundingBoxD boundingBox) { VRageMath.ContainmentType result; BoundingFrustum.Contains(ref boundingBox, out result); return(result != VRageMath.ContainmentType.Disjoint); }