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.
Set position
-
- Posts: 77
- Joined: Thu Nov 26, 2009 6:32 pm
Re: Set position
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.
-
- Posts: 7
- Joined: Fri Jan 21, 2011 4:25 am
Re: Set position
You can manually set the position of dynamic bodies all you want, you just can't use a motion state to do so.
-
- Posts: 16
- Joined: Sun Dec 13, 2009 3:21 pm
Re: Set position
I use btConvexHullShape and btBvhTriangleMeshShape with CF_STATIC_OBJECT | CF_KINEMATIC_OBJECT flags.winspear wrote:Only kinematic objects or can be moved using set position.
I transform body with this code:Coderro wrote:you just can't use a motion state to do so
Code: Select all
btTransform transform;
body->getMotionState()->getWorldTransform(transform);
transform.setPosition(new_position);
body->getMotionState()->setWorldTransform(transform);
-
- Posts: 7
- Joined: Fri Jan 21, 2011 4:25 am
Re: Set position
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:whiplash wrote:I transform body with this code:Coderro wrote:you just can't use a motion state to do soIt's no valid?Code: Select all
btTransform transform; body->getMotionState()->getWorldTransform(transform); transform.setPosition(new_position); body->getMotionState()->setWorldTransform(transform);
Code: Select all
btTransform transform = body -> getCenterOfMassTransform();
transform.setOrigin(new_position);
body -> setCenterOfMassTransform(transform);
-
- Posts: 96
- Joined: Mon Nov 03, 2008 9:57 pm
Re: Set position
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.
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.
-
- Posts: 16
- Joined: Sun Dec 13, 2009 3:21 pm
Re: Set position
Thanks for help me! Its work.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:
-
- Posts: 15
- Joined: Mon Oct 04, 2010 5:55 pm
Re: Set position
Or you could use setFromOpenGLMatrix