Jump to content

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


Link to comment
Share on other sites

here is an example, and HIP file:

vector amin,amax;
vector 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);

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


Edited by bunker
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...