[SOLVED] Updating CollisionShape leads to undetected collisions

Post Reply
BeneHei
Posts: 2
Joined: Wed Mar 14, 2018 2:59 pm

[SOLVED] Updating CollisionShape leads to undetected collisions

Post by BeneHei »

Hello there, i have been working with bullet for quite a while now and everything always worked out well for me until i had to encounter the following Problem:


At some point in my project i need to update the shapes of some btCollisionObject and after all btCollisionShape have been updated i call bd_pWorld->performDiscreteCollisionDetection(), Collision Filters stay the same.

Now the Problem, my programm does not find any collisions between a objects with ShapeType btConvexHullShape and objects with ShapeType btBoxShape if the shape of the Object with the btBoxShape had its shape updated at some point in the program, collisions with objects that did not have their shapes updated at some point are detected correctly.

However, if i extract all vertices of the Box-Object and create a new ConvexHullShape with this information and replace the btCollisionShape of the Box-Object with the new ConvexHull, which was created using the btBoxShape, everything works just fine and all collisions are detected, but this needs much more time. So collisions between updated ConvesHullShapes are properly detected.

I implemented a Debug Drawer that shows collisions as Red dots, when i use the ConvexHullShape, collisions are displayed but if i use the btBoxShape nothing is displayed. I also tried out the contactpairTest function, same result.

I also tried using other CollisionShapes than the btBoxShape, for example: ConeShape; CylinderShape and ShpereShape, it seems that all of them are not recognized by the detection algorithm. Only the way using the convexhulls seems to work.






My Configuration:

Code: Select all

	bd_pCollisionConfiguration = new btDefaultCollisionConfiguration();
	bd_pDispatcher = new btCollisionDispatcher(bd_pCollisionConfiguration);
	bd_pBroadphase = new btDbvtBroadphase();
	bd_pWorld = new btCollisionWorld(bd_pDispatcher, bd_pBroadphase, bd_pCollisionConfiguration);

Function that updates the shape of the Box-Object

Code: Select all



void 	UpdateBoxShape(){


	
	 btVector3 mCurrent_Half_Extends_MV = btVector3(2,2,2);
	 btBoxShape* BoxShape= new btBoxShape(mCurrent_Half_Extends_MV);

	 btVector3 vertice = btVector3(0,0,0);


/*   This is where i extract the vertice data from the previously build btBoxShape

 btConvexHullShape* ConvexShape = new btConvexHullShape();
	for (unsigned int vtx = 0; vtx < 8;  vtx++){
		BoxShape->getVertex(vtx, vertice);
		ConvexShape->addPoint(vertice);
	}
	ConvexShape->recalcLocalAabb();
	ConvexShape->initializePolyhedralFeatures();
*/
	



	delete this->mMovement_Objects[0]->GetCollisionObject()->getCollisionShape();
	this->mMovement_Objects[0]->GetCollisionObject()->setCollisionShape(BoxShape); // does not work!
	this->mMovement_Objects[0]->GetCollisionObject()->setCollisionShape(ConvexShape); // works fine!



}


I dont know if someone has ever had this problem, but thanks in advance, i really hope that you guys can help me out here.
Last edited by BeneHei on Thu Mar 15, 2018 11:20 am, edited 1 time in total.
BeneHei
Posts: 2
Joined: Wed Mar 14, 2018 2:59 pm

Re: Updating CollisionShape leads to undetected collisions

Post by BeneHei »

Hey, i found a solution by myself, here is the trick:


Somehow i created the btBoxShape by using a btVector3 with negative values. And Somehow btBoxShapes that where created using negative values are correct in terms of size and are displayed the exact same as btBoxShapes that where created with Vectors that only contain positive values. But i think the internal collision algorithm does not recognize BosShapes that had negative values for the half_extends parameter.


The ConvexHullShape worked out because all the vertices of the Box where computed correctly even though the Box was initialized with values like this:

btBoxShape* shape_bad = new btBoxShape(btVector3(2, -1, 2);

but it should look like this:

btBoxShape* shape_good = new btBoxShape(btVector3(2, 1, 2);


Inside the Debug drawer and by only checking the vertices, shape_good and shape_bad appear exactly the same, but only shape_good is properly recognized by the collision detection.




so remember: Never initialize a BoxShape with a half_extends vector that carries negative values (this should be obvious bc. there is no such thing as negative extends, but when you are building something somewhat "automatically" this can happen :P )



Dont know if this has ever happend to someone or if it is a common mistake, but yeah hope this helps.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: [SOLVED] Updating CollisionShape leads to undetected collisions

Post by Erwin Coumans »

Halfextents needs to be positive values (and sphere radius too etc). Negative mass is also not supported.

In addition, if you make changes to collision shape, you first need to

1) remove the rigid body/collision object from the world,
2) make the changes
3) re-insert the body to the world.
Post Reply