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 );
}
How to properly update the position of a RigidBody?
-
- Posts: 14
- Joined: Mon Feb 23, 2009 9:01 am
-
- Posts: 20
- Joined: Tue Nov 04, 2008 1:50 pm
Re: How to properly update the position of a RigidBody?
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:
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.
Code: Select all
btMotionState* motionState = body->getMotionState();
btTransform trans;
motionState->getWorldTransform(trans);
-
- Posts: 14
- Joined: Mon Feb 23, 2009 9:01 am
Re: How to properly update the position of a RigidBody?
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...