Runtime/Bounds.cs
/// <summary>
/// Return enter position of ray in this bound.Ray need to start outside of bound!
/// <see cref="https://www.youtube.com/watch?v=4h-jlOBsndU"/>
/// </summary>
/// <param name="ray"></param>
/// <returns></returns>
Return enter position of ray in this bound.Ray need to start outside of bound!
Return enter position of ray in this bound . Ray need to start outside of bound!
public bool GetExitPosition(Ray ray, float length, out float3 exitPoint)
        {
            exitPoint = new float3();
            var minBounds = Min;
            var maxBounds = Max;
            var rayProjectionLength = ray.direction * length;
            var minProjection = (minBounds - (float3)ray.origin) / rayProjectionLength;
            var maxProjection = (maxBounds - (float3)ray.origin) / rayProjectionLength;
            var temp          = math.min(minProjection, maxProjection);
            maxProjection = math.max(minProjection, maxProjection);
            minProjection = temp;
            if (minProjection.x > maxProjection.y || minProjection.y > maxProjection.x)
                return false;
            var tMin = math.max(minProjection.x, minProjection.y); 
            var tMax = math.min(maxProjection.x, maxProjection.y); 
            if (tMin > maxProjection.z || minProjection.z > tMax)
                return false;
            tMax = math.min(maxProjection.z, tMax);
            exitPoint = ray.origin + ray.direction * length * tMax;
            return true;
        }
public bool GetExitPosition ( Ray ray , float length , out float3 exitPoint ) { exitPoint = new float3 ( ) ; var minBounds = Min ; var maxBounds = Max ; var rayProjectionLength = ray . direction * length ; var minProjection = ( minBounds - ( float3 ) ray . origin ) / rayProjectionLength ; var maxProjection = ( maxBounds - ( float3 ) ray . origin ) / rayProjectionLength ; var temp = math . min ( minProjection , maxProjection ) ; maxProjection = math . max ( minProjection , maxProjection ) ; minProjection = temp ; if ( minProjection . x > maxProjection . y || minProjection . y > maxProjection . x ) return false ; var tMin = math . max ( minProjection . x , minProjection . y ) ; var tMax = math . min ( maxProjection . x , maxProjection . y ) ; if ( tMin > maxProjection . z || minProjection . z > tMax ) return false ; tMax = math . min ( maxProjection . z , tMax ) ; exitPoint = ray . origin + ray . direction * length * tMax ; return true ; }
Return enter position of ray in this bound.Ray need to start outside of bound!
Return enter position of ray in this bound . Ray need to start outside of bound!
//Get Greatest Min //Get Smallest Max
None
ray
Ray
None
length
float
float3
out