Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 23 July 2012 - 02:28 PM
// I am assuming normal is a unit vector // although the overlap algorithm will still // work even if normal is not a unit vector double scalarProjection(point, normal) { // http://en.wikipedia.org/wiki/Vector_projection return point.dot(normal) / normal.dot(normal); } Range projectBox(box, normal) { Range result; // iterate over each corner in the box foreach (vertex in box.vertices) { double scalar = scalarProjection(vertex, normal); if first vertex { result.max = scalar; result.min = scalar; } else if (scalar > result.max) result.max = scalar; else if (scalar < result.min) result.min = scalar; } } bool doesCollide(boxa, boxb) { // create an array of vectors the represent the combined axis of the two boxes Array<Vector> boxaxislist; boxaxislist.append(boxa.axisList); boxaxislist.append(boxb.axisList); foreach (axis in boxaxislist) { Range boxaRange = projectBox(boxa, axis); Range boxbRange = projectBox(boxb, axis); if (!boxaRange.intersects(boxbRange)) { // there was no overlap, we found a plane that separates the two boxes. return false; } } // no plane was found, the boxes must be overlapping return true; }
Edited by HappyCoder, 23 July 2012 - 02:28 PM.
Posted 23 July 2012 - 04:17 PM
Posted 24 July 2012 - 09:52 AM
I don't know if I remember correctly but with 2 OBB don't you have to check 15 axis? 3 normals of the first box, 3 normals of the second box and all possibly cross products between the normals of the the two boxes? 3 + 3 + 3 * 3.
Maybe I'm overlooking something. You seem to have a good grasp of that stuff, maybe you can explain?
bool doesCollide(boxa, boxb){ // create an array of vectors the represent the combined axis of the two boxes Array<Vector> boxaxislist; foreach (axisa in boxa.axisList) { foreach (axisb in boxb.axisList) { boxaxislist.append(axisa.cross(axisb)); } } boxaxislist.append(boxa.axisList); boxaxislist.append(boxb.axisList); // rest of the doesCollide code....
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.