btMotionState questions

Jack
Posts: 59
Joined: Thu Aug 31, 2006 11:51 am

btMotionState questions

Post by Jack »

1) You call motionState->getWorldTransform(m_worldTransform) in btRigidBody constructor. I need to prepare Transform before object creation. It is not good. Normal sequence is:
  • a) Create object
    b) Set position
    c) Add to Scence
Something like:

Code: Select all

const __m128 m128 = _mm_set_ps(0,6,6,6);
BODY_BOX *p = new BODY_BOX(m128);

p->SetPosition(D3DXVECTOR3(4*x-8,3*y+1.5f,4*z-5));
p->SetFriction(0.8f);
p->SetRestitution(0.5f);

RENDER::COMPLEX::AddToComplex(p);
PHYSICS::COMPLEX::AddToComplex(p);
It is better to call motionState->getWorldTransform(m_worldTransform) in void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body)

Code: Select all

void	btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body)
{
if (body->getMotionState())
	body->getMotionState()->getWorldTransform(body->getWorldTransform());
body->setGravity(m_gravity);
bool isDynamic = !(body->isStaticObject() || body->isKinematicObject());
short collisionFilterGroup = isDynamic? btBroadphaseProxy::DefaultFilter : btBroadphaseProxy::StaticFilter;
short collisionFilterMask = isDynamic? btBroadphaseProxy::AllFilter : 	btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::StaticFilter;

addCollisionObject(body,collisionFilterGroup,collisionFilterMask);
}
2) Unable to set new Transform several times (while object is in the Scene). Where are functions like SetPosition, SetOrientation? How can I set new position/orientation to the object? The only function I found is void translate(const btVector3& v). But it sets relative position. :cry: :cry: :cry: I need ability to set absolute position...

3) Objects stand unstable. Stack of cylinders is shaking (They stood calm in prev. versions). :cry:
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

If you want to set a new world transform on a dynamic rigidbody, just call

Code: Select all

void	setWorldTransform(const btTransform& worldTrans)
Static objects (mass 0) should not move, unless you use the kinematic flag.

Are you using the btDefaultMotionState, or your own derived version?
What timestep are you passing? variable? fixed?
You can pass variable timestep, and the system does interpolation for you.

For dynamic objects, do you make sure to read the worldtransform from the motionstate?

Not sure about your cylinder issues, can you give more details about sizes etc?
Thanks,
Erwin



Jack wrote:1) You call motionState->getWorldTransform(m_worldTransform) in btRigidBody constructor. I need to prepare Transform before object creation. It is not good. Normal sequence is:
  • a) Create object
    b) Set position
    c) Add to Scence
Something like:

Code: Select all

const __m128 m128 = _mm_set_ps(0,6,6,6);
BODY_BOX *p = new BODY_BOX(m128);

p->SetPosition(D3DXVECTOR3(4*x-8,3*y+1.5f,4*z-5));
p->SetFriction(0.8f);
p->SetRestitution(0.5f);

RENDER::COMPLEX::AddToComplex(p);
PHYSICS::COMPLEX::AddToComplex(p);
It is better to call motionState->getWorldTransform(m_worldTransform) in void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body)

Code: Select all

void	btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body)
{
if (body->getMotionState())
	body->getMotionState()->getWorldTransform(body->getWorldTransform());
body->setGravity(m_gravity);
bool isDynamic = !(body->isStaticObject() || body->isKinematicObject());
short collisionFilterGroup = isDynamic? btBroadphaseProxy::DefaultFilter : btBroadphaseProxy::StaticFilter;
short collisionFilterMask = isDynamic? btBroadphaseProxy::AllFilter : 	btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::StaticFilter;

addCollisionObject(body,collisionFilterGroup,collisionFilterMask);
}
2) Unable to set new Transform several times (while object is in the Scene). Where are functions like SetPosition, SetOrientation? How can I set new position/orientation to the object? The only function I found is void translate(const btVector3& v). But it sets relative position. :cry: :cry: :cry: I need ability to set absolute position...

3) Objects stand unstable. Stack of cylinders is shaking (They stood calm in prev. versions). :cry:
Jack
Posts: 59
Joined: Thu Aug 31, 2006 11:51 am

Re: Bad 2.23 :(

Post by Jack »

1) Can we have additionally to setWorldTransform separate setPosition and setOrientation?

Initial transform you get via MotionState::getWorldTransform. Next transforms go via RigidBody::setWorldTransform. Why make things so complicated? We need one indoor and one outdoor.

To the Bullet:
a) All transforms go via RigidBody::setWorldTransform. There is no MotionState::getWorldTransform method.
OR
b) MotionState::getWorldTransform is called in each frame. There is no RigidBody::setWorldTransform method.

From the Bullet:
a) All transforms go via MotionState::setWorldTransform. No calls for static/kinematic objects (if we use point "a" in prev. section - "To the Bullet").
OR
b) All transforms go via MotionState::setWorldTransform. It is called for static/kinematic objects once RigidBody::setWorldTransform is called.

2) cylinder issues: A pile of three cylinders. HalfSize = {1.5f,1.5f,1.5f}. I noticed that resulting cylinder size is slightly greater. It is around 3.1 (instead of 3). If I put them one on one with gap=3, they jump up due to interpenetration. For example, if I use BOX shape (HalfSize=1.5), then I can put them one on one with exact gap=3. Even if I put cylinders with gap=3.1, all pile is shaking around Y-axis (precession).
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Bad 2.23 :(

Post by Erwin Coumans »

Jack wrote:1) Can we have additionally to setWorldTransform separate setPosition and setOrientation?

Initial transform you get via MotionState::getWorldTransform. Next transforms go via RigidBody::setWorldTransform. Why make things so complicated? We need one indoor and one outdoor.

To the Bullet:
a) All transforms go via RigidBody::setWorldTransform. There is no MotionState::getWorldTransform method.
OR
b) MotionState::getWorldTransform is called in each frame. There is no RigidBody::setWorldTransform method.

From the Bullet:
a) All transforms go via MotionState::setWorldTransform. No calls for static/kinematic objects (if we use point "a" in prev. section - "To the Bullet").
OR
b) All transforms go via MotionState::setWorldTransform. It is called for static/kinematic objects once RigidBody::setWorldTransform is called.
OK, the motionstate should be improved and made more consistent. I will look into the interface issue. It got complicated due to the additional interpolation scheme and kinematic support.
2) cylinder issues: A pile of three cylinders. HalfSize = {1.5f,1.5f,1.5f}. I noticed that resulting cylinder size is slightly greater. It is around 3.1 (instead of 3). If I put them one on one with gap=3, they jump up due to interpenetration. For example, if I use BOX shape (HalfSize=1.5), then I can put them one on one with exact gap=3. Even if I put cylinders with gap=3.1, all pile is shaking around Y-axis (precession).
There are 2 issues: The collision margin affects different shapes in different ways. For cylinders, the collision margin is outside for cylinders. You can subtract the margin from the cylinder extends to hide this issue.

About stability, I'm not aware of issues, here. Can you reproduce this in the CcdPhysicsDemo?

What timestep are you using? Variable or fixed? What are the values passed when you calling stepSimulation?

Thanks,
Erwin
Jack
Posts: 59
Joined: Thu Aug 31, 2006 11:51 am

Post by Jack »

I use variable time stamp:

void PHYSICS::Sync(void)
{
const float dt = DeltaTime();

LockWrite();
_pPhysWorld->stepSimulation(dt, 10);
UnlockWrite();

}

I'll try to reproduce it in demo...