Jump to content
Sign in to follow this  
theshizon

Axis-aligned bounding boxes with VEX- collision detection

Recommended Posts

Hi guys.  I found some code on this game dev site

function intersect(a, b) {
  return (a.minX <= b.maxX && a.maxX >= b.minX) &&
         (a.minY <= b.maxY && a.maxY >= b.minY) &&
         (a.minZ <= b.maxZ && a.maxZ >= b.minZ);
}

I need to recreate this in VEX for packed primitive bboxes.  It doesn't have to be this method. I just need a really fast efficient way to detect a collision between moving bounding boxes and returning a 0 or a 1.  Its in a scene thats going to be using the bboxes of a package containing many instances of trees, getting copied onto points on 2 colliding surfaces, hence the need to want to keep it packed for efficiency.  Not sure how to fit this into vex.  Any advice would be great

Cheers

Share this post


Link to post
Share on other sites

you can use the getbbox vex function.

Share this post


Link to post
Share on other sites

here is an example, and HIP file:

vector amin,amax;
getbbox(0,amin,amax);
vector bmin,bmax;
getbbox(1,bmin,bmax);

int intersect_(vector amin,amax,bmin,bmax) {
  return(amin.x <= bmax.x && amax.x >= bmin.x &&
         amin.y <= bmax.y && amax.y >= bmin.y &&
         amin.z <= bmax.z && amax.z >= bmin.z);
}
i@intersect_=intersect_(amin,amax,bmin,bmax);

intersect is a reserved VEX function name, so I used intersect_ instead

bunker_intersect_packed_001.hip

Edited by bunker

Share this post


Link to post
Share on other sites

Also, for object aligned boxes, I would generally loop over the objects, just use the Box SOP and then in VEX, do a intersect along the Normal (z), Up (y) vector and crossproduct(N, up) for the x axis, to get the scales.

Share this post


Link to post
Share on other sites

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  

×