Constant velocity?

Pby
Posts: 2
Joined: Sun Apr 04, 2010 2:54 pm

Constant velocity?

Post by Pby »

Hello

I am having difficulty to simulating objects with constant velocity.

* a btDiscreteDynamicsWorld (gravity = 0);
* a room with 6 btBoxShape (mass = 0; restitution = 1; damping = 0);
* a btBoxShape (also tested with btSphereShape) (which must be at constant speed) (dimensions = 1x1x1; mass = 1; inertia calculated with calculateLocalInertia(); linear velocity = btVector3(0,-30,0); restitution = 1; damping = 0);

Until the object collides with any wall, the velocity is constant (30), but then, depending of the object rotation at the time of the collision, the speed increases (when the rotation is equal to the wall) or decreases... sometimes continues constant, but at some point (collision) destabilizes.

What is the problem? how can I ensure constant velocity?
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Constant velocity?

Post by Flix »

Pby wrote:Until the object collides with any wall, the velocity is constant (30), but then, depending of the object rotation at the time of the collision, the speed increases (when the rotation is equal to the wall) or decreases... sometimes continues constant, but at some point (collision) destabilizes.

What is the problem? how can I ensure constant velocity?
Mmmh, it might depend on the frictions you have assigned to the static and dynamic bodies that collide (you can use the setFriction(...) method to change it). I would try to set the friction and restitution to zero and see what happens.
Pby wrote:how can I ensure constant velocity?
You can set the module of the velocity at each internal timestep (you can use "pre" or "post" step callbacks for it, see the wiki: try both of them and see).
Basically something like:

Code: Select all

btRigidBody* myBody; // valid body

//At each timestep:
myBody->setLinearVelocity(myBody->getLinearVelocity().getNormalizedCopy()*30);
// Please replace getNormalizedCopy() with the appropriate method...
Hope it helps.