Sign in to follow this  
Narf the Mouse

Critique my theoretical procedure for swept box collision

Recommended Posts

I've never written my own swept collision procedure before and want to make sure I've got things down, first. So, tell me if, what and how this works/doesn't work.

Pseudo-code for a swept BoxBox collision check:
[code]
Box boxOnePos0 in boxOnePos0's reference frame
Box boxOnePos1 in boxOnePos0's reference frame
Box boxTwo
Rotate boxTwo into WorldFrame
Transform boxTwo into in boxOnePos0's reference frame

Rightmost edge of boxOnePos0 form face with Rightmost edge of boxTwoPos1
Leftmost edge of boxOnePos0 form face with Leftmost edge of boxTwoPos1
Topmost edge of boxOnePos0 form face with Topmost edge of boxTwoPos1
Bottommost edge of boxOnePos0 form face with Bottommost edge of boxTwoPos1
Result is boxOneSwept

for faceOne in boxOneSwept
axis is faceOne normal
for faceTwo in boxTwoSwept
projectTwo is faceTwo along axis
distanceTwo is distance between faceOne.Middle and faceTwo.Middle
if distanceTwo minus projectTwo is greater than zero, then return NoCollision
next
next
return Collision
[/code]

So, critique, comments, improvements, suggestions?

Thanks.

Share this post


Link to post
Share on other sites
Hi,

I assume you're doing OBB vs OBB not AABB vs AABB?

Have you written static OBB vs OBB before? I'm pretty sure you're missing a bunch of edge vs edge cases in there.... Swept OBB vs OBB is basically just ray-cast against the Minkowski Difference of both OBBs. The MD in 3d is formed of vertex vs face, face vs vertex and edge vs edge feature pairs (or axis as in SAT)...

Cheers, Paul.

Share this post


Link to post
Share on other sites
[quote name='wildbunny' timestamp='1317674892' post='4868699']
Hi,

I assume you're doing OBB vs OBB not AABB vs AABB?

Have you written static OBB vs OBB before? I'm pretty sure you're missing a bunch of edge vs edge cases in there.... Swept OBB vs OBB is basically just ray-cast against the Minkowski Difference of both OBBs. The MD in 3d is formed of vertex vs face, face vs vertex and edge vs edge feature pairs (or axis as in SAT)...

Cheers, Paul.
[/quote]
Yes, OOB. Yes, I've written static OBB vs OBB before.

My basic idea was, if the extent of a face (from its midpoint) in the direction of the other face's normal is greater than the distance between their midpoints, then they're colliding. Thinking it over again, it isn't accurate in the case where one face goes past, but does not collide with, the other.

Revised to be less clever:
[code]
Box boxOnePos0 in boxOnePos0's reference frame
Box boxOnePos1 in boxOnePos0's reference frame
Box boxTwo
Rotate boxTwo into WorldFrame
Transform boxTwo into in boxOnePos0's reference frame

Rightmost edge of boxOnePos0 form face with Rightmost edge of boxTwoPos1
Leftmost edge of boxOnePos0 form face with Leftmost edge of boxTwoPos1
Topmost edge of boxOnePos0 form face with Topmost edge of boxTwoPos1
Bottommost edge of boxOnePos0 form face with Bottommost edge of boxTwoPos1
Result is boxOneSwept

for faceOne in boxOneSwept
for vertexTwo in boxTwoSwept
projectTwo is vertexTwo in faceOne.ReferenceFrame
distance is projectTwo.Z - faceOne.Z
If distance is greater than zero, return NoCollision
next
next

Likewise faceTwo, vertexOne

for axisOne in boxOneSwept
for axisTwo in boxTwoSwept
referenceFrame is axisOne crossed with axisTwo
projectOne is edgeOne length along referenceFrame // edgeOne is axisOne along referenceFrame
projectTwo is edgeTwo length along referenceFrame // edgeTwo is axisTwo along referenceFrame
distance is (distance between boxOneSwept.Center and boxTwoSwept.Center) length along referenceFrame
if projectOne + projectTwo is less than distance, return NoCollision

return Collision
[/code]

Thanks.

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