Hello,
After a year, i am returning to this thread, i am experiencing some problems :
First,
Erwin : the function btTransformUtil::calculateVelocity doesn't seems to work correctly, this is a simplified version of my code :
Code: Select all
Ogre::TransformKeyFrame *target_tkf = desired key frame;
btTransform tA = myRigidBody->getCenterOfMassTransform();
btTransform tB;
tB.setIdentity();
tB.setRotation(Util::toBtQuaternion(bone->convertLocalToWorldOrientation(target_tkf->getRotation())));
tB.setOrigin(Util::toBtVector3(bone->convertLocalToWorldPosition(target_tkf->getTranslate())));
btTypedConstraint* tc = a constraint that join two bodies like : head to spine joint;
switch(tc->getConstraintType())
{
case HINGE_CONSTRAINT_TYPE:
{
//printf("HINGEVelCalc\n");
btHingeConstraint* hc = static_cast<btHingeConstraint*>(tc);
btVector3 lvel, avel;
btTransformUtil::calculateVelocity(tA, tB, 1, lvel, avel);
btScalar force = avel[0]+avel[1]+avel[2];
hc->enableAngularMotor(true, force, 100.f);
} break;
case CONETWIST_CONSTRAINT_TYPE:
{
//printf("CONETWISTVelCalc\n");
btConeTwistConstraint* ctc = static_cast<btConeTwistConstraint*>(tc);
ctc->setAngularOnly(true);
ctc->enableMotor(true);
ctc->setMotorTarget(tB.getRotation());
ctc->setMaxMotorImpulse(100.f);
} break;
case SLIDER_CONSTRAINT_TYPE:
{
//printf("SLIDERVelCalc\n");
btSliderConstraint* sc = static_cast<btSliderConstraint*>(tc);
btVector3 lvel, avel;
btTransformUtil::calculateVelocity(tA, tB, 1, lvel, avel);
sc->setPoweredLinMotor(true);
sc->setPoweredAngMotor(true);
sc->setTargetLinMotorVelocity(lvel[0]+lvel[1]+lvel[2]);
sc->setTargetAngMotorVelocity(avel[0]+avel[1]+avel[2]);
sc->setMaxAngMotorForce(100.f);
sc->setMaxLinMotorForce(100.f);
} break;
case D6_CONSTRAINT_TYPE:
{
printf("Generic6DOFVelCalc\n");
btGeneric6DofConstraint* g6dofc = static_cast<btGeneric6DofConstraint*>(tc);
btVector3 lvel, avel;
btTransformUtil::calculateVelocity(tA, tB, 1, lvel, avel);
//avel *= 60.f;
// Seting rotational motors
for(int i=0; i<3; i++)
{
btRotationalLimitMotor* rotLim = g6dofc->getRotationalLimitMotor(i);
rotLim->m_enableMotor = true;
rotLim->m_maxLimitForce = 99999.9f;
rotLim->m_maxMotorForce = 200.f;
rotLim->m_targetVelocity = avel[i];
}
// -> some debugging outputs ...
}
The problem i think is that the returned angular velocity is not enought to push the body to the desired state in both of Hinge and Generic6DOF constraint that i tested, the ConeTwist doesn't seem to have this problem but it has some precision and stability problem.
This is some debugging output where "A" is the rigid body rotation, "B" is the desired rotation and "V" is the angular velocity returned by the btTransformUtil::calculateVelocity function :
Note : In my exemple i'm only interesting in the Y axis so don't look to the others
Code: Select all
Generic6DOFVelCalc
**********************************
A=-0.658356;0.249826;-0.044969
B=4.914749;5.597017;-0.479366
**********************************
V=5.546857;5.361677;-0.235211
**********************************
Generic6DOFVelCalc
**********************************
A=-2.001161;0.402409;-0.340210
B=5.020587;13.020824;-1.132568
**********************************
V=6.900428;12.642287;-0.456080
**********************************
Generic6DOFVelCalc
**********************************
A=-1.601413;0.613351;-0.272982
B=5.220694;20.442895;-1.826346
**********************************
V=6.468188;19.877541;-0.908424
**********************************
Generic6DOFVelCalc
**********************************
A=-1.156978;0.944907;-0.205564
B=5.533372;27.843014;-2.589738
**********************************
V=5.967929;26.975901;-1.302698
**********************************
Generic6DOFVelCalc
**********************************
A=-0.676906;1.394787;-0.138891
B=5.992235;35.238317;-3.465508
**********************************
V=5.411608;33.958683;-1.632781
**********************************
Generic6DOFVelCalc
**********************************
A=-0.168283;1.961058;-0.073862
B=6.213282;38.018173;-3.836001
**********************************
V=4.860001;36.193870;-1.689451
**********************************
Generic6DOFVelCalc
**********************************
A=0.363377;2.564585;-0.010980
B=6.467050;40.796783;-4.235722
**********************************
V=4.283088;38.393085;-1.716395
**********************************
Generic6DOFVelCalc
**********************************
A=0.301682;3.204421;0.080141
B=6.387526;39.966607;-4.112976
**********************************
V=4.303945;36.922231;-1.816571
**********************************
As you can see the rotation of the body(A) is so far from the desired rotation(B) and applying "38" of velocity just moves the rotation by 1°
Can anyone tell me what's wrong ?
Thanks.