CCD: how it works exactly ?

Post Reply
petitg1987
Posts: 4
Joined: Tue Oct 18, 2016 9:59 am

CCD: how it works exactly ?

Post by petitg1987 »

Hello,

I try to understand how work the continuous collision detection.
I have identified two main methods:

- btDiscreteDynamicsWorld::integrateTransforms(): this method seems to update the body transform in such way to not go through the others bodies. It also update the linear velocity to max speed authorized by "ccdMotionThreshold" properties.
- btDiscreteDynamicsWorld::createPredictiveContacts(): this method seems create contact point for bodies when CCD is required in order to be solved later by constraint solver.

My question: why the first method is not sufficient for CCD ? Once the velocity reduced: why the classical way to create the contact point is not sufficient and createPredictiveContacts() method is required ?

Thank you in advance.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: CCD: how it works exactly ?

Post by drleviathan »

I think both of the methods you identified are used in the normal (non-CCD) simulation path. Enabling CCD is done on a per-body basis: you set the sphere of the sweep proxy and a speed threshold where CCD kicks in. The sweep test is done with the proxy sphere because it is computationally cheaper than sweeping the real geometry. The sweep results are used to place the real body where it most likely first collides with other geometry (if any). Once the body is placed the two methods you identified are called as normal.
petitg1987
Posts: 4
Joined: Tue Oct 18, 2016 9:59 am

Re: CCD: how it works exactly ?

Post by petitg1987 »

Thanks drleviathan.
Indeed, the methods are also used in normal simulation path but 90% of source code seems executed only for CCD, no ?
See 'if': "if (getDispatchInfo().m_useContinuous && body->getCcdSquareMotionThreshold() && body->getCcdSquareMotionThreshold() < squareMotion)" which use properties at body level.
In these methods, we also see the usage of the sweep sphere defined on bodies.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: CCD: how it works exactly ?

Post by drleviathan »

Ah, I see I did not read your original question carefully enough.

After looking at the code...

The predicted transform is the where the object would be after a full step -- if it suffered zero collisions. When there is no CCD happening that is where the object ends up before collisions and penetrations are solved. After resolving contacts the final transform is known.

The CCD code checks to see if the the predicted transform happened to pass completely through some collision surface. If so, then the predicted transform is modified before it is passed to the contact/penetration resolution code.
petitg1987
Posts: 4
Joined: Tue Oct 18, 2016 9:59 am

Re: CCD: how it works exactly ?

Post by petitg1987 »

Thanks again drleviathan.
What you describe is exactly what I describe for method "btDiscreteDynamicsWorld::integrateTransforms()" in my first post, no ? This method modify the predict transform in case of CCD to avoid collision.

So my question: what is the utility of btDiscreteDynamicsWorld::createPredictiveContacts() method ?
petitg1987
Posts: 4
Joined: Tue Oct 18, 2016 9:59 am

Re: CCD: how it works exactly ?

Post by petitg1987 »

Finally, I think I understand why it's necessary to have both methods.

Here what I understand of a simulation step:
1) btDiscreteDynamicsWorld::createPredictiveContacts(): this method create predictive contact points (when CCD required) for bodies based on current bodies linear velocities.
2) The solver will solve the constraints and so update the bodies linear velocities.
3) btDiscreteDynamicsWorld::integrateTransforms(): here, we will apply linear velocity on body transform. We are sure that a body won't go through the bodies detected in step 1. But as the linear velocity has changed in step 2, the body could go through another body not detected at step 1. This is why we also handle CCD in this method.

I think, the best example is when a ball bounce quickly between two close walls. The step 1 will create predictive contact points for wall 1. The solver will update the linear velocity to go toward wall 2. The step 3 will ensure that ball won't go through wall 2.

Is that fair?
Post Reply