Shifting Dynamic-Kinematic: Objects no longer move.

Korut
Posts: 5
Joined: Sun Aug 03, 2008 12:12 am

Shifting Dynamic-Kinematic: Objects no longer move.

Post by Korut »

Hi everyone.

I'm working in some simulations with ragdolls. Everything goes fine, but currently, I want to be able to put some bones as kinematics, so they do follow an animation, and some others as rigid bodies, so they behave as the physics says. It is, for example, to leave a "dumb" limb.

I can do this part well, but when I shift the kinematic objects back to dinamics, to use the full ragdoll, they no longer move correctly, like if they were not computing at all the angular velocity. I am using 2.75 Beta.

Here is an example of my code:

Code: Select all

	for ( unsigned i = 0; i < rigid_bodies.size(); ++i ) {
		if ( set_kynematic ) { // Change body properties to kynematic mode
			if ( core->bones[ i ].kinematic ) {
				rigid_bodies[ i ]->setCollisionFlags( rigid_bodies[ i ]->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
				rigid_bodies[ i ]->setMassProps( 0.0f, btVector3( 0.0f, 0.0f, 0.0f ) );
				rigid_bodies[ i ]->updateInertiaTensor();
				rigid_bodies[ i ]->setInterpolationWorldTransform(rigid_bodies[ i ]->getWorldTransform());
				rigid_bodies[ i ]->setInterpolationLinearVelocity(btVector3(0,0,0));
				rigid_bodies[ i ]->setInterpolationAngularVelocity(btVector3(0,0,0));
			}
			rigid_bodies[ i ]->setActivationState(DISABLE_DEACTIVATION);
		}
		else {
			rigid_bodies[ i ]->setActivationState(WANTS_DEACTIVATION);
			if ( core->bones[ i ].kinematic ) {
				rigid_bodies[ i ]->setCollisionFlags( rigid_bodies[ i ]->getCollisionFlags() & ~btCollisionObject::CF_KINEMATIC_OBJECT);
				rigid_bodies[ i ]->setMassProps( 1.0f, btVector3( 0.0f, 0.0f, 0.0f ) );
				rigid_bodies[ i ]->updateInertiaTensor();
			}
		}
	}
I have tried adding and removing the bodies, reassigning gravity, passing something different than 0 to the inertia, different activation states...

Any ideas? Has anyone tried something like this?

Thank you in advance.
Korut
Posts: 5
Joined: Sun Aug 03, 2008 12:12 am

Re: Shifting Dynamic-Kinematic: Objects no longer move.

Post by Korut »

Fixed: All I had to do is getting the right inertia from the shape with calculateLocalInertia :oops: