Weird box interaction with default dynamics setup

Mind Calamity
Posts: 13
Joined: Tue Feb 28, 2012 7:51 am

Weird box interaction with default dynamics setup

Post by Mind Calamity »

Image

Excuse the non-existent lighting and lack of detail, I'm using the default setup copy-pasted from the BasicDemo code, and adopted to my engine.

Here's the code, just in case:

Code: Select all

	///collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration.
	mColCfg = new btDefaultCollisionConfiguration();

	///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
	mColDispatcher= new	btCollisionDispatcher(mColCfg);

	///btDbvtBroadphase is a good general purpose broadphase. You can also try out btAxis3Sweep.
	mBroadphase = new btDbvtBroadphase();

	///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
	mConstraintSolver = new btSequentialImpulseConstraintSolver;
And then using those, I'm creating the world like so:

Code: Select all

		world = new btDiscreteDynamicsWorld
			( mPhysicsSys->getCollisionDispatcher()
			, mPhysicsSys->getBroadphaseInterface()
			, mPhysicsSys->getConstraintSolver()
			, mPhysicsSys->getCollisionConfig());

		world->setGravity(btVector3(0,-10,0));
Simulating it:

Code: Select all

world->stepSimulation(timeSinceLastUpdate, 5);
I'm using a simple motion state setup to synchronize my graphics objects with the physics objects, no problems there.

Here's my object creation:

Code: Select all

	btTransform bulletTrans;
	bulletTrans.setOrigin(toBullet(trans->getPosition()));
	bulletTrans.setRotation(toBullet(trans->getOrientation()));

	mMotionState = new MotionState(trans, bulletTrans);

	BoxParams params = dynamic_cast<BoxParams&>(geometryParams);
	mShape = new btBoxShape(toBullet(params.halfExtents)); // halfExtents is Vector3(1, 1, 1)
	
	btVector3 inertia(0,0,0);

	mShape->calculateLocalInertia(mass, inertia);

	btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, mMotionState, mShape, inertia);
	rbInfo.m_restitution = 0.2f;
	rbInfo.m_friction = 1.5f;
	mBody = new btRigidBody(rbInfo);
Sorry for spamming code, and thanks in advance for any replies :)
allsey87
Posts: 33
Joined: Fri Oct 26, 2012 1:50 pm

Re: Weird box interaction with default dynamics setup

Post by allsey87 »

The problem is mostly likely in your implementation of btMotionState. Also show the code for the toBullet method and explain in detail what the 'weird' behaviour you are seeing is.
Mind Calamity
Posts: 13
Joined: Tue Feb 28, 2012 7:51 am

Re: Weird box interaction with default dynamics setup

Post by Mind Calamity »

Here's the header of my motion state implementation:

Header: http://pastebin.com/NVcfNq2K
Source: http://pastebin.com/NgPuMVXh

I made a video for more detail: http://www.youtube.com/watch?v=eFareVg4XC8

My transform class is basically an Ogre SceneNode.

And my conversion functions:

Code: Select all

	inline btQuaternion toBullet(const Ogre::Quaternion &q)
	{
		return btQuaternion(q.x, q.y, q.z, q.w);
	}
	inline btVector3 toBullet(const Ogre::Vector3 &v)
	{
		return btVector3(v.x, v.y, v.z);
	}

	inline Ogre::Quaternion toOgre(const btQuaternion &q)
	{
		return Quaternion(q.w(), q.x(), q.y(), q.z());
	}

	inline Ogre::Vector3 toOgre(const btVector3 &v)
	{
		return Vector3(v.x(), v.y(), v.z());
	}
Mind Calamity
Posts: 13
Joined: Tue Feb 28, 2012 7:51 am

Re: Weird box interaction with default dynamics setup

Post by Mind Calamity »

Weird, it seems that the btTransform that is passed to setWorldTransform of my motion state seems to always have an identity rotation - it's always at 1 0 0 0. :cry:
Mind Calamity
Posts: 13
Joined: Tue Feb 28, 2012 7:51 am

Re: Weird box interaction with default dynamics setup

Post by Mind Calamity »

Thanks to xissburg (on the IRC) for pointing out that zero/infinite inertia can cause behavior like this. Apparently the problem was in a piece of code I removed while pasting here and calculateLocalInertia wasn't getting called at all.