Skip to content

Individual bodies within compounds do not retain pointers to their positions #223

@apsabelhaus

Description

@apsabelhaus

The way that we, and Bullet, treat compound bodies, makes our current implementation of getCenterOfMass() incorrect when rigid bodies are within a compound.

Here's the problem:
When creating a compound in tgcreator, we make a btCompoundShape (of type btCollisionShape), which is then passed as the collision shape when constructing a btRigidBody. This way, btRigidBodies have exactly one collision shape, which is made up of compound shapes, one for each tgRigidBody we've specified.

However, since there's only one btRigidBody within a compound, that means that the getPRigidBody() method for ANY shape within a single compound returns a pointer to the WHOLE btRigidBody. In effect, this means that we've got (for example), tgSpheres, tgRods, tgBoxes, etc. which are different in NTRT but are the same in Bullet Physics.

Practically: when calling getCenterOfMass() from a tgRigidBody, that gets the COM of its btRigidBody. So, when two tgRigidBodies are in a compound, getCenterOfMass() returns the center of mass of the entire compound, NOT each individual element.

Example: make a sphere on a stick, have them auto-compounded, and call getCenterOfMass() on each of them (as tgModels()) anywhere within NTRT. You'll get the same value (the COM of the compound.)

The only way to differentiate between components within a compound is to get the btCollisionShape of the rigid body (for any component), confirm it's a btCompoundShape, and try to get some information out of the child btCollisionShapes that make up that compound. (For the example suggested here - you can call getName() on the children and get back "SPHERE" and "CylinderY.")

This creates major issues with (1) consistency, since it's misleading to have centers of masses within NTRT that don't refer to individual objects, and (2) not seemingly possible to get the COM of each component in a compound.

I tried to pull out each btCollisionShape out of a btCompoundShape, and somehow get its transform with respect to the local frame of the compound (thinking we could call getCenterOfMass() for a compound then transform it individually to each component), but I couldn't seem to get it to work. Somehow, the pointers are all messed up with btCollisionShape's getChildTransform's getOrigin and getRotation methods.

Might try to use the btCompoundShape's calculatePrincipalAxisTransform() method, (https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=&f=&t=11004), to do what we want.

For now, all sensor data for individual bodies, within compound bodies, is BROKEN in NTRT.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions