Set position

whiplash
Posts: 16
Joined: Sun Dec 13, 2009 3:21 pm

Set position

Post by whiplash »

Hello!

I have strange problem. I created rigid body in position (0, 0, 0). After creation i move my rigid body in new position - (200, 200, 200) and i checked up that rigid body is valid in this position.

Problem: if i called "m_dynamics_world->stepSimulation" then my rigid body moved in (0, 0, 0). Why?

p.s. If it is required, I will attach a code.
winspear
Posts: 77
Joined: Thu Nov 26, 2009 6:32 pm

Re: Set position

Post by winspear »

Only kinematic objects or can be moved using set position. Dynamic objects follow basic Newtonian physics, so you have to apply a force to move them.
Coderro
Posts: 7
Joined: Fri Jan 21, 2011 4:25 am

Re: Set position

Post by Coderro »

You can manually set the position of dynamic bodies all you want, you just can't use a motion state to do so.
whiplash
Posts: 16
Joined: Sun Dec 13, 2009 3:21 pm

Re: Set position

Post by whiplash »

winspear wrote:Only kinematic objects or can be moved using set position.
I use btConvexHullShape and btBvhTriangleMeshShape with CF_STATIC_OBJECT | CF_KINEMATIC_OBJECT flags.
Coderro wrote:you just can't use a motion state to do so
I transform body with this code:

Code: Select all

btTransform transform;
body->getMotionState()->getWorldTransform(transform);
transform.setPosition(new_position);
body->getMotionState()->setWorldTransform(transform);
It's no valid?
Coderro
Posts: 7
Joined: Fri Jan 21, 2011 4:25 am

Re: Set position

Post by Coderro »

whiplash wrote:
Coderro wrote:you just can't use a motion state to do so
I transform body with this code:

Code: Select all

btTransform transform;
body->getMotionState()->getWorldTransform(transform);
transform.setPosition(new_position);
body->getMotionState()->setWorldTransform(transform);
It's no valid?
Motion states only work in one direction. For kinematic bodies they let you write the transform and Bullet reads it. For dynamic bodies, Bullet writes it for you to read. Here's code to do what you want:

Code: Select all

btTransform transform = body -> getCenterOfMassTransform();
transform.setOrigin(new_position);
body -> setCenterOfMassTransform(transform);
User avatar
ejtttje
Posts: 96
Joined: Mon Nov 03, 2008 9:57 pm

Re: Set position

Post by ejtttje »

I should revisit the setCenterOfMassTransform() method in the current version.

Just for reference, I previously had some issues with this approach and wound up simply removing the rigid body from the dynamics world and then re-inserting it at the new position, which is probably less computationally efficient but seems very robust. Just a thought for last resort.
whiplash
Posts: 16
Joined: Sun Dec 13, 2009 3:21 pm

Re: Set position

Post by whiplash »

Coderro wrote:Motion states only work in one direction. For kinematic bodies they let you write the transform and Bullet reads it. For dynamic bodies, Bullet writes it for you to read. Here's code to do what you want:
Thanks for help me! Its work.
Etek
Posts: 15
Joined: Mon Oct 04, 2010 5:55 pm

Re: Set position

Post by Etek »

Or you could use setFromOpenGLMatrix