Getting the dimensions of collision objects

Please don't post Bullet support questions here, use the above forums instead.
YAN3
Posts: 11
Joined: Fri May 07, 2010 2:18 pm

Getting the dimensions of collision objects

Post by YAN3 »

Hello everyone. I'm knew to bullet and I have a small problem. I'd like to read all the objects a certain collision world and then figure out what shapes they are and what are their sizes (dimensions).

To get the objects, I use:
btCollisionObjectArray myObjects = collisionWorld->getCollisionObjectArray();

And to figure out what shape an object is, I use:
cout<<"Collision shape: "<<myObjects->getCollisionShape()->getName()<<endl;

The problem is that I can't find a way to retrieve the dimensions of the object. For example, if it is a BOX collision shape, is there anyway to get the width, depth, and height of that box? Thanks a lot.

Best regards,
Nick
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: Getting the dimensions of collision objects

Post by Dirk Gregorius »

I think Bullet has a type system. So you get the type and then cast down the hierarchy:

if ( shape->getType() == BOX )
Box* box = static_cast< Box* > ( shape );
Vector3 e = box->getHalfExtents();

if ( shape->getType() == SPHERE )
Sphere* sphere = static_cast< Sphere* > ( shape );
float radius = sphere->getRadius();

Note this is only conceptual, but Bullet should have very similar functions.


Cheers,
-Dirk