collision detection without solver

gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

collision detection without solver

Post by gjaegy »

Hi,

First I would like to apologize if my question sounds stupid, I haven't a lot of experience in physic programming...

My company provides image generators (IG) for a simulator. Basically it is a 3D view of the simulated environment. The position of the objects are computed by the simulator software and sent to the IG through a network protocol.

The company developing the simulator would like to get a feedback from the IG when two objects collides. For instance, the simulator sends the position of two cars every second. The 3D interpolate accordingly to recreate a smooth movement. When a collision between these cars is detected by the 3D, it should notify the simulator software.

My first idea was to introduce a physic engine, obviously in order to avoid reinventing the wheel. However in my case, I don't want the physic engine to solve the collisions, only detect them and provide some information (no idea how) about where the collision occurred.

Is that something bullet could handle ? Or does anybody knows a library which would suit my need ?

Thanks a lot for any information !

Greg
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: collision detection without solver

Post by Erwin Coumans »

gjaegy wrote:Is that something bullet could handle ? Or does anybody knows a library which would suit my need ?
Yes, you can use Bullet just for the collision detection (in fact, several game companies use only Bullet for its collision detection). For that, you only need to include LinearMath and BulletCollision libraries. You can safely ignore or delete Bullet/src/BulletDynamics.

Just check out Bullet/Demos/CollisionInterfaceDemo, ConcaveConvexcastDemo etc. You can also just use the regular btDiscreteDynamicsWorld, and switch off collision response.

Hope this helps,
Erwin
gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

Re: collision detection without solver

Post by gjaegy »

Excellent, thanks for the good new. I will have a look at the samples you've mentionned !
gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

Re: collision detection without solver

Post by gjaegy »

In the case I would like to use btDiscreteDynamicsWorld, how can I switch off collision response ?

Also, which method is going to be the fastest ?

It seems using btDiscreteDynamicsWorld would be more flexible, as I could simply re-enable collision response in the case it is needed in the future, no ?

Thanks !
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: collision detection without solver

Post by Erwin Coumans »

btDiscreteDynamicsWorld is derived from btCollisionWorld, so there is not too much difference.

There are several ways to disable collision response. Instead of creating btRigidBody you can create btCollisionObjects, and add those into the world. Those will be static and will not be processed in the response.


I would suggest simply starting with btCollisionWorld, and later upgrade to btDiscreteDynamicsWorld (or btSoftRigidDynamicsWorld if you like to try the new soft bodies).

Erwin
gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

Re: collision detection without solver

Post by gjaegy »

Thanks Erwin. I am currently getting familiar with the API and integrating it into our engine. I will try the different approaches, and might come back for more specific questions later !

Anyway, thanks a lot for your help, I appreciate.

Greg
gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

Re: collision detection without solver

Post by gjaegy »

Hi guys,

I have successfully integrated Bullet into our engine (or actually, started to ;) It is amazing how easy it is, and how realist the result is !! very good job !

I would need you to share your experience, as I am not sure which collision shapes I should use to maximize performances.

So basically, I have two types of objects:
1 - the airport, static. This model is composed of many sub-objects (tower, buildings, trees, ground, etc...), I can collapsed them for the physic mesh
2 - the aircrafts / vehicles, which are composed by 3-10 sub-objects which I can collapse as well.

For 1, I think the best approach would be to use btBvhTriangleMeshShape with mass=0.
However, I am not sure how Bullet handles the shape. I know it uses a tree internally, so I guess the best thing would be to collapse all the objects, and provide bullets with one single list of vertices and one single list of indices for all the sub-objects. Am I right, or should I rather create one shape per object (so one per building, etc...) ? Or rather use a combinaison of convex shapes (using the convex decomposition sample) ?

For 2, I am not sure which is the fastest method. Should I create one concave triangle mesh shape and use GImpact ? Or would it be more efficient to use a combinaison of convex hull shapes (using decomposition as well) ? I have no idea how both approach would perform (performance-wise and quality-wise), so any input would be welcome !!


Other question, should I call the following methods ? If I should, should I do it with all different shape types ? From what I understand it would allow to skip continuous physic computations if objects are isolated enough, right ?

Code: Select all

	// Only do CCD if  motion in one timestep (1.f/60.f) exceeds CUBE_HALF_EXTENTS
	// _vSize is the size of the bounding box
	gjFloat fMinSize = gjMin(gjMin(_vSize.x, _vSize.y), _vSize.z);
	m_pBody->setCcdSquareMotionThreshold(0.5f * fMinSize);

	//Experimental: better estimation of CCD Time of Impact:
	m_pBody->setCcdSweptSphereRadius(0.2f * fMinSize);
Thanks a lot.
wbaldwin
Posts: 14
Joined: Mon Feb 23, 2009 9:01 am

Re: collision detection without solver

Post by wbaldwin »

Erwin Coumans wrote:There are several ways to disable collision response. Instead of creating btRigidBody you can create btCollisionObjects, and add those into the world. Those will be static and will not be processed in the response.Erwin
I know this is a year old post, but I figured I'd toss my question up here anyways.

My goal is much the same as stated above: to create an object which just alerts me of collision (without any physics response) in a world where all other objects have a physical reaction to collision with each other. So in my world of btRigidBodys I created a btCollisionObject, but unfortunately it still responded to collision with other objects. Is there anything that needs to be set or done to a btCollisionObject to assure that it is not influenced by collision?
gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

Re: collision detection without solver

Post by gjaegy »

Hi,

I solved my issue by overriding the btCollisionDispatcher::needsCollision() method. I added a method Set/GetNeedCollisionResponse() to my hi-level physic objects (which are stored as user pointers at the boCollisionObject level). In the btCollisionDispatcher::needsCollision() method I test whether one of the body doesn't need response, in which case I return false.

I hope this helps.

cheers,
Greg
wbaldwin
Posts: 14
Joined: Mon Feb 23, 2009 9:01 am

Re: collision detection without solver

Post by wbaldwin »

Ok, so this is what I have:

Code: Select all

struct TempCallback : public btDynamicsWorld::ClosestConvexResultCallback
{
	TempCallback(const btVector3&	convexFromWorld,const btVector3&	convexToWorld)
		: ClosestConvexResultCallback( convexFromWorld, convexToWorld )
	{
		;
	}
	
	std::vector<btCollisionObject*> mHits;
	
	btScalar addSingleResult( btDynamicsWorld::LocalConvexResult& convexResult, bool normalInWorldSpace )
	{
		mHits.push_back( convexResult.m_hitCollisionObject );
		
		return ClosestConvexResultCallback::addSingleResult( convexResult, normalInWorldSpace );
	}
};

bool bResult( false );

float fOffsetHeight( 5000.0f );
btTransform	startTransform, endTransform;

btVector3 vStart( rvPosition.x, rvPosition.y + fOffsetHeight, rvPosition.z );
btVector3 vEnd( rvPosition.x, rvPosition.y - fOffsetHeight, rvPosition.z );

startTransform.setIdentity();
endTransform.setIdentity();

startTransform.setOrigin( vStart );
endTransform.setOrigin( vEnd );

btConvexShape *pColShape = new btSphereShape( btScalar( fRadius ) );

TempCallback res( vStart, vEnd );
res.m_collisionFilterGroup = nBitGroup;
res.m_collisionFilterMask = nBitMask;

g_World->convexSweepTest( pColShape, startTransform, endTransform, res );

for( std::vector<btCollisionObject*>::iterator iter = res.mHits.begin(); iter != res.mHits.end() ; ++iter )
{
	btCollisionObject *pPitObj = (*iter);
	
	// ユーザーポインタ内のデータをチェック
	
	bResult = true;
}
SAFE_DELETE( pColShape );

// 結果をリターン
return bResult;
Just trying to create the shape, then test it for hits in my world. Anyone know what could be the problem?