Esempio n. 1
0
 public MyQuantizedBvhAllTrianglesResult()
 {
     ProcessTriangleHandler = new ProcessCollisionHandler(ProcessTriangle);
 }
        public bool RayQueryClosest(ref IndexedVector3 ray_dir, ref IndexedVector3 ray_origin, ProcessCollisionHandler handler)
        {
            int   curIndex = 0;
            int   numNodes = GetNodeCount();
            float distance = float.PositiveInfinity;

            while (curIndex < numNodes)
            {
                AABB bound;
                GetNodeBound(curIndex, out bound);

                //catch bugs in tree data

                float?aabbDist               = bound.CollideRayDistance(ref ray_origin, ref ray_dir);
                bool  isLeafNode             = IsLeafNode(curIndex);
                bool  aabbOverlapSignificant = aabbDist.HasValue && aabbDist.Value < distance;

                if (aabbOverlapSignificant && isLeafNode)
                {
                    foreach (var i in GetNodeData(curIndex))
                    {
                        float?newDist = handler(i);
                        if (newDist.HasValue && newDist.Value < distance)
                        {
                            distance = newDist.Value;
                        }
                    }
                }

                if (aabbOverlapSignificant || isLeafNode)
                {
                    //next subnode
                    curIndex++;
                }
                else
                {
                    //skip node
                    curIndex += GetEscapeNodeIndex(curIndex);
                }
            }
            return(distance != float.PositiveInfinity);
        }
        public bool RayQuery(ref IndexedVector3 ray_dir, ref IndexedVector3 ray_origin, ProcessCollisionHandler handler)
        {
            int  curIndex = 0;
            int  numNodes = GetNodeCount();
            bool res      = false;

            while (curIndex < numNodes)
            {
                AABB bound;
                GetNodeBound(curIndex, out bound);

                bool aabbOverlap = bound.CollideRay(ref ray_origin, ref ray_dir);
                bool isLeafNode  = IsLeafNode(curIndex);

                if (isLeafNode && aabbOverlap)
                {
                    foreach (var i in GetNodeData(curIndex))
                    {
                        handler(i);
                        res = true;
                    }
                }

                if (aabbOverlap || isLeafNode)
                {
                    //next subnode
                    curIndex++;
                }
                else
                {
                    //skip node
                    curIndex += GetEscapeNodeIndex(curIndex);
                }
            }

            return(res);
        }
 public MyQuantizedBvhResult()
 {
     ProcessTriangleHandler = new ProcessCollisionHandler(ProcessTriangle);
 }