erase static flag from kinematic bodies

Post Reply
topcomer
Posts: 31
Joined: Thu Sep 21, 2006 1:53 pm
Location: sweden but italian

erase static flag from kinematic bodies

Post by topcomer »

I see that btRigidBody.cpp contains the following:

Code: Select all

void btRigidBody::setMassProps(btScalar mass, const btVector3& inertia)
{
	if (mass == btScalar(0.))
	{
		m_collisionFlags |= btCollisionObject::CF_STATIC_OBJECT;
		m_inverseMass = btScalar(0.);
	} else
	{
		m_collisionFlags &= (~btCollisionObject::CF_STATIC_OBJECT);
		m_inverseMass = btScalar(1.0) / mass;
	}
	
	m_invInertiaLocal.setValue(inertia.x() != btScalar(0.0) ? btScalar(1.0) / inertia.x(): btScalar(0.0),
				   inertia.y() != btScalar(0.0) ? btScalar(1.0) / inertia.y(): btScalar(0.0),
				   inertia.z() != btScalar(0.0) ? btScalar(1.0) / inertia.z(): btScalar(0.0));

}
which means that the following initialization in ConcavePhysicsDemo.cpp will give a static and not kinematic body:

Code: Select all

float mass = 0.f;
btTransform startTransform;
startTransform.setIdentity();
btVector3 camPos = getCameraPosition();
startTransform.setOrigin(camPos);

btRigidBody* body = this->localCreateRigidBody(mass, startTransform,m_trimeshShape);

// Make it kinematic
body->setCollisionFlags( body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT );
body->setActivationState(DISABLE_DEACTIVATION);
I added:

Code: Select all

body->setCollisionFlags( body->getCollisionFlags() & (~btCollisionObject::CF_STATIC_OBJECT) );
to the initialization but it does not help at all. Is there something else I should change? Thanks.
Chaster
Posts: 19
Joined: Mon Oct 01, 2007 7:24 pm

Re: erase static flag from kinematic bodies

Post by Chaster »

I have noticed the same thing (making a body kinematic by changing the collision flags to include CF_KINEMATIC does not remove the CF_STATIC flag) and thought it odd. However, it does work for me. Apparently, kinematic bodies are "special case" versions of static bodies.

One thing that you should check if the kinematic body is not working correctly is to make sure you are using btMotionState to update the body's position/orientation. For some reason I don't quite understand, it seems one MUST use the btMotionState to update kinematic bodies worldTransform (whereas just using the btRigidBody->setWorldTransform() seems to work fine for dynamic bodies).

This brings up a request:

The whole btMotionState thing is very poorly explained (actually, I can find no explanation of it at all). Where is it required? Where is it optional? Why is it used/not used? Can we have a SINGLE way to set a rigid body's position/orientation/transform. instead of having to figure out whether or not to go through btRigidBody->getMotionState() or not? It's quite confusing and not user-friendly for the newbies...

Chaster
topcomer
Posts: 31
Joined: Thu Sep 21, 2006 1:53 pm
Location: sweden but italian

Re: erase static flag from kinematic bodies

Post by topcomer »

Chaster wrote:I have noticed the same thing (making a body kinematic by changing the collision flags to include CF_KINEMATIC does not remove the CF_STATIC flag) and thought it odd. However, it does work for me. Apparently, kinematic bodies are "special case" versions of static bodies.
Thanks for the reply.
In my case if I move a kinematic body through a static plane I get no collision callback, probably because they are considered both static. Does this work for you?

Alessio
Chaster
Posts: 19
Joined: Mon Oct 01, 2007 7:24 pm

Re: erase static flag from kinematic bodies

Post by Chaster »

I have never tried to collide a static & kinematic body. You will need to change the collision group AND collision filter flags I think. .
Post Reply