[SOLVED] Length, width, and height of a rigid body.
[SOLVED] Length, width, and height of a rigid body.
I know how to get the collision sphere radius and offset using getBoundingSphere, but is there a way to get the XYZ sizes of a rigid body model? That would include the XYZ lengths and center offsets.
Last edited by Crayder on Sun Aug 23, 2015 4:46 pm, edited 1 time in total.
Re: Length, width, and height of a rigid body.
If you mean the axis-aligned bounding box and the center of mass, then yes.
For the AABB, there is btCollisionShape::getAabb.
The center of mass is always (0,0,0) in local coordinates of any collision shape. In world coordinates, this is the world transform of the body (see btRigidBody::getCenterOfMassPosition). An exception to this is compound shapes, where child shapes have an offset.
For the AABB, there is btCollisionShape::getAabb.
The center of mass is always (0,0,0) in local coordinates of any collision shape. In world coordinates, this is the world transform of the body (see btRigidBody::getCenterOfMassPosition). An exception to this is compound shapes, where child shapes have an offset.
Re: Length, width, and height of a rigid body.
Not exactly what I'm looking for.anthrax11 wrote:If you mean the axis-aligned bounding box and the center of mass, then yes.
For the AABB, there is btCollisionShape::getAabb.
The center of mass is always (0,0,0) in local coordinates of any collision shape. In world coordinates, this is the world transform of the body (see btRigidBody::getCenterOfMassPosition). An exception to this is compound shapes, where child shapes have an offset.
About the center of mass being (0,0,0), that is false. Not every rigid body's center is (0,0,0).
I'll have to get a picture of what I'm trying to say to explain about the lengths, I'll edit this in a sec.
EDIT:
Say that the (0,0,0) of that world was the center of the object by definition. The center offset would not be (0,0,0), it's be like (1.5,0.75,-1.0). The lengths would be the total length of each side. Basically the lengths would be the edges of the bounding box shown in that picture.
Re: Length, width, and height of a rigid body.
By definition the center of mass for any rigid body is at the local coordinates of (0,0,0). As anthrax11 stated, you can find the bounding box of the object from it's AABB, and that will give you the effective size. Simply load your mesh at the default orientation and calculate the AABB, and you'll have the dimensions you are requesting. If your mesh is not defined with the center of gravity at (0,0,0), you'll have to either redefine the mesh or recalculate the dimensions using an offset.Crayder wrote: About the center of mass being (0,0,0), that is false. Not every rigid body's center is (0,0,0).
Re: Length, width, and height of a rigid body.
Ok I guess I understand now. Now though, I've run into a new problem.Basroil wrote:By definition the center of mass for any rigid body is at the local coordinates of (0,0,0). As anthrax11 stated, you can find the bounding box of the object from it's AABB, and that will give you the effective size. Simply load your mesh at the default orientation and calculate the AABB, and you'll have the dimensions you are requesting. If your mesh is not defined with the center of gravity at (0,0,0), you'll have to either redefine the mesh or recalculate the dimensions using an offset.Crayder wrote: About the center of mass being (0,0,0), that is false. Not every rigid body's center is (0,0,0).
getAabb is returning nothing but 0's...
Here are two functions I have. The sphere one works perfectly fine, but the box is returning 0's (as I said above, it's because of getAabb).
Code: Select all
int ObjectManager::getBoundingSphere(uint16_t modelid, btVector3& center, btScalar& radius)
{
uint16_t colindex = ModelRef[modelid];
if (colindex != 65535)
{
colObjects[colindex]->getCompoundShape()->getBoundingSphere(center, radius);
return 1;
}
return 0;
}
int ObjectManager::getBoundingBox(uint16_t modelid, btVector3& min, btVector3& max)
{
uint16_t colindex = ModelRef[modelid];
btTransform t;
if (colindex != 65535)
{
colObjects[colindex]->getCompoundShape()->getAabb(t, min, max);
return 1;
}
return 0;
}
Re: Length, width, and height of a rigid body.
The transform should be initialized to the identity transform, meaning no rotation (or translation).
Just to clarify, the fact that (0,0,0) is the center of mass (COM) is an assumption that bullet makes. The actual COM could be different, but then you'd need to either adjust the model so that the COM matches the model origin or use a compound shape. There is no function in bullet to calculate the exact COM of an arbitrary user-defined shape, so you have to find it yourself. The center of the AABB is usually a good estimate.
See also: http://www.bulletphysics.org/Bullet/php ... php?t=2209
Code: Select all
btTransform t;
t.setIdentity();
See also: http://www.bulletphysics.org/Bullet/php ... php?t=2209
- drleviathan
- Posts: 849
- Joined: Tue Sep 30, 2014 6:03 pm
- Location: San Francisco
Re: Length, width, and height of a rigid body.
And if you want to compute the center of mass of an arbitrary mesh shape yourself here is some code for doing that (from this thread).
Re: Length, width, and height of a rigid body.
Thanks guys, adding setIdentity solved the problem.
Re: Length, width, and height of a rigid body.
Pretty sure most realtime physics engines do that, it's much cleaner mathematically as all linear velocity changes are simple additions and almost the same with angular velocity (rather than having to do a full matrix multiplication for each and every change).anthrax11 wrote: Just to clarify, the fact that (0,0,0) is the center of mass (COM) is an assumption that bullet makes.
Defining objects with a geometric mean different than it's center of mass is a drag, but at least it's easier to keep track of both if you define one as (0,0,0)