# What are some good resources on swept collision?

This topic is 3001 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've got working 2D circle/AABB/OBB collision, so the basics are down, there. The next step would seem to be swept collision. So, I'm looking for good resources on swept collision. I've already got swept sphere. Thanks.

##### Share on other sites
Try geometrictools.com (PDF articles and code). You could also check the TOCs online for Christer Ericson's and Gino van den Bergen's collision detection books and see if any swept tests are described therein.

Also, check the articles section here on GDNet - I'm pretty sure there are (or at least used to be) some articles there that covered some swept tests.

And, search the forum archives here for phrases such as 'swept sat', 'continuous sat', 'continuous collision', 'swept collision', 'swept circle', 'swept sphere', and so on; the topic is discussed fairly frequently, and you should be able to find some references, tutorials, and/or sample code if you look through some of the previous threads on the subject.

##### Share on other sites
Thanks; that all makes sense.

I found the swept sphere (Which I turned into swept circle, as I'm currently doing 2D) here, but a lot of the collision article links here are broken - For one, it appears gamasutra has updated its website in a way that breaks links. Just FYI.

##### Share on other sites
I'm trying to implement the "BoxBoxCollision" example here: http://www.gamedev.net/community/forums/topic.asp?topic_id=346956

But I'm not quite sure which data to give it. I've wrapped my code around like this:
        public static bool Intersection(RigidBody aR, AxisAlignedBoundingBox a, RigidBody bR, AxisAlignedBoundingBox b, double dt, out double t)        {            double tfirst = 0.0, tlast = 0.0;            bool check = BoxBoxCollision(                -a.HalfSize,                a.HalfSize,                -b.HalfSize,                b.HalfSize,                b.WorldPosition - a.WorldPosition,                ref tfirst, ref tlast            );            t = tfirst;            return check;        }

However, it never detects a collision.

##### Share on other sites
It looks like the first four arguments are supposed to be the 'min' and 'max' vectors of box A and B, respectively (note that these arguments are vectors, not scalars), and the fifth argument is supposed to the relative motion (displacement) vector for box B. (Box A is assumed to be stationary, which means that the input displacement vector should be box B's displacement vector minus box A's displacement vector.)

##### Share on other sites
That leaves out position, which I think would be rather critical. Also, it doesn't seem to work:
        public static bool Intersection(RigidBody aR, AxisAlignedBoundingBox a, RigidBody bR, AxisAlignedBoundingBox b, double dt, out double t)        {            double tfirst = 0.0, tlast = 0.0;            bool check = BoxBoxCollision(                a.WorldPosition - a.HalfSize,                a.WorldPosition + a.HalfSize,                b.WorldPosition - b.HalfSize,                b.WorldPosition + b.HalfSize,                // a.WorldPosition - b.WorldPosition,                (bR.PositionDifference - aR.PositionDifference),                ref tfirst, ref tlast            );            t = tfirst;            return check;        }

If I add their world positions to the HalfSize vectors as shown, it finds a collision, but way too early. If I don't, it doesn't find any collision.

Adding the world position of either body to the displacement doesn't help.

##### Share on other sites
Quote:
 That leaves out position
No it doesn't; the position is implicit in the 'min' and 'max' vectors. (Plus, you're referring to the position repeatedly when computing the first four arguments, so I'm not sure why you'd think it's being left out.)

As for why it's not working, I really couldn't say. Maybe one of your support functions is implemented incorrectly?

[Edit: Are you sure you're computing the PositionDifference values correctly?]

##### Share on other sites
Ah - I've tried it with and without adding world positions to various places.

However, it appears the real problem is the algorithm searches for collisions during the next second, returning the millisecond - And my physics simulation updates by seconds, updating every 0.040 seconds and interpolating otherwise.

Which means that I get a ms collision time of "216~", while my time step is 40 ms, measured as 0.040.

Correction: It does not cap at all, simply returning the next t of collision, if any. Which means the solution is simple; I just have to disregard anything over 40 ms. :) (Hopefully)

##### Share on other sites
Ok, the problem is that it measures in straight ms. My PositionDifference is measured per update (Full or interval). My full update is measured in 0.040 seconds.

...Now, to solve the outline...

...Odd. Very odd. tfirst increases as the two objects approach.

...Or not. This would work better if my brain didn't feel like milk right now.

[Edited by - Narf the Mouse on April 28, 2010 6:01:38 PM]

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631712
• Total Posts
3001849
×