コード例 #1
0
        public RayMarchInfo March(Field field)
        {
            RayMarchInfo info = new RayMarchInfo {
                ray       = this.ray,
                distance  = float.PositiveInfinity,
                rayLength = 0.0f,
                raySteps  = 0
            };

            Vector3 rayPoint = ray.origin;

            while (info.raySteps < maxRaySteps && info.rayLength < maxRayLength)
            {
                info.raySteps++;

                float distance = field.distance(rayPoint);
                if (info.distance > distance)
                {
                    info.deepestPoint = rayPoint;
                }
                info.distance = Mathf.Min(distance, info.distance);

                float marchDistance = Mathf.Clamp(distance, minRayMarch, maxRayMarch);
                rayPoint       += marchDistance * ray.direction;
                info.rayLength += marchDistance;
            }

            info.deepestSurfacePoint = field.closestPoint(info.deepestPoint);

            return(info);
        }
コード例 #2
0
 public override float distanceToField(Field field)
 {
     rayMarch.ray.origin    = transform.position;
     rayMarch.ray.direction = transform.forward;
     rayMarchInfo           = rayMarch.March(field);
     return(rayMarchInfo.distance);
 }