Collision Response without Rotational Response?

Rhekua
Posts: 4
Joined: Tue May 15, 2007 11:58 pm

Collision Response without Rotational Response?

Post by Rhekua »

I integrated Bullet into my project and everything seems to work fine except one thing: When objects collide with other objects their rotation does not update. Things do not bounce off of other things and rotate how they should in response to the collision. They kind of just sit there in their normal orientation, bouncing off eachother.

It's not a graphical error as I can use setAngularVelocity and the objects (which are box shapes at the moment) will rotate and collide, climbing over eachother, etc. but they do not influence eachother's rotation.

I followed the user manual's integration steps and also looked at the other demos and it seems to me that I am initializing everything how I should.

I am using the newest version, 2.50b.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

It sounds like the 'angularFactor' is set to zero in the rigidbody.

Did you use this one?

Code: Select all

btRigidBody::setAngularFactor(btScalar angFac)
Hope this helps,
Erwin
Rhekua
Posts: 4
Joined: Tue May 15, 2007 11:58 pm

Post by Rhekua »

I didn't use that function, no. But I tried adding it in and setting it to 1 but there is still no rotation.

Should I be including more than just:

Code: Select all

#include "Contrib\bullet-2.50b\src\btBulletDynamicsCommon.h"
#if defined(DEBUG) || defined(_DEBUG)
	#pragma comment( lib, "libbulletcollision_d.lib" )
	#pragma comment( lib, "libbulletdynamics_d.lib" )
	#pragma comment( lib, "libbulletmath_d.lib" )
#else
	#pragma comment( lib, "libbulletcollision.lib" )
	#pragma comment( lib, "libbulletdynamics.lib" )
	#pragma comment( lib, "libbulletmath.lib" )
#endif
Everything else seems to work fine but I can't figure out why they just won't rotate. I can link to a video if you would like to see exactly what is going on.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

It might be some initialization issue.

Did you initialize the local inertia properly? Can you compare it more carefully with Bullet Demo initialization (see Bullet/Demos/OpenGL/DemoApplication.cpp )

Can you provide a snippet of collision shape and rigidbody creation?

Thanks,
Erwin
Rhekua
Posts: 4
Joined: Tue May 15, 2007 11:58 pm

Post by Rhekua »

Code: Select all

btMotionState* g_motionState = NULL;
btRigidBody* g_rigidBody = NULL;
btCollisionShape* box = NULL;

	btTransform boxTrans;
	boxTrans.setIdentity();
	boxTrans.setOrigin(btVector3( 0.0f,100.0f,0.0f));
	g_motionState = new btDefaultMotionState(boxTrans);
	box = new btBoxShape( btVector3(1.0f, 1.0f, 1.0f) );
	g_rigidBody = new btRigidBody( 1.0f, g_motionState, box, btVector3(0,0,0), btScalar(0), btScalar(0), btScalar(0.5), btScalar(1.0) );
	g_DynamicsWorld->addRigidBody( g_rigidBody );
	g_rigidBody->setAngularFactor( btScalar(1) );
	g_rigidBody->setLinearVelocity( btVector3( 0.0f, 0.0f, 0.0f ) );
	g_rigidBody->setAngularVelocity( btVector3( 0.0f, 0.0f, 0.0f ) );
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

g_rigidBody = new btRigidBody( 1.0f, g_motionState, box, btVector3(0,0,0), btScalar(0), btScalar(0), btScalar(0.5), btScalar(1.0) );

You should provide a proper local inertia tensor, instead of btVector3(0,0,0) as 4th argument in btRigidBody constructor.

The sample code in Bullet uses the shape and mass to calculate the localInertia:

Code: Select all

btRigidBody*    DemoApplication::localCreateRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape)
{
        //rigidbody is dynamic if and only if mass is non zero, otherwise static
        bool isDynamic = (mass != 0.f);

        btVector3 localInertia(0,0,0);
        if (isDynamic)
                shape->calculateLocalInertia(mass,localInertia);

        //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects

#define USE_MOTIONSTATE 1
#ifdef USE_MOTIONSTATE
        btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
        btRigidBody* body = new btRigidBody(mass,myMotionState,shape,localInertia);

#else
        btRigidBody* body = new btRigidBody(mass,startTransform,shape,localInertia);
#endif//
        m_dynamicsWorld->addRigidBody(body);

        return body;
}
Hope this helps,
Erwin
Rhekua
Posts: 4
Joined: Tue May 15, 2007 11:58 pm

Post by Rhekua »

Awesome! Thank you very much for your help.