How to properly update the position of a RigidBody?

wbaldwin
Posts: 14
Joined: Mon Feb 23, 2009 9:01 am

How to properly update the position of a RigidBody?

Post by wbaldwin »

What is the proper way to update the position of a RigidBody set as a CF_KINEMATIC_OBJECT? I’m currently using the following code and wanted to confirm that it is an effective method or that there’s not some other method that I’m missing. Thanks and any help is greatly appreciated.

void move( int nIndex, const btVector3 &newPos )
{
btCollisionObject *body = m_dynamicsWorld->getCollisionObjectArray()[nIndex ];

btTransform t;

t.setIdentity();
t.setOrigin( newPos );

body->setCenterOfMassTransform( t );
body->getMotionState()->setWorldTransform( t );
body->activate( true );
}
zzcn
Posts: 20
Joined: Tue Nov 04, 2008 1:50 pm

Re: How to properly update the position of a RigidBody?

Post by zzcn »

Hi, I used the motion state to update the rigidbody also, It's the right way to do it, but I'am not sure whether it's the efficiency. I measured the time of these function calling, some code like this:

Code: Select all

btMotionState* motionState = body->getMotionState();
btTransform trans;
motionState->getWorldTransform(trans);
only these 3 functions take 8 microseconds on my computer, it's not so fast like i expected, and if i have lots of objects to update for every frame, that will be a problem if i call these functions for every objects every frame.
wbaldwin
Posts: 14
Joined: Mon Feb 23, 2009 9:01 am

Re: How to properly update the position of a RigidBody?

Post by wbaldwin »

Does anyone know of a more efficient method? I plan on having a couple thousand objects to update every frame and fear what kind of hits I'm going to take in speed and performance with my current approach...