Coordinate Space Conversions? Are there any?

Post Reply
Geklmin
Posts: 2
Joined: Sun Jan 14, 2018 12:48 am

Coordinate Space Conversions? Are there any?

Post by Geklmin » Sun Jan 14, 2018 1:40 am

OK. I have done enough OpenGL code to render my meshes at any location in 3D space, using a transformation 4x4 matrix. I can scale, rotate, translate, all the good stuff. Magic.

I can even move my camera around in 3D space, and all that wonderful stuff using some maths from GLM (GL mathematics). I feel like a wizard.

I've set up a basic rendering engine. Practically godlike.
(I even have neat-o rendering effects like shadow maps and point lights and phong shading... Very cool stuff, lots of fun to code.)

I Have not delved into bullet physics yet, but what I need to know before implementing it is whether or not I will have to do any coordinate system conversions, and i'd like to get to know the quirks of converting from bullet to OpenGL BEFORE I start trying to render rigid body objects.

For instance, Does bullet always provide a rigid body object's location from the origin of the coordinate system the collision shape was loaded in, or from barycentric coordinates?

Do I have to load my convex collision hulls into bullet collision shapes (Just bunches of points) in barycentric (Center-of-Mass at origin) coordinates?

In essence, what coordinate system conversions do I need to do for 1) objects to be rendered at the right location in world space when I query a rigid body object's position and 2) objects to have the correct centers of mass

I'm also wondering how the inertia tensors for rigid bodies are generated. If the centers of mass are already computed for a given collision shape, I assume the inertia tensor would be too (Where the inertia tensor would assume uniform density based on whatever mass you picked for the shape)



And one more thing.

Can I use multiple convex hulls for a bullet rigid body object's collision shape?





~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I apologize deeply if my ignorance makes you cringe, All I know how to do is write OpenGL things right now (It's, like, the first visually beautiful thing i've ever done with C++... everything else makes text or files).

I very nearly wrote my own physics engine (As in, i have a rather extensive partial plan complete with pseudocode) to avoid having to learn an existing physics engine. this big batch of CPP files from the repository looks quite... ominous, and whenever I think for any length of time about trying to implement bullet my eagerness to smash my hands into this lovely piece of plastic fades, and I stop being productive, and I go back to doing drugs out the back of the local pub.

User avatar
drleviathan
Posts: 451
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Coordinate Space Conversions? Are there any?

Post by drleviathan » Sun Jan 14, 2018 3:22 pm

The position of the btRigidBody is the position of its center of mass in the simulation-frame.

The points in a btConvexHull are in the local-frame with center of mass at the origin.

The btCollisionShape interface declares that all derived classes must implement: calculateLocalInertia(). Somewhere along the class derivation chain that method must be implemented. Turns out btConvexHullShape gets its implementation from btPolyhedralConvexShape which just computes the interia tensor of a box of uniform density. You can compute the inertia tensor yourself and supply that instead, however Bullet assumes the inertia's eigenvectors align with the cardinal axes of the shape's local-frame, so if you wanted the inertia tensor to be exactly right for some arbitrary convex hull you would have to transform the hull points to make that the case.

You can use a btCompoundShape which is a list of convex sub-shapes with local transforms. In fact, this is the only way to have a concave RigidBody that is dynamic or kinematic. There are other concave shapes (e.g. btTriangleMeshShape, btHeightFieldShape) but they can only be used for static objects.

hyyou
Posts: 89
Joined: Wed Mar 16, 2016 10:11 am

Re: Coordinate Space Conversions? Are there any?

Post by hyyou » Mon Jan 15, 2018 2:05 am

Just want to add some little things to drleviathan's great answer :-
drleviathan wrote:
Sun Jan 14, 2018 3:22 pm
the inertia's eigenvectors align with the cardinal axes of the shape's local-frame
^ btMatrix3x3::diagonalized() will help about this.
drleviathan wrote:
Sun Jan 14, 2018 3:22 pm
In fact, this is the only way to have a concave RigidBody that is dynamic or kinematic. There are other concave shapes (e.g. btTriangleMeshShape, btHeightFieldShape) but they can only be used for static objects.
^ It is consistent with the wiki page : http://www.bulletphysics.org/mediawiki- ... ion_Shapes
:P

Geklmin
Posts: 2
Joined: Sun Jan 14, 2018 12:48 am

Re: Coordinate Space Conversions? Are there any?

Post by Geklmin » Mon Jan 15, 2018 5:20 pm

If object locations are in center of mass coordinates, how do I convert back to model coordinates so I can render the object?

I need to create btCompoundShapes with multiple convex hulls that may not be centered at the origin.

As in, I have a model to render and a collision hull. The coordinate systems of the renderable object and collision hull are the same, and each individual convex hull in my collision hull has its points specified in the coordinate system of the model.



How do I take that information and pack it into a Compound Shape?

Thanks!
-Gek

hyyou
Posts: 89
Joined: Wed Mar 16, 2016 10:11 am

Re: Coordinate Space Conversions? Are there any?

Post by hyyou » Wed Jan 17, 2018 1:53 am

If I remember correctly, there is an official tutorial at FractureDemo> btFractureBody.cpp in the repository.

Post Reply