Hello Everyone!
As a programing exercise, I am writing a program to load a custom file into bullet. I would also like to store the information. Kinda like a level loader/saver.
The loader part works great. What's got me stumped is how to save the size of my objects. As I want to let the user enter values, I do not have measurements on hand. I do, however, have the collision shapes, although I won't know what kind they are(btSphereShape, btBoxShape, etc). I will only have the standard collision shapes.
Is there any way to extract size information, such as radius and extents from a collision shape?
Thanks in advance!
ryan0618
Collision Shape Statistics
-
- Posts: 169
- Joined: Sun Jan 14, 2007 7:56 pm
- Location: Norway
Re: Collision Shape Statistics
Hi Ryan,
yes there are two methods you can use, take a look in btCollisionShape.h:
In your case, I think the bounding sphere version is what you are looking for. It uses the other getAabb function to calculate the center and radius.
For the getAbb function, do the following to get the proper bounding box:
Cheers,
Ola
yes there are two methods you can use, take a look in btCollisionShape.h:
Code: Select all
///getAabb returns the axis aligned bounding box in the coordinate frame of the given transform t.
virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const =0;
virtual void getBoundingSphere(btVector3& center,btScalar& radius) const;
For the getAbb function, do the following to get the proper bounding box:
Code: Select all
btTransform t;
t.setIdentity();
btVector3 aabb_min, aabb_max;
shape->getAabb(t,aabb_min, aabb_max);
Ola
-
- Posts: 9
- Joined: Sun Mar 29, 2009 10:27 pm
Re: Collision Shape Statistics
Thanks for the help!
Unfortunately, that approach will only work for spheres. I have spheres and boxes that I would like to save. Is there any way to get the box extents. As I understand it, aabb is only aligned one way, which would prevent me finding the values if they are rotated. Correct?
Thanks in advance
ryan0618
Unfortunately, that approach will only work for spheres. I have spheres and boxes that I would like to save. Is there any way to get the box extents. As I understand it, aabb is only aligned one way, which would prevent me finding the values if they are rotated. Correct?
Thanks in advance
ryan0618
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Collision Shape Statistics
You can use the btCollisionShape::getShapeType() method, and do an upcast to the specific class, and get access to any data you need.
See src\BulletCollision\BroadphaseCollision\btBroadphaseProxy.h for all shape types.
Hope this helps,
Erwin
See src\BulletCollision\BroadphaseCollision\btBroadphaseProxy.h for all shape types.
Hope this helps,
Erwin
-
- Posts: 9
- Joined: Sun Mar 29, 2009 10:27 pm
Re: Collision Shape Statistics
Perfect! thanks for the help.
EDIT: Now I am having a similar problem with mass. Where would I get the mass? from the btrigidbody? I feel like the amswer is staring me in face and I just can't see it .
Thanks in advance,
ryan0618
EDIT: Now I am having a similar problem with mass. Where would I get the mass? from the btrigidbody? I feel like the amswer is staring me in face and I just can't see it .
Thanks in advance,
ryan0618
-
- Posts: 5
- Joined: Sat Apr 04, 2009 7:25 am
Re: Collision Shape Statistics
1.0 / btRigidBody::getInvMass() should do the trick. FYI, the doxygen generated documentation (you'll probably want to look up btRigidBody and btCollisionShape) is available here : http://www.continuousphysics.com/Bullet ... index.html.
-
- Posts: 9
- Joined: Sun Mar 29, 2009 10:27 pm
Re: Collision Shape Statistics
Thanks for the tip. Unfortunately, that method returns the inverse mass, or 1/mass. Now, it is a simple matter to convert that to the mass using 1/inverse, but I wish there was a more direct method.
ryan0618
ryan0618