what is the purpose of those methods ?

Post Reply
gokoon
Posts: 9
Joined: Fri Jan 27, 2012 10:57 am

what is the purpose of those methods ?

Post by gokoon »

All I want is collisions between many object (no more than about 30), no dymamics. I'm currently using btOgre, and since I'm just using simple shapes like sphere and boxes, it doesn't bring a lot.

I'm currently trying to understand this demo: http://code.google.com/p/bullet/source/ ... ceDemo.cpp
Can somebody explain what are those classes/struct/methods for, and how I can inherit and/or overrides some functions to use to my liking, there are several alternatives which I don't understand the meaning.

Code: Select all

btCollisionWorld::ContactResultCallback::addSingleResult(...)
and

Code: Select all

btCollisionWorld::ContactResultCallback::needsCollision(...)
I can understand what a callback is, I just don't really get what are those function's arguments, and the doc doesn't tell much. I guess that in

Code: Select all

virtual	btScalar	addSingleResult(btManifoldPoint& cp,	const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1)
colobj are the object which collided, index are their position in CollisionWorld::getCollisionObjectArray(), but what about partId ? I'd like to know if I'm right about the index, since it help for how I manage my object in Ogre3D.

I see many #ifdef and I'm a little confused when reading CollisionInterfaceDemo.cpp, I'm having a hard time figuring things out.

Thanks again in advance for reading this and providing help !
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm
Contact:

Re: what is the purpose of those methods ?

Post by dphil »

Yes, the 2 collision object parameters in addSingleResult are 2 objects that are detected to be colliding. The "index" parameter for each object is the index of the specific triangle in contact, if the object's shape is a triangle mesh (ex. btTriangleMeshShape). The partId refers to the part of the mesh involved, if the object's shape is, again, a triangle mesh shape. This is the same data you'll find in LocalShapeInfo, which is used in ray tests, for example.

This wiki page might also shed a little light on the ContactResultCallback functions: http://bulletphysics.org/mediawiki-1.5. ... ontactTest
kloplop321
Posts: 55
Joined: Sun Jan 01, 2012 7:37 pm

Re: what is the purpose of those methods ?

Post by kloplop321 »

You don't even need to use all of what is in the demo for requirements like that.

But to answer your question

Code: Select all

btCollisionWorld::ContactResultCallback::addSingleResult(...)
This adds a result to a Contact result structure which you can get information from later.
The manifold point is where the contact happens (I believe). Aside from the bodies, the other parameters are mainly for internal use. You are only supposed to read these as a user, not write them.

Code: Select all

btCollisionWorld::ContactResultCallback::needsCollision(...)
This will tell whether or not it is colliding, so for a dynamics world, it will know that it needs to process that there is a collision taking place which should be handled.
A broadphase proxy is what calculates if further collision detection is required, that is why it is a parameter.
gokoon wrote: I can understand what a callback is, I just don't really get what are those function's arguments, and the doc doesn't tell much. I guess that in

Code: Select all

virtual	btScalar	addSingleResult(btManifoldPoint& cp,	const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1)
colobj are the object which collided, index are their position in CollisionWorld::getCollisionObjectArray(), but what about partId ? I'd like to know if I'm right about the index, since it help for how I manage my object in Ogre3D.

I see many #ifdef and I'm a little confused when reading CollisionInterfaceDemo.cpp, I'm having a hard time figuring things out.

Thanks again in advance for reading this and providing help !

Code: Select all

#if 0
...
#endif
basically comments out the code they did, which can be re-enabled easily by just switching the 0 to a 1.
The compiler just skips over those sections.

Code: Select all

#ifndef TEST_NOT_ADDING_OBJECTS_TO_WORLD
can be read as

Code: Select all

if NOT defined TEST_NOT_ADDING_OBJECTS_TO_WORLD then ...
It means that when the compiler doesn't know anything about TEST_NOT_ADDING_OBJECTS_TO_WORLD existing, use the following code.

Its likely just parts left over by the developer as they were writing the program. Ultimately trust what cmake or the make file tells the compiler to use regarding these definitions.
gokoon
Posts: 9
Joined: Fri Jan 27, 2012 10:57 am

Re: what is the purpose of those methods ?

Post by gokoon »

I managed to get collisions working without using those callbacks, so to be clear, in what situation would I need to use those callbacks and those 2 methods I asked above ?

Are they useful to get some info about the concerned triangle ?
I'm also doing some basic raycasting, I want to know the coordinate where my ray hits, do I need to use callbacks, needsCollision() or addSingleResult() ?
Post Reply