I am writing a character animation animation engine that uses Bullet Physics as a physics modeling engine.
The sequence will start without a model on the screen, then the animation will be assigned to this model, the model will be transferred to frame 0 of the animation, and the engine will begin rendering the model with animation.
What is the correct way to rearrange rigid bodies in a character model when it is initialized in frame 0?
I am currently using this code, which is called right after the animation is assigned to the model, and the bones move to frame position 0:
_world->removeRigidBody(_body); bool k = (_type == Kinematics); _body->setCollisionFlags(_body->getCollisionFlags() & ~btCollisionObject::CF_NO_CONTACT_RESPONSE); btTransform tr = BulletPhysics::ConvertD3DXMatrix(&(_bone->getCombinedTrans())); tr *= _trans; _body->setCenterOfMassTransform(tr); _body->clearForces(); _body->setLinearVelocity(btVector3(0,0,0)); _body->setAngularVelocity(btVector3(0,0,0)); _world->addRigidBody(_body, _groupID, _groupMask);
The problem is that sometimes it works, and sometimes not. For example, take a model skirt. Sometimes it appears in its natural position, sometimes it shifts slightly, and it falls into place, and in other cases it is completely cut out through the body, as if the collision is disconnected, and some force pushes it in this direction. This makes sense most of the time, because in the test animation I use the model's initial position in the center of the screen, but the animation starts on the left side of the screen. Does anyone know how to solve this?
I know that the bones on the skirt are not a problem, because I turned off the physics and forced it to manually update the position of the bones in each frame, and everything was in the right positions throughout the animation.
EDIT: I also have limitations, maybe this could be the reason for this?