[SOLVED] Slider constraint attached to world have limit?

User avatar
emersonmx
Posts: 9
Joined: Mon Sep 09, 2013 2:06 pm

[SOLVED] Slider constraint attached to world have limit?

Post by emersonmx »

I'm playing with slider constraint and I found something strange.

I create a slider contraint attached to world

Code: Select all

btTransform 
axis.setIdentity();
axis.setRotation(btQuaternion(0, 0, 1, 1));

btSliderConstraint* constraint =
    new btSliderConstraint(*rigid_body, axis, true);
constraint->setLowerLinLimit(-200);
constraint->setUpperLinLimit(200);
dynamic_world_->addConstraint(constraint, true);
The rigidbox have a box collision shape (btBoxShape) and have this configuration

Code: Select all

rigid_body->setLinearFactor(btVector3(0, 1, 0));
rigid_body->setAngularFactor(btVector3(0, 0, 0));
rigid_body->setDamping(0.999f, 1);
rigid_body->setActivationState(DISABLE_DEACTIVATION);
The rigidbody is moved with UP and DOWN keys. Like

Code: Select all

btScalar velocity = 250;
if (keyboard->isKeyDown(OIS::KC_UP)) {
    btVector3 position(0, velocity, 0);
    rigid_body->setLinearVelocity(position);
} else if (keyboard->isKeyDown(OIS::KC_DOWN)) {
    btVector3 position(0, -velocity, 0);
    rigid_body->setLinearVelocity(position);
}
And to hold the DOWN key, the rigidbody reaches the limit of the constraint(=-200).
If the key remains pressed, the rigidbody will exceed the limit of the constraint(>-200) and
after a while will go back to the limit of the constraint(=-200).

This does not occur if the limit is set to

Code: Select all

constraint->setLowerLinLimit(-100);
constraint->setUpperLinLimit(100);
I really can not explain why this occurs.
Does anyone have any idea why this happens?
Last edited by emersonmx on Thu Sep 19, 2013 12:53 am, edited 1 time in total.
User avatar
emersonmx
Posts: 9
Joined: Mon Sep 09, 2013 2:06 pm

Re: Slider constraint attached to world have limit?

Post by emersonmx »

Somehow, I managed to solve (luck) this by reducing the value of fixedTimeStep to 1 / 256.f :?

Code: Select all

dynamic_world_->stepSimulation(clock_->time() / 1000.f, 10, 1 / 256.f);
I assume from now on, when I have trouble, I'll increase the value of fixedTimeStep and see what happens. :mrgreen:
Rikus
Posts: 4
Joined: Sat Sep 14, 2013 7:40 am

Re: [SOLVED] Slider constraint attached to world have limit?

Post by Rikus »

Hey,
Here is all the information you need regarding timeStep: http://www.bulletphysics.org/mediawiki- ... _The_World
What you just did (I think) is set the maxSubSteps to "0" (1/256.f)

By that you are setting to use a variable tick rate (it will use delta time for simulating the physics).

As the wiki says:
maxSubSteps == 0 ?
If you pass maxSubSteps=0 to the function, then it will assume a variable tick rate. Every tick, it will move the simulation along by exactly the timeStep you pass, in a single tick, instead of a number of ticks equal to fixedTimeStep.
This is not officially supported, and the death of determinism and framerate independence. Don't do it.
User avatar
emersonmx
Posts: 9
Joined: Mon Sep 09, 2013 2:06 pm

Re: [SOLVED] Slider constraint attached to world have limit?

Post by emersonmx »

Rikus wrote:Hey,
Here is all the information you need regarding timeStep: http://www.bulletphysics.org/mediawiki- ... _The_World
What you just did (I think) is set the maxSubSteps to "0" (1/256.f)

By that you are setting to use a variable tick rate (it will use delta time for simulating the physics).

As the wiki says:
maxSubSteps == 0 ?
If you pass maxSubSteps=0 to the function, then it will assume a variable tick rate. Every tick, it will move the simulation along by exactly the timeStep you pass, in a single tick, instead of a number of ticks equal to fixedTimeStep.
This is not officially supported, and the death of determinism and framerate independence. Don't do it.
I use maxSubSteps = 10 and not maxSubSteps = 0
The real problem with decreasing the size of fixedTimeStep is the CPU usage (In my simulation I am using 1% :lol: ).