[ODE] Springs with ODE

Tom De Muer tom.demuer at skynet.be
Tue Feb 24 08:28:08 MST 2004


>> see the >> :)

Hi all,

After lots of time playing arround with constraints, I couldnt understand
its conceptual properties. Someone on the graphics front suggested,
calculate the forces and apply them directly. So this is what I have done...

Vector3 calculateSpringForce ( Vector3 positionA, Vector3 positionB, float k
  float dDistance )
{
   Vector3 force;
   float intensity;

   Vector3 direction ( positionB.x - positionA.x,
                                    positionB.y - positionA.y,
                                    positionB.z - positionA.z ) ;
    Real distance = direction.length ();
    if ( distance < 0.0000000005f )
        return Vector3::ZERO;

    intensity = k * ( distance - dDistance );
    force = direction;
    force.normalise;
    force *= intensity;
    return force;
};

After that, on every simulation step (aka graphics frame in my app)

bool frameEnded(const FrameEvent& evt)
{
    Vector3 a = ball->getPosition ();
    Vector3 b = ball1->getPosition ();

    Vector3 force = calculateSpringForce ( a, b, 1, 40 );

    ball->addForce ( force );
    ball1->addForce ( -force );

>> doing this should be enough, no need to set the linear velocity yourself

>> try to get rid of this
    Vector3 velocity = ball->getLinearVelocity ();
    velocity *= 0.99;
    ball->setLinearVelocity (velocity);

    velocity = ball1->getLinearVelocity ();
    velocity *= 0.99;
    ball1->setLinearVelocity (velocity);
>> up till here and see if it gets any better

    // Call superclass
    bool ret = ExampleRefAppFrameListener::frameEnded(evt);
    return ret;
}

The latest part (setting linear velocity on each frame) was something I've
done because the simulation blowed away (welcome to simulated physics :D)...

So anyone have a better idea how to make that system to behave a little more
stable?

>> use dampers in your springs (they are linear term in the velocity of the
piston speed of your spring/damper)

Greetings
Federico Andres Lois

>> Cheers!
>> Tom


____________________________________________________
  IncrediMail - Email has finally evolved - Click Here



_______________________________________________
ODE mailing list
ODE at q12.org
http://q12.org/mailman/listinfo/ode



More information about the ODE mailing list