[ODE] Stepfast - auto-disable stuff

Aras Pranckevicius nearaz at interamotion.com
Mon Jul 14 04:13:02 2003


> the documentation defines a number of other functions that are not
> actually implemented in the source:
>   dBodySetAutoDisableThresholdSF1
>   dBodyGetAutoDisableThresholdSF1
>   ...

These weren't implemented in the stepfast source. I've implemented these for
my LTGameJam - that required some small modifications to ODE core.

You can either try to grab the source from http://jammy.sourceforge.net/2003
("dingus.zip", dingus/lib/ode, look for "Araz" comment :)), or I can explain
it in basic steps here:

Changes to ODE internal files (hm, my naming convention differs from ODE's
:)):
objects.h:
    add to struct dxBody:
        int mDisableSteps; // auto-disable counter
    add to struct dxWorld:
        dReal mAutoDisableThreshold;
        int mAutoDisableSteps;
ode.cpp:
    add to dBodyCreate(dxWorld* w):
        b->mDisableSteps = 0;
    add to dWorldCreate():
        w->mAutoDisableSteps = 10;
        w->mAutoDisableThreshold = REAL(0.008);
    add functions like (add their prototypes to public objects.h):
        void dWorldSetAutoDisableSteps( dWorldID w, int steps )
       {
           dAASSERT(w);
           w->mAutoDisableSteps = steps;
       }
       void dWorldSetAutoDisableThreshold( dWorldID w, dReal threshold )
       {
           dAASSERT(w);
           w->mAutoDisableThreshold = threshold;
       }
stepfast.cpp (actually one needs to add this to "normal" ODE's solver also):
    insert approx at line 1016, at start of loop for( bb=world->firstbody;
... ):
        // ---- code begin ------------------------
        if( !(bb->flags&dxBodyDisabled) ) {
            bool disable = true;
            const dReal *lvel = bb->lvel;;
            dReal lspeed = dDOT(lvel,lvel);
            if( lspeed > world->mAutoDisableThreshold ) {
               disable = false;
            } else {
                const dReal *avel = bb->avel;
                dReal aspeed = dDOT(avel,avel);
                if( aspeed > world->mAutoDisableThreshold ) {
                    disable = false;
                }
            }
            if( disable )
                ++bb->mDisableSteps;
            else
                bb->mDisableSteps = 0;
            if( bb->mDisableSteps > world->mAutoDisableSteps ) {
                bb->flags |= dxBodyDisabled;
            }
        }

        // ---- code end ------------------------
    add approx. at line 1080 (with above code included), in "traverse and
tag all body's joints, add untagged..." code:
       n->body->flags &= ~dxBodyDisabled; // this line exists
       n->body->mDisableSteps = 0; // add this line
       n->body->tag = 1; // this exists

Basically, that's all :)


Aras Pranckevicius aka NeARAZ
http://www.gim.ktu.lt/nesnausk/nearaz/