Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question
    
What is the code behind mat.GetStorage()? Calling that method over and over is unnecessary; you should store its result in a variable. –  Ricket Oct 4 '12 at 17:27
    
There is something wrong in your matrix transpose code. 16 ms for 100 matrices takes way too long. This is the time 60 fps games use for the entire frame, having tons of matrix operations. Please show us more code –  Maik Semder Oct 4 '12 at 17:38
    
My 1 year old mac book pro needs 1.8 ms transposing 100,000 matrices –  Maik Semder Oct 4 '12 at 17:56
    
@Ricket mat.GetStorage() return XMFLOAT4X4. –  Mathias Hölzl Oct 4 '12 at 18:09
    
@Maik Semder The time I mentioned was for transposing, building the btTransform(bulletRotation,bulletPosition) and body->setWorldTransform( trans );. The transposing/building takes 0.005ms and the setWorldTransform() takes 0.0013ms (for 1 matrix). –  Mathias Hölzl Oct 4 '12 at 18:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.