[SOLVED]2 RigidBodies Not Colliding

Post Reply
erbisme4@yahoo.com
Posts: 41
Joined: Fri Apr 29, 2016 2:41 pm

[SOLVED]2 RigidBodies Not Colliding

Post 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.
Last edited by erbisme4@yahoo.com on Thu Jan 19, 2017 5:33 pm, edited 1 time in total.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: 2 RigidBodies Not Colliding

Post 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.
erbisme4@yahoo.com
Posts: 41
Joined: Fri Apr 29, 2016 2:41 pm

Re: 2 RigidBodies Not Colliding

Post 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.
erbisme4@yahoo.com
Posts: 41
Joined: Fri Apr 29, 2016 2:41 pm

Re: 2 RigidBodies Not Colliding

Post 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.
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: 2 RigidBodies Not Colliding

Post 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.
Post Reply