ccd motion clamping

sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

ccd motion clamping

Post by sparkprime »

m_ccdMotionThreshold is squared twice, once here

Code: Select all

    void    setCcdMotionThreshold(btScalar ccdMotionThreshold)
    {
        m_ccdMotionThreshold = ccdMotionThreshold*ccdMotionThreshold;
    }
and once here

Code: Select all

    btScalar    getCcdSquareMotionThreshold() const
    {
        return m_ccdMotionThreshold*m_ccdMotionThreshold;
    }
Changing the setter to just assign without squaring seems to work.



Also, why does btDiscreteDynamicsWorld::integrateTransforms have the following if block

Code: Select all

if (body->getCollisionShape()->isConvex()) {
    gNumClampedCcdMotions++;
    ...
}
It means I can't do ccd motion clamping with compound shapes. Commenting it out however, it seems to work. Are there cases where it doesn't work? I've only done some simple tests so far but I have to say this feature seems to work well.
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: ccd motion clamping

Post by sparkprime »

I've been using the swept sphere radius too, it seems for spheres, a good value is just less than the radius of the collision shape of the projectile. If you set it equal you can get some stacking and clustering of spheres which is very unrealistic. But just less than equal and it's fine.

For boxes none of this motion clamping stuff seems to work at all. If i'm understanding correctly, the motion clamping ensures that you get at least 1 collision detected, by limiting the distance moved so that the projectile will intersect whatever plane it is passing through. However I think that a single simulation step is not long enough to establish enough contacts to stop the penetration from proceeding in the subsequent steps?
Bbilz
Posts: 26
Joined: Wed Feb 27, 2008 9:55 am

Re: ccd motion clamping

Post by Bbilz »

The way I understood it, it detects if an object has moved further this frame than the threshold value. If it has, then it sweeps a sphere test over the distance it is planning on moving. If it detects a collision it just sets the integration to whatever fraction matches where the collision was detected.

The problem I have had with this, is that it doesn't modify the velocity in any way, so the next frame it is travelling just as fast and activates the CCD again. This gives the result of it just getting stuck permenantly on the surface it collided with..

I kind of hacked in a btTransformUtil::calculateVelocity to update the velocity using the current world transform and the newly clamped one, but I see artifacts with this - I think there's got to be friction stuff and some kind of consideration of the collision normal..

So yeah!
Just passing on my experiences with the CCD :)
Would love to get the problems ironed out though, its so incredibly useful to have certain objects guaranteed not pass through anything in the game I am doing
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: ccd motion clamping

Post by sparkprime »

I had the getting stuck problem but it's solved by using a smaller swept sphere radius, that way the object is not cut short unless it is penetrating something, which means the solver will kick it back in the opposite direction with equal+opposite momentum.

The problem I found with boxes was that even though they were penetrating, there was no collision registered, and I assumed this was because only 1 contact is generated per frame and one contact was not enough to stop a box tunneling at high speed (whereas 1 contact is enough for a sphere).