Timestep and erp

Post Reply
note173
Posts: 16
Joined: Wed Jan 25, 2012 6:32 pm

Timestep and erp

Post by note173 » Thu Feb 23, 2012 6:40 pm

A strange thing happens, when I change the fixedTimeStep (3rd parameter of stepSimulation) to some small value (1 / 400, for example). All spring constraints seem start to have more "strength". I adjust erp parameter:

Code: Select all

float physicsResolution = 1.0f / 60.0f / 10.0f;
float dt = timeSinceLastFrame;
...
dynamicsWorld->getSolverInfo ().m_erp = 0.2f / 10.0f;
priv->dynamicsWorld->stepSimulation (dt, 20, physicsResolution);
I think that the problem may be in the folowing lines of btGeneric6DofSpringConstraint.cpp:

Code: Select all

void btGeneric6DofSpringConstraint::internalUpdateSprings(btConstraintInfo2* info)
{
	// it is assumed that calculateTransforms() have been called before this call
	int i;
	btVector3 relVel = m_rbB.getLinearVelocity() - m_rbA.getLinearVelocity();
	for(i = 0; i < 3; i++)
	{
		if(m_springEnabled[i])
		{
			// get current position of constraint
			btScalar currPos = m_calculatedLinearDiff[i];
			// calculate difference
			btScalar delta = currPos - m_equilibriumPoint[i];
			// spring force is (delta * m_stiffness) according to Hooke's Law
			btScalar force = delta * m_springStiffness[i];
			btScalar velFactor = info->fps * m_springDamping[i] / btScalar(info->m_numIterations);
			m_linearLimits.m_targetVelocity[i] =  velFactor * force;
			m_linearLimits.m_maxMotorForce[i] =  btFabs(force) / info->fps;
		}
	}
	for(i = 0; i < 3; i++)
	{
		if(m_springEnabled[i + 3])
		{
			// get current position of constraint
			btScalar currPos = m_calculatedAxisAngleDiff[i];
			// calculate difference
			btScalar delta = currPos - m_equilibriumPoint[i+3];
			// spring force is (-delta * m_stiffness) according to Hooke's Law
			btScalar force = -delta * m_springStiffness[i+3];
			btScalar velFactor = info->fps * m_springDamping[i+3] / btScalar(info->m_numIterations);
			m_angularLimits[i].m_targetVelocity = velFactor * force;
			m_angularLimits[i].m_maxMotorForce = btFabs(force) / info->fps;
		}
	}
}
More specifically, I think it's related to wrong use of info->fps, but can't find the solution.
Is it correct, that when fps doubles, m_targetVelocity doubles too, and maxMotorForce halves?

kloplop321
Posts: 55
Joined: Sun Jan 01, 2012 7:37 pm

Re: Timestep and erp

Post by kloplop321 » Thu Feb 23, 2012 7:39 pm

Could you provide a recorded example showing the problem in action?
That and or plotted data showing the differences?

Post Reply