[sldev] Linear motion interpolation weirdness?

John Hurliman jhurliman at wsu.edu
Mon Apr 9 00:09:31 PDT 2007


John Hurliman wrote:
> In llviewerobject.cpp starting around line 1997, the basic linear 
> motion interpolation for objects is done to calculate their position 
> in between the object update packets. The algorithm used is:
>
> LLVector3 <http://gza.props.org:8180/source/s?defs=LLVector3> pos 
> <http://gza.props.org:8180/source/s?defs=pos>     = (vel 
> <http://gza.props.org:8180/source/s?defs=vel> + (0.5f * (dt 
> <http://gza.props.org:8180/source/s?defs=dt>-HAVOK_TIMESTEP 
> <http://gza.props.org:8180/source/s?defs=HAVOK_TIMESTEP>)) * accel 
> <http://gza.props.org:8180/source/s?defs=accel>) * dt 
> <http://gza.props.org:8180/source/s?defs=dt>;
>
> But it it wrapped inside this check:
>
>
> *if* (!(accel 
> <http://gza.props.org:8180/source/s?defs=accel>.isExactlyZero 
> <http://gza.props.org:8180/source/s?defs=isExactlyZero>() && vel 
> <http://gza.props.org:8180/source/s?defs=vel>.isExactlyZero 
> <http://gza.props.org:8180/source/s?defs=isExactlyZero>()))
>
> So even though velocity is figured in to the equation, the calculation 
> will never be reached unless it is zero. Why is interpolation only 
> being done when (vel.isExactlyZero()), and if this is the correct 
> behavior why is velocity used in the algorithm?
>
> John Hurliman 

Wow thanks Thunderbird. Here's what that whole block of code looks like:

LLVector3 accel = getAcceleration();
LLVector3 vel     = getVelocity();

if (!(accel.isExactlyZero() && vel.isExactlyZero()))
{
    LLVector3 pos     = (vel + (0.5f * (dt-HAVOK_TIMESTEP)) * accel) * dt;

    // region local
    setPositionRegion(pos + getPositionRegion());
    setVelocity(vel + accel*dt);

    // for objects that are spinning but not translating, make sure to 
flag them as having moved
    setChanged(MOVED | SILHOUETTE);
}

With the curious part being where vel.isExactlyZero() is checked and 
then it is used in the equation on the next line.


More information about the SLDev mailing list