invisible bounds stopping my rigidbody movement

jackskelyton
Posts: 32
Joined: Mon Nov 05, 2007 3:52 pm

invisible bounds stopping my rigidbody movement

Post by jackskelyton »

I'm having a strange problem with my code and my simple Ccd Physics simulation. I pretty much followed the steps in the user manual and the Ccd demo that comes with the source files: i'm using DefaultDynamicWorld, DefaultSolver, DefaultBroadphase, pretty much just copying and pasting from the demo source. The code is plugged into my team's proprietary game engine, but right now all that's doing is tying one of our meshes to a btRigidBody and drawing it based on the rigidbody's btWorldTransform. Everything appears to be working just fine, but for some reason the mesh won't translate beyond 16 units in any direction. It does this no matter how large I set the AABB min and max for the btDynamicWorld. Has anyone come across something like this? Any ideas about what I should examine to try and fix this? We've been over and over the code, tracking values at every level of the simulation, and we just cannot explain why the mesh stops at +/- 16.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: invisible bounds stopping my rigidbody movement

Post by Erwin Coumans »

jackskelyton wrote:DefaultDynamicWorld, DefaultSolver, DefaultBroadphase, pretty much just copying and pasting from the demo source.
I'm not aware of a DefaultDynamicsWorld, nor DefaultSolver DefaultBroadphase.
Do you mean btDiscreteDynamicsWorld, btSequentialImpulseConstraintSolver and btAxisSweep3?

What kind of collision shape do you create and pass into the moving btRigidBody? Can you provide a small snippet (less then 100 lines please) how you construct the collision shape and rigid body, and btAxisSweep3?

How many objects are in the dynamics world?

Thanks,
Erwin
jackskelyton
Posts: 32
Joined: Mon Nov 05, 2007 3:52 pm

Re: invisible bounds stopping my rigidbody movement

Post by jackskelyton »

Certainly. We have two classes, PhysicsSystem and PhysicsObject, that interface between our engine and Bullet. The PhysicsSystem init method does the following:

Code: Select all

bool PhysicsSystem::Initialize() {

    // set physics world size (axis sweep)
   btVector3 worldAABBMin(-100,-100,-100);
   btVector3 worldAABBMax(100,100,100);
   const int maxProxies = 1000;
   
   // Initialize Bullet configurations
   mPhysicsConfig = new btDefaultCollisionConfiguration();
   mPhysicsDispatcher = new btCollisionDispatcher(mPhysicsConfig);
   mPhysicsSolver = new btSequentialImpulseConstraintSolver;
   mPhysicsBroadphase = new btAxisSweep3(worldAABBMin,worldAABBMax,maxProxies);

   // Create Bullet physics world
  	mPhysicsWorld = new btDiscreteDynamicsWorld(mPhysicsDispatcher,mPhysicsBroadphase,mPhysicsSolver);

	// Set initial values
	mPhysicsWorld->getDispatchInfo().m_enableSPU = true;
   mPhysicsWorld->setGravity(btVector3(0,-0.5,0));

   return 1;
}
Then in PhysicsObject, after we initialize variables that store btTransform, mass, and inertia data, we run the build method below:

Code: Select all

void PhysicsObject::BuildCollisionSphere(float radius) {
   mCollisionShape = new btSphereShape(radius);
   
   mMotionState = new btDefaultMotionState(mTransform);
	btRigidBody* mRigidBody = new btRigidBody(mMass,mMotionState,mCollisionShape,mInertia);

   GAME->GetPhysicsSystem()->GetPhysicsWorld()->addRigidBody(mRigidBody);
   mRigidBody->setCcdSquareMotionThreshold(0.5);
}
Finally, we attach the PhysicsObject to an Actor object that handles loading, moving, and drawing a mesh and tell the Actor to get its transform from the PhysicsObject's btWorldTransform and put a stepSimulation call in the game loop. In fact, I found that the physics object stops moving at +/-.016 units, not 16.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: invisible bounds stopping my rigidbody movement

Post by Erwin Coumans »

jackskelyton wrote:I found that the physics object stops moving at +/-.016 units, not 16.
Does this happen even with one single moving rigid body?

Does it move only one frame, and could the world transform be overwritten each frame?

It is probably best to compare your setup with one of the demos (Bullet/Demos/BasicDemo).
Thanks,
Erwin
jackskelyton
Posts: 32
Joined: Mon Nov 05, 2007 3:52 pm

Re: invisible bounds stopping my rigidbody movement

Post by jackskelyton »

We solved it :) As it turned out, the Bullet world was set up correctly, but we were inadvertently converting from row- to column-order when translating between btVectors and our engine's proprietary vector class. We switched it and it works great.