Sign in to follow this  

AABB Ray collision confusion

This topic is 2849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 2849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this