Esempio n. 1
0
        public bool DistanceToRay(Ray ray, HitResultPolygon result)
        {
            bool hit = false;

            if (DistanceToRayLocal(ray, result))
            {
                hit = true;
            }

            if (Childs.Length == 0)
            {
                return(hit);
            }

            var candicates = new List <(OctagonalNode obj, float start)>();

            foreach (var node in Childs)
            {
                if (node.AABB.CalculateTimeToIntersectWithRay(ray, out float start, out float end) && start < result.distance)
                {
                    if (end <= 0)
                    {
                        continue;
                    }

                    if (result.distance > start)
                    {
                        candicates.Add((node, start));
                    }
                }
            }

            foreach ((var node, float f) in candicates.OrderBy(o => o.start))
            {
                if (node.DistanceToRay(ray, result))
                {
                    hit = true;
                    break;
                }
            }
            return(hit);
        }
Esempio n. 2
0
        private bool DistanceToRayLocal(Ray ray, HitResultPolygon result)
        {
            bool hit = false;

            for (int i = 0; i < Polygons.Count; i++)
            {
                var   poly_temp = Polygons[i];
                float distance  = poly_temp.CalculateTimeToIntersectWithRay(ray);

                if (result.distance > distance && distance > 0.05 && poly_temp.BarycentricPos(ray, out Vector3 baryPos))
                {
                    hit = true;

                    result.poly           = poly_temp;
                    result.distance       = distance;
                    result.barycentricPos = baryPos;
                }
            }

            return(hit);
        }
Esempio n. 3
0
        public override bool DistanceToRay(Ray ray, HitResult result)
        {
            var resultPoly = new HitResultPolygon
            {
                distance = result.distance
            };

            if (OctagonalNode.DistanceToRay(Ray.Transform(ray, TransformInv), resultPoly))
            {
                result.distance = resultPoly.distance;
                result.normal   = resultPoly.poly.normal * TransformInv;
                result.uv       = resultPoly.poly.CalcUV(resultPoly.barycentricPos);
                result.material = Material;

                return(true);
            }
            else
            {
                return(false);
            }
        }