Changing position of btRigidBody in a post-tick callback

Post Reply
Spaddlewit
Posts: 28
Joined: Fri Sep 04, 2009 8:23 pm

Changing position of btRigidBody in a post-tick callback

Post by Spaddlewit »

In my post-tick callback, I evaluate the contact points and perform different actions. One of these actions is that I want to change, essentially 'teleport' the btRigidBody. But I have an eerie feeling it's not a good idea to be adding & removing objects from the dynamicsWorld until the entire simulation is completed.

So far I'm doing:
btTransform newTransform = body->getWorldTransform();
newTransform.setOrigin(btVector3(posToSet.x, posToSet.y, posToSet.z));
body->setWorldTransform(newTransform);


What other things do I need to recalculate (AABB??) to reset the position without removing it & readding it?
LJS
Posts: 9
Joined: Mon Feb 04, 2013 12:12 pm

Re: Changing position of btRigidBody in a post-tick callback

Post by LJS »

Maybe too soon for me to answer but here is my thought, maybe you can do something with it already:

As far as my understanding goes, when you reposition an object, the physics will be calculated from there on. Think you need to take into account the velocity so if you are running for your digital butt and teleport to another spot you stand still (or that object). Bounding box would still be the same as it travels with the object (assuming, you synchronize the visual mesh and the btRigidBody).

Think you are right about removing and adding objects that are just the same as creating a new object (allocating memory) is costly. Maybe adding a reset function to your object would clearify and easing your code.

If you like a mess and a lot of coding, keep the velocity and add a wall at the second teleporter :)

I am using Ogre and this is how I set up my 'object'

Code: Select all

class cObject : public btMotionState
{
  cObject()
  {
    create my mesh and scenenode
    create the rigidbody
  }
  // inherited set/getWorldTransform
  virtual void getWorldTransform( btTransform& transform ) const
  {
     take either __*alway*__ the position of the rigid body or from the scenenode
  }
  virtual void setWorldTransform( const btTransform& transform )
  {
     m_scenenode->setPosition( ToOgreVector( transform -> pos -> rot ) )
     m_rigidbody->setWorldTransform( transform );
    // well something like that
  }
}
Post Reply