btBoxShape spinning out of control

Post Reply
ofcbobrovsky
Posts: 1
Joined: Mon Feb 09, 2015 12:04 am

btBoxShape spinning out of control

Post by ofcbobrovsky »

I'm creating rigid bodies using btBoxShape, but the boxes are spinning wildly, and only stop if I apply a ridiculous amount of friction to them. They started out spinning, and they appear to only be spinning wildly on the Y axis.

Here is what is happening

Here are the relevant parts of my code:

Creating the world:

Code: Select all

	m_pBroadphase = new btDbvtBroadphase();

	m_pCollisionConfig = new btDefaultCollisionConfiguration();
	m_pCollisionDispatcher = new btCollisionDispatcher( m_pCollisionConfig );

	m_pPhysicsSolver = new btSequentialImpulseConstraintSolver();

	// Create the world
	m_pPhysWorld = new btDiscreteDynamicsWorld( m_pCollisionDispatcher, m_pBroadphase, m_pPhysicsSolver, m_pCollisionConfig );
	m_pPhysWorld->setGravity( btVector3( 0, -9.8f, 0 ) );
Creating the rigid body:

Code: Select all

	// Create the collision shape
	m_pBoxCollision = new btBoxShape( btVector3( 0.5f, 0.5f, 0.5f ) );
	boxMass = 1.0f;
	boxInertia = btVector3( 0.0f, 0.0f, 0.0f );
	m_pBoxCollision->calculateLocalInertia( boxMass, boxInertia );
	// Create the motion state
	boxTrans.setIdentity();
	boxTrans.setOrigin( ConversionUtil::vec3_to_btVector3( this->getPosition() ) );
	m_pBoxMotion = new btDefaultMotionState( boxTrans );
	// Create rigid body
	btRigidBody::btRigidBodyConstructionInfo boxRigidBodyInfo( boxMass, m_pBoxMotion, m_pBoxCollision, boxInertia );
	//boxRigidBodyInfo.m_friction = 25.0f;
	m_pBoxBody = new btRigidBody( boxRigidBodyInfo );
	// Add box physics to world
	GetGame()->getRenderer()->getWorld()->addRigidBody( m_pBoxBody );
Stepping the world:

Code: Select all

	m_pPhysWorld->stepSimulation( (btScalar)GetGame()->getFrameTimeS(), 10 );
Also, converting the transform to glm for OpenGL:

Code: Select all

	btTransform trans;
	btScalar matrixRaw[16];
	glm::mat4 matrix;
	m_pBoxBody->getMotionState( )->getWorldTransform( trans );
	trans.getOpenGLMatrix( matrixRaw );
	matrix = ConversionUtil::btScalar_to_mat4( &matrixRaw[0] );
I've tried multiple methods for converting to a rotation matrix and all of them have the same result.

If I had to guess the problem would be in the stepping part, to be honest I'm still not too sure as to how that works. My game is running at about 1200 FPS currently, although when I locked it to around 60 FPS and adjusted the step function, the boxes behaved the same. Also most of this code is just copied from the tutorials, I've looked it over countless times to find differences but maybe someone else's eyes can find something I missed.
ezraanderson
Posts: 4
Joined: Fri Feb 13, 2015 8:15 am

Re: btBoxShape spinning out of control

Post by ezraanderson »

~
I experiences this also in my current demo. It helps alittle by adding damping

Code: Select all

m_bodies[i]->setDamping(0.05, 0.85);
m_bodies[i]->setDeactivationTime(0.8);
m_bodies[i]->setSleepingThresholds(1.6, 2.5);

edit:
hey started out spinning
My issues is probably differnet.

edit:

Code: Select all

   boxTrans.setOrigin( ConversionUtil::vec3_to_btVector3( this->getPosition() ) );
Is the shape being attached to the center of the body ?
Post Reply