AABB Ray collision confusion

Started by
1 comment, last by oliii 14 years, 2 months ago
So I've been looking around for a good ray - box collision detection methood and I recently found one. http://www.cs.utah.edu/~awilliam/box/ (the pdf) I was looking at the function, which looks something like this I'm just confused on what to pass as an argument for t0 and t1. The paper called those arguments "valid intersection intervals"



bool Box::intersect(const Ray &r, float t0, float t1) const {
  float tmin, tmax, tymin, tymax, tzmin, tzmax;

  tmin = (parameters[r.sign[0]].x() - r.origin.x()) * r.inv_direction.x();
  tmax = (parameters[1-r.sign[0]].x() - r.origin.x()) * r.inv_direction.x();
  tymin = (parameters[r.sign[1]].y() - r.origin.y()) * r.inv_direction.y();
  tymax = (parameters[1-r.sign[1]].y() - r.origin.y()) * r.inv_direction.y();
  if ( (tmin > tymax) || (tymin > tmax) ) 
    return false;
  if (tymin > tmin)
    tmin = tymin;
  if (tymax < tmax)
    tmax = tymax;
  tzmin = (parameters[r.sign[2]].z() - r.origin.z()) * r.inv_direction.z();
  tzmax = (parameters[1-r.sign[2]].z() - r.origin.z()) * r.inv_direction.z();
  if ( (tmin > tzmax) || (tzmin > tmax) ) 
    return false;
  if (tzmin > tmin)
    tmin = tzmin;
  if (tzmax < tmax)
    tmax = tzmax;
  return ( (tmin < t1) && (tmax > t0) );
}


Can someone explain to me what to pass as t0 and t1? Thanks
Advertisement
It looks like those values are a needless complication. tMin and tMax are the values you're interested in returning. They should be stored in output parameters.

Any "t" values represents the "time" along the ray, this represents the distance along the ray to some point.

P(t) = rayOrigin + rayDirection * t;

When the ray passes through a box shape there will be two points it intersects. These points will be stored as t values as tmin (the face it first hits/enters) and tmax (the second face where it exits).

If the ray intersected an edge, tmin and tmax should equal each other.

To make the result a boolean, they allowed you to pass in a "valid interval" for tmin and tmax to be compared to.

If a time values is less than zero, it lies before the start of the ray, in the negative rayDirection. If the time value is greater than 1, it lies after the end of rayDirection

Last but not least, if rayDirection is of unit length then time is equivalent to distance.
usually, t0 is set to '0', and t1, to the ray 'length'.

Everything is better with Metal.

This topic is closed to new replies.

Advertisement