Page 1 of 1

[SOLVED]2 RigidBodies Not Colliding

Posted: Tue Jun 28, 2016 3:11 pm
by erbisme4@yahoo.com
I have a problem where I cannot get two imported rigidbodies to collide. The rigidBodies are made using btGImpactMeshShape, and btTriangleIndexVertexArray. Code for import is as follows:

Code: Select all

btBulletWorldImporter* import = new btBulletWorldImporter(0);
	if (import->loadFile("world.bullet"))
	{
		int num = import->getNumRigidBodies();
		for (int i = 0; i < num; i++)
		{
			btRigidBody* body = (btRigidBody*)import->getRigidBodyByIndex(i);
			body->setWorldTransform(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, 0)));
			dynamicsWorld->addRigidBody(body);
		}
	}
	btRigidBody* myBody = (btRigidBody*)(dynamicsWorld->getCollisionObjectArray()[0]);
	myBody->setActivationState(DISABLE_DEACTIVATION);
	myBody->getCollisionShape()->setLocalScaling(btVector3(2, 2, 2));
	myBody->setWorldTransform(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 2, 0)));
	myBody->setLinearVelocity(btVector3(0, -.5, 0));
I have viewed the simulation at different viewing angles and the one shape(cylinder) goes right through the cube shape.

Re: 2 RigidBodies Not Colliding

Posted: Tue Jun 28, 2016 3:40 pm
by drleviathan
Are the bodies being set dynamic? It isn't clear to me because you are loading them from some file. I would guess if they are properly flagged as dynamic in the file they will be loaded correctly but since you are having problems you need to start sanity checking your assumptions.

By default a btRigidBody is static (that is, btCollisionObject::_collisionFlags is initialized to btCollisionObject::CF_STATIC_OBJECT) and static objects do not collide with each other. In general one would make a body dynamic by clearing the static and kinematic flags (if any):

Code: Select all

body->setCollisionFlags(body->getCollisionFlags & ~(btCollisionObject::CF_STATIC_OBJECT | btCollisionObject::CF_KINEMATIC_OBJECT)
Ideally this would be done before adding the body to the DynamicsWorld. When moving a static object from dynamic or kinematic one must first remove it from the DynamicsWorld and then re-add it.

Re: 2 RigidBodies Not Colliding

Posted: Tue Jun 28, 2016 9:18 pm
by erbisme4@yahoo.com
With the same code I posted, I am failing to get any rigidBody count. Is bullet physics finicky about exporting worlds? I clearly have a rigidBody in my world when I export it, but when I call

Code: Select all

import.loadFile("world.bullet");
	{

		int numRigid = import.getNumRigidBodies();
I fail to get a non-zero number for numRigid. I am exporting from MSVC_DLL release program to plain multithreaded. I have been trying to figure out why no rigidbodies are found with no luck.

Re: 2 RigidBodies Not Colliding

Posted: Tue Jun 28, 2016 9:31 pm
by erbisme4@yahoo.com
I figured it out. I was calling serializer->startSerialization() and finishSerialization() before and after serializing the world. I guess it doesn't like that.

Re: 2 RigidBodies Not Colliding

Posted: Wed Jun 29, 2016 10:11 pm
by benelot
Edit your first post's title and add the [SOLVED] tag to the beginning of it, so that we can all see that it is solved.