How to set btFixedConstraint stiffness?

Post Reply
Slin
Posts: 3
Joined: Thu Jul 17, 2008 2:48 pm

How to set btFixedConstraint stiffness?

Post by Slin »

I am working on a small tennis VR game and am having a lot of problems getting the physics to behave correctly.
There is only one static triangle mesh shape and two dynamic rigid bodies in the simulation. The two bodies are the ball and the racket. Well and there is also a static body the racket is attached to with a btFixedConstraint. I am using 100 solver iterations and because the racket can move very fast and tends to just go through the ball, I am now at a step rate of 1/1440 (performance isn't really an issue at the moment, but it would still be great to be able to reduce this a bit...). I am currently using the Dantzig solver for somewhat better ball behavior, but also tried the SI one.

The problem is that when the ball is hit by the racket, it tends to get a much stronger impulse than it should, but not always.
A solution I found was setting m_globalCfm = 0.1 (on the solver info). The problem with this is that the ball doesn't behave correctly anymore when hitting the ground. It tends to just pass through (even though ccd is enabled) and doesn't bounce correctly.

It would be nice if the constraint stiffness could be controlled somehow, but I can't seem to find anything.
What I did try was: constraint->setParam(BT_CONSTRAINT_STOP_CFM, 0.1f, i) for all dofs, but it doesn't seem to make any difference.

Any ideas or solutions would be great ;)
Thanks!
Slin
Posts: 3
Joined: Thu Jul 17, 2008 2:48 pm

Re: How to set btFixedConstraint stiffness?

Post by Slin »

I switched to moving the racket directly by modifying its velocity every frame like this:

Code: Select all

RN::Vector3 speed = GetWorldPosition() - _racketBody->GetWorldPosition();
speed /= delta;
RN::Quaternion rotationSpeed = GetWorldRotation()*_racketBody->GetWorldRotation().GetConjugated();
RN::Vector4 axisAngleSpeed = rotationSpeed.GetAxisAngle();
if(axisAngleSpeed.w > 180.0f)
	axisAngleSpeed.w -= 360.0f;
RN::Vector3 angularVelocity(axisAngleSpeed.x, axisAngleSpeed.y, axisAngleSpeed.z);
angularVelocity *= axisAngleSpeed.w*M_PI;
angularVelocity /= 180.0f;
angularVelocity /= delta;

_racketBody->SetLinearVelocity(speed);
_racketBody->SetAngularVelocity(angularVelocity);
I am not entirely sure why this works, but it does solve the problem I had.
Post Reply