Placement of Colliders in MultiBody

Post Reply
LukeMurray
Posts: 2
Joined: Tue Mar 22, 2022 2:27 pm

Placement of Colliders in MultiBody

Post by LukeMurray »

Hi all,

I'm creating a MultiBody and I'm having a hard time figuring out whether or not I am actually supposed to have control over where to place the colliders?

To take the MultiDofDemo example provided, in the code there is the following:

Code: Select all

for (int i = 0; i < pMultiBody->getNumLinks(); ++i)
	{
		[b]btVector3 posr = local_origin[i + 1] + btVector3(30.f, 1.f, 0.f);//
		//	float pos[4]={posr.x(),posr.y(),posr.z(),1};

		btScalar quat[4] = {-world_to_local[i + 1].x(), -world_to_local[i + 1].y(), -world_to_local[i + 1].z(), world_to_local[i + 1].w()};

		btCollisionShape* box = new btBoxShape(linkHalfExtents);
		btMultiBodyLinkCollider* col = new btMultiBodyLinkCollider(pMultiBody, i);

		col->setCollisionShape(box);
		btTransform tr;
		tr.setIdentity();
		tr.setOrigin(posr);
		tr.setRotation(btQuaternion(quat[0], quat[1], quat[2], quat[3]));
		col->setWorldTransform(tr);
		col->setFriction(friction);
		pWorld->addCollisionObject(col, 2, 1 + 2);
		pMultiBody->getLink(i).m_collider = col;[/b]
	}
What I have found though is once the Collider is set:

Code: Select all

pMultiBody->getLink(i).m_collider = col;
All the transforms added prior are gone! In fact, I have found the below has the exact same effect:

Code: Select all

for (int i = 0; i < pMultiBody->getNumLinks(); ++i)
	{

		btCollisionShape* box = new btBoxShape(linkHalfExtents);
		btMultiBodyLinkCollider* col = new btMultiBodyLinkCollider(pMultiBody, i);

		col->setCollisionShape(box);
		col->setFriction(friction);
		pWorld->addCollisionObject(col, 2, 1 + 2);
		pMultiBody->getLink(i).m_collider = col;
	}
This is currently an issue for me since I have everything working on a MultiBody of my own, however since I am wanting to use capsules I can not rotate them to face the correct way. Am I missing something?

Thanks everyone, any help would be greatly appreciated!
LukeMurray
Posts: 2
Joined: Tue Mar 22, 2022 2:27 pm

Re: Placement of Colliders in MultiBody

Post by LukeMurray »

Found a simple solution to this is just to use btCompoundShape and add both the shape and the transform as a child shape.

Code: Select all

CompoundShape->addChildShape(transform/*offset*/, CollisionShape);
Post Reply