Updating physics for animated models

Posted by Mathias Hölzl on Game Development See other posts from Game Development or by Mathias Hölzl
Published on 2012-10-04T17:18:45Z Indexed on 2012/10/04 21:54 UTC
Read the original article Hit count: 305

For a new game we have do set up a scene with a minimum of 30 bone animated models.(shooter) The problem is that the update process for the animated models takes too long.

Thats what I do: Each character has ~30 bones and for every update tick the animation gets calculated and every bone fires a event with the new matrix. The physics receives the event with the new matrix and updates the collision shape for that bone. The time that it takes to build the animation isn't that bad (0.2ms for 30 Bones -> 6ms for 30 models). But the main problem is that the physic engine (Bullet) uses a diffrent matrix for transformation and so its necessary to convert it.

Code for matrix conversion: (~0.005ms)

btTransform CLEAR_PHYSICS_API Mat_to_btTransform( Mat mat )
{
btMatrix3x3 bulletRotation;
btVector3 bulletPosition;

XMFLOAT4X4 matData = mat.GetStorage();


// copy rotation matrix
for ( int row=0; row<3; ++row )
    for ( int column=0; column<3; ++column )
        bulletRotation[row][column] = matData.m[column][row];   
for ( int column=0; column<3; ++column )
    bulletPosition[column] = matData.m[3][column];

return btTransform( bulletRotation, bulletPosition );
}

The function for updating the transform(Physic):

void CLEAR_PHYSICS_API BulletPhysics::VKinematicMove(Mat mat, ActorId aid)
{
if ( btRigidBody * const body = FindActorBody( aid ) )
{
    btTransform tmp = Mat_to_btTransform( mat );
    body->setWorldTransform( tmp ); 
    }
}

The real problem is the function FindActorBody(id):

    ActorIDToBulletActorMap::const_iterator found = m_actorBodies.find( id );
if ( found != m_actorBodies.end() )
    return found->second;

All physic actors are stored in m_actorBodies and thats why the updating process takes to long. But I have no idea how I could avoid this.


Friendly greedings, Mathias

© Game Development or respective owner

Related posts about collision-detection

Related posts about physics