Ygolonac
19-12-2007 21:35:23
I'm trying to accomplish a body that is fixed on a 2D plane and that can rotate around the global Y axis (the 2D plane's normal), and tilt left and right around its local Z axis. Think a ship on a 2D plane that tilts left and right slightly upon turning for a nicer look. I'm using the 6 DOF constraint for this. However, after fixing it to the plane and only allowing rotation around the plane normal, it explodes whenever the body rotates more than 90 degrees from its initial orientation around the plane normal. Until the explosion the other axes seem to be locked correctly, but when it explodes it is pushed back strongly to rotate in the opposite direction, and if it was rotating too fast, it starts spinning wildly around all axes. I can't find out the cause.
Here's the code... there's a little bit of mixing OgreBullet and Bullet code.
Initialization (impl has DynamicsWorld *physicalWorld and btRigidBody *staticBody):
Body creation (given parameters Entity *entity and SceneNode *node):
I apply rotation using addImpulse -- it explodes when the body crosses the 90 degree boundary regardless of if more impulse is being applied at that time or not, so that can't be the cause.
Any ideas?
Edit: Eh, noticed some more kooky behavior. Unless I apply impulse during the first second or two of the simulation, the body will get stuck in thin air, unable to move at all. Puzzling. Oh yeah, forgot to mention there is only one body (and the shapeless staticBody) in the simulation.
Here's the code... there's a little bit of mixing OgreBullet and Bullet code.
Initialization (impl has DynamicsWorld *physicalWorld and btRigidBody *staticBody):
Vector3 worldSize(1000, 1000, 1000);
impl->physicalWorld = new OgreBulletDynamics::DynamicsWorld(Common::getSingleton().getSceneManager(), AxisAlignedBox(-worldSize, worldSize), Vector3::ZERO);
btRigidBody *staticBody = new btRigidBody(0, NULL, NULL);
impl->physicalWorld->getBulletDynamicsWorld()->addRigidBody(staticBody);
impl->staticBody = staticBody;
Body creation (given parameters Entity *entity and SceneNode *node):
RigidBody *body = new RigidBody("testBody", impl->physicalWorld);
MeshToShapeConverter conv(entity);
float restitution = 0.5;
float friction = 0.5;
float mass = 1;
CollisionShape *shape = static_cast<CollisionShape *>(conv.createConvex());
body->setShape(node, shape, restitution, friction, mass, node->getWorldPosition(), node->getWorldOrientation());
impl->physicalWorld->addRigidBody(body, 0, 0);
btTransform identity;
identity.setIdentity();
btGeneric6DofConstraint *constraint = new btGeneric6DofConstraint(*body->getBulletRigidBody(), *impl->staticBody, identity, identity, false);
constraint->setLimit(0, 1, 0);
constraint->setLimit(1, 0, 0);
constraint->setLimit(2, 1, 0);
constraint->setLimit(3, 0, 0);
constraint->setLimit(4, 1, 0);
constraint->setLimit(5, 0, 0);
impl->physicalWorld->getBulletDynamicsWorld()->addConstraint(constraint);
I apply rotation using addImpulse -- it explodes when the body crosses the 90 degree boundary regardless of if more impulse is being applied at that time or not, so that can't be the cause.
Any ideas?
Edit: Eh, noticed some more kooky behavior. Unless I apply impulse during the first second or two of the simulation, the body will get stuck in thin air, unable to move at all. Puzzling. Oh yeah, forgot to mention there is only one body (and the shapeless staticBody) in the simulation.