private static bool testOBBvsCircle(RectangleParticle ra, CircleParticle ca) { Vector collisionNormal = new Vector(); float collisionDepth = float.PositiveInfinity; float[] depths = new float[2]; // first go through the axes of the rectangle for (int i = 0; i < 2; i++) { Vector boxAxis = ra.axes[i]; float depth = testIntervals(ra.getProjection(boxAxis), ca.getProjection(boxAxis)); if (depth == 0) return false; if (Math.Abs(depth) < Math.Abs(collisionDepth)) { collisionNormal = boxAxis; collisionDepth = depth; } depths[i] = depth; } // determine if the circle's center is in a vertex region float r = ca.Radius; if (Math.Abs(depths[0]) < r && Math.Abs(depths[1]) < r) { Vector vertex = closestVertexOnOBB(ca.samp, ra); // get the distance from the closest vertex on rect to circle center collisionNormal = vertex - ca.samp; float mag = collisionNormal.magnitude(); collisionDepth = r - mag; if (collisionDepth > 0) { // there is a collision in one of the vertex regions collisionNormal /= mag; } else { // ra is in vertex region, but is not colliding return false; } } CollisionResolver.resolveParticleParticle(ra, ca, collisionNormal, collisionDepth); return true; }