Wheel collision shape?

ola
Posts: 169
Joined: Sun Jan 14, 2007 7:56 pm
Location: Norway

Wheel collision shape?

Post by ola »

Hi all,

I have just started to use a convex collision shape for my offroad vehicle wheels, instead of a raycast. So I have a cylinder shape for the wheel, and find the collision points with the environment using convexSweepTest. That works well.

I'm looking for better options for a wheel shape than a cylinder - something that has got rounded edges. First I thought of using non-uniform scaling on a sphere, but found that it's not supported anymore. I guess the shape I'm looking for is the convex hull of a torus, which would look very much like a motorcycle wheel.

Or maybe a sphere with two symmetrical caps cut off, even. Is it possible to cap off parts of convex shapes like that in any way?

Any hints on how to create such a collision shape would be very welcome!

Best regards,
Ola
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: Wheel collision shape?

Post by Dirk Gregorius »

A wheel could be nicely modeled as the Minkowski sum of a sphere and a disc. Think of sweeping the sphere center along the outer rim of the disc to get an idea how the shape looks like...
ola
Posts: 169
Joined: Sun Jan 14, 2007 7:56 pm
Location: Norway

Re: Wheel collision shape?

Post by ola »

Hey, thanks! That sounds just like what I'm after.

I tried to make one and visualize it in the bullet Raytracer demo, but I get weird results: instead of looking like a wheel there are "random pixels" coming in and out when the shape rotates.

I used a short and wide cylinder shape as disc, and a sphere shape for the sphere. Does the order of the objects matter when using btMinkowskiSumShape? (I tried both, couldn't see any difference). I also tried various combinations for the transforms, having the cylinder in the centre and moving the sphere about. So, anyone got tips for how to use these minkowski shapes in bullet?

Best regards,
Ola :-)

below: my current and not so successful version of initPhysics in the raytracer demo:

Code: Select all

void	Raytracer::initPhysics()
{
	m_ele = 0;

	raytracePicture = new renderTexture(screenWidth,screenHeight);

         btCylinderShapeZ* cylinder = new btCylinderShapeZ(btVector3(1.0, 0.1, 0.1));
         btTransform ct;
         ct.setIdentity();
         
         btSphereShape* sphere = new btSphereShape(0.7);
         btTransform st;
         st.setIdentity();
         st.setOrigin(btVector3(0.0, 0.0, 1.0));
         
         btMinkowskiSumShape* sumshape = new btMinkowskiSumShape(cylinder, sphere);
         sumshape->setTransformA(ct);
         sumshape->setTransformB(st);
       
        shapePtr[0] = cylinder;
        shapePtr[1] = sumshape;
        shapePtr[2] = sphere;

	for (int i=0;i<numObjects;i++)
	{
		transforms[i].setIdentity();
		btVector3	pos(0.f,0.f,-(2.5* numObjects * 0.5)+i*2.5f);
		transforms[i].setIdentity();
		transforms[i].setOrigin( pos );
		btQuaternion orn;
		if (i < 2)
		{
			orn.setEuler(yaw,pitch,roll);
			transforms[i].setRotation(orn);
		}
	}
	
        m_collisionConfiguration = new btDefaultCollisionConfiguration();
	m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
	btVector3 worldMin(-1000,-1000,-1000);
	btVector3 worldMax(1000,1000,1000);
	m_overlappingPairCache = new btAxisSweep3(worldMin,worldMax);

	m_collisionWorld = new btCollisionWorld(m_dispatcher,m_overlappingPairCache,m_collisionConfiguration);
	
	for (int s=0;s<numObjects;s++)
	{
		btCollisionObject* obj = new btCollisionObject();
		obj->setCollisionShape(shapePtr[s]);
		obj->setWorldTransform(transforms[s]);
		m_collisionWorld->addCollisionObject(obj);
	}
}