示例#1
0
 /// <summary>
 /// Recursive method which casts a ray against 'node' and moves down the
 /// hierarchy towards the terminal nodes and stores any hits between the
 /// ray and these nodes inside 'hitList'.
 /// </summary>
 private void RaycastAllRecurse(Ray ray, SphereTreeNode <T> node, List <SphereTreeNodeRayHit <T> > hitList)
 {
     // Is this a terminal node?
     if (!node.IsFlagBitSet(BVHNodeFlags.Terminal))
     {
         // This is not a terminal node. We will check if the ray intersects the node's
         // sphere and if it does, we will go further down the hierarchy. If it doesn't
         // then there is no need to go on because if the ray does not intersect the node,
         // it can't possibly intersect any of its children.
         if (SphereMath.Raycast(ray, node.Center, node.Radius))
         {
             List <SphereTreeNode <T> > children = node.Children;
             foreach (var child in children)
             {
                 RaycastAllRecurse(ray, child, hitList);
             }
         }
     }
     else
     {
         // This is a terminal node and if the ray intersects this node, we will add the
         // node hit information inside the hit list.
         float t;
         if (SphereMath.Raycast(ray, out t, node.Center, node.Radius))
         {
             var nodeHit = new SphereTreeNodeRayHit <T>(ray, node, t);
             hitList.Add(nodeHit);
         }
     }
 }
示例#2
0
        public static bool Raycast(Ray ray, out float t, Vector3 startPoint, Vector3 endPoint, SegmentEpsilon epsilon = new SegmentEpsilon())
        {
            if (CylinderMath.Raycast(ray, out t, startPoint, endPoint, epsilon.RaycastEps))
            {
                return(true);
            }

            if (SphereMath.Raycast(ray, out t, startPoint, epsilon.RaycastEps))
            {
                return(true);
            }
            return(SphereMath.Raycast(ray, out t, endPoint, epsilon.RaycastEps));
        }
示例#3
0
        public bool RaycastAll(Ray ray, List <SphereTreeNodeRayHit <T> > hits)
        {
            hits.Clear();
            if (_root == null)
            {
                return(false);
            }

            float t;

            _root.StackPush(_root);
            while (_root.StackTop != null)
            {
                var node = _root.StackPop();
                if (!node.IsLeaf)
                {
                    if (SphereMath.Raycast(ray, node.Center, node.Radius))
                    {
                        if (SphereMath.Raycast(ray, node.Children[0].Center, node.Children[0].Radius))
                        {
                            _root.StackPush(node.Children[0]);
                        }
                        if (node.Children[1] != null && SphereMath.Raycast(ray, node.Children[1].Center, node.Children[1].Radius))
                        {
                            _root.StackPush(node.Children[1]);
                        }
                    }
                }
                else
                {
                    if (SphereMath.Raycast(ray, out t, node.Center, node.Radius))
                    {
                        hits.Add(new SphereTreeNodeRayHit <T>(ray, node, t));
                    }
                }
            }

            return(hits.Count != 0);
        }
示例#4
0
        public bool OverlapBox(OBB box, List <SphereTreeNode <T> > nodes)
        {
            nodes.Clear();
            if (_root == null)
            {
                return(false);
            }

            _root.StackPush(_root);
            while (_root.StackTop != null)
            {
                var node = _root.StackPop();
                if (!node.IsLeaf)
                {
                    if (SphereMath.ContainsPoint(box.GetClosestPoint(node.Center), node.Center, node.Radius))
                    {
                        if (SphereMath.ContainsPoint(box.GetClosestPoint(node.Children[0].Center), node.Children[0].Center, node.Children[0].Radius))
                        {
                            _root.StackPush(node.Children[0]);
                        }
                        if (node.Children[1] != null && SphereMath.ContainsPoint(box.GetClosestPoint(node.Children[1].Center), node.Children[1].Center, node.Children[1].Radius))
                        {
                            _root.StackPush(node.Children[1]);
                        }
                    }
                }
                else
                {
                    if (SphereMath.ContainsPoint(box.GetClosestPoint(node.Center), node.Center, node.Radius))
                    {
                        nodes.Add(node);
                    }
                }
            }

            return(nodes.Count != 0);
        }
 public bool ContainsPoint(Vector3 point)
 {
     return(SphereMath.ContainsPoint(point, _center, _radius, _epsilon));
 }
 public override bool Raycast(Ray ray, out float t)
 {
     return(SphereMath.Raycast(ray, out t, _center, _radius, _epsilon));
 }
示例#7
0
 public List <Vector3> GetRightUpExtents(Vector3 right, Vector3 up)
 {
     return(SphereMath.CalcRightUpExtents(_center, _radius, right, up));
 }