Пример #1
0
    public RayCastHit <T> BoundingPrimativeCast <T>(IBoundingShape myTestBox)
    {
        if (Root == null)
        {
            return(new RayCastHit <T>(new List <T>()));
        }
        List <T>          myResults      = new List <T>();
        Stack <IAABBNode> NodesToExplore = new Stack <IAABBNode>();
        IAABBNode         Current        = Root;

        if (Current.ContainsData())
        {
            if (Current.Bounds.Contains(myTestBox) != ContainmentType.Disjoint)
            {
                TryDataConvert <T>(myResults, Current);
            }
            return(new RayCastHit <T>(myResults));
        }
        while (Current != null)
        {
            ContainmentType left  = ContainmentType.Disjoint;
            ContainmentType right = ContainmentType.Disjoint;
            if (Current.Left != null)
            {
                left = myTestBox.Contains(Current.Left.Bounds);
            }
            if (Current.Right != null)
            {
                right = myTestBox.Contains(Current.Right.Bounds);
            }
            if (left == ContainmentType.Contains || left == ContainmentType.Intersects) //So it hit.
            {
                if (Current.Left.ContainsData())
                {
                    TryDataConvert <T>(myResults, Current.Left);
                }
                else
                {
                    NodesToExplore.Push(Current.Left);
                }
            }
            if (right == ContainmentType.Contains || right == ContainmentType.Intersects) //So it hit.
            {
                if (Current.Right.ContainsData())
                {
                    TryDataConvert <T>(myResults, Current.Right);
                }
                else
                {
                    NodesToExplore.Push(Current.Right);
                }
            }
            if (NodesToExplore.Count == 0)
            {
                break;
            }
            Current = NodesToExplore.Pop();
        }
        return(new RayCastHit <T>(myResults));
    }
Пример #2
0
    protected IAABBNode GetMinimalBranch(IBoundingShape areabounds)
    {
        if (Root == null)
        {
            return(null);
        }
        IAABBNode         CurrentMinimalObject = Root;
        Stack <IAABBNode> LastChecked          = new Stack <IAABBNode>();

        while (CurrentMinimalObject != null)
        {
            ContainmentType leftContainment  = ContainmentType.Disjoint;
            ContainmentType rightContainment = ContainmentType.Disjoint;
            if (CurrentMinimalObject.Left != null)
            {
                leftContainment = CurrentMinimalObject.Left.Bounds.Contains(areabounds);
            }
            if (CurrentMinimalObject.Right != null)
            {
                rightContainment = CurrentMinimalObject.Right.Bounds.Contains(areabounds);
            }
            else if (CurrentMinimalObject.Left == null)
            {
                break;
            }

            if (leftContainment == ContainmentType.Contains || (leftContainment == ContainmentType.Intersects && rightContainment == ContainmentType.Disjoint))
            {
                CurrentMinimalObject = CurrentMinimalObject.Left;
            }
            else if (rightContainment == ContainmentType.Contains || (rightContainment == ContainmentType.Intersects && leftContainment == ContainmentType.Disjoint))
            {
                CurrentMinimalObject = CurrentMinimalObject.Right;
            }
            else if (leftContainment == ContainmentType.Intersects && rightContainment == ContainmentType.Intersects)
            {
                break;
            }
            else
            {
                throw new Exception("Tree was left in unclean state.");
            }
        }
        return(CurrentMinimalObject);
    }
Пример #3
0
        public bool CollidesWith(IBoundingShape shape)
        {
            // TODO: przerobic
            if (shape.GetType() == typeof(BoundingBox))
            {
                BoundingBox bb = (BoundingBox)shape;

                if (bb.box.Left < box.Right && bb.box.Right > box.Left)
                {
                    if (bb.box.Top > box.Bottom)
                    {
                        return(false);
                    }

                    if (bb.box.Top > box.Top)
                    {
                        return(true);
                    }
                    else
                    {
                        int h = bb.box.Bottom - bb.box.Top;
                        if (bb.box.Top + h < box.Bottom && bb.box.Top > box.Top)
                        {
                            return(true);
                        }
                        else if (bb.box.Top + h > box.Bottom && bb.box.Top < box.Top)
                        {
                            return(true);
                        }
                    }

                    return(false);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                // TODO: idiom do dupy
                throw new NotImplementedException();
            }
        }
Пример #4
0
 public ContainmentType Contains(IBoundingShape myShape)
 {
     return(myShape.Contains(this));
 }