Riding an elevator - jittering

Post Reply
Spaddlewit
Posts: 28
Joined: Fri Sep 04, 2009 8:23 pm

Riding an elevator - jittering

Post by Spaddlewit »

I have a rigid body that is riding an elevator, slowly rising. I've tried creating the elevator out of btBvhTriangleMeshShape, btConvexShape, btBoxShape, and all have the same behavior -- as the elevator slowly rises, the rigid body on top (btSphereShape), jitters up and down. What is causing this and how can I avoid it? I just want it to remain flush against the 'floor' of the elevator during the whole rise.

Here are my two creation functions - one for the sphere, the other for the elevator:

Code: Select all

	btSphereShape *shape = new btSphereShape(object->radius);

	ObjectMotionState *motionState = new ObjectMotionState(object);
	btRigidBody::btRigidBodyConstructionInfo rbInfo(1.0f, motionState, shape, btVector3(0, 0, 0));
	rbInfo.m_linearSleepingThreshold = 0.0f;
	rbInfo.m_angularDamping = 0.0f;
	btRigidBody *body = new btRigidBody(rbInfo);
	
	body->setAngularFactor(0);
	body->setFriction(0.0f);
	body->setRestitution(0);
	body->setUserPointer(object);
	body->setCcdSweptSphereRadius(shape->getRadius() * 0.2f);
	body->setCcdMotionThreshold(shape->getRadius());

	body->setSleepingThresholds(0.0f, 0.0f);
	body->setActivationState(DISABLE_DEACTIVATION);
	body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);

	dynamicsWorld->addRigidBody(body);

Code: Select all

btTriangleMesh *trimesh = new btTriangleMesh();

	int i;
	for (i = 0; i < object->model->numMeshes; i++)
	{
		Model::mesh_t *mesh = &object->model->meshes[i];
		Model::frame_t *frame = &mesh->frames[0];

		int j;
		for (j = 0; j < mesh->numTriangles; j++)
		{
			float *vertices = &frame->vertices[9 * j];

			btVector3 tri[] = {
				btVector3(vertices[0], vertices[1], vertices[2]),
				btVector3(vertices[3], vertices[4], vertices[5]),
				btVector3(vertices[6], vertices[7], vertices[8])};

			trimesh->addTriangle(tri[0], tri[1], tri[2]);
		}
	}

	btBvhTriangleMeshShape *shape = new btBvhTriangleMeshShape(trimesh, true, true);

	ObjectMotionState *motionState = new ObjectMotionState(object);
	btRigidBody::btRigidBodyConstructionInfo rbInfo(0.0f, motionState, shape, btVector3(0, 0, 0));
	btRigidBody *body = new btRigidBody(rbInfo);
	body->setFriction(0.0f);
	body->setRestitution(0);

	dynamicsWorld->addRigidBody(body);
Post Reply