Center of Mass Question

Started by
1 comment, last by TheAdmiral 16 years, 11 months ago
So I am programming a 3D physics engine and I have a question about which way I should determine the center of mass of a body. Background info: I handle bodies as a collection of shapes, and each shape has its own mass, mu, e, inertia tensor, etc.. Which way should I do this? 1. center of mass is the "position" of a body in world coordinates. When shapes are added to the body, they are positioned in body coordinates. The center of mass does not change. The problem with this is that its not the most accurate way to do things (the center of mass is not where it should be). But, it is easy to do and makes it easier for the user to superimpose visuals on top of bodies. 2. center of mass is the "position" of a body in world coordinates. When shapes are added to the body, the center of mass of the body is calculated and the body's world "position" is moved relative to the center of mass vector (transformed into world coordinates of course). The shapes in body coordinates are translated by the negative center of mass. The effect of this is that the shapes appear stationary, while the center of mass moves. This option is much more realistic but I worry that it will make actual use of the engine harder. This is because the "position" of the body moves around as shapes are added, making it hard to synchronize visuals. A solution to this problem is that I could have 2 positions for a body, one of its visual position (the one used by the user, doesn't change relative to the center of mass (except when adding a shape)) and another for its center of mass (used by the physics engine for calculations). The disadvantage is that this could be tricky, especially in keeping track of the visual position (performing the necessary transformations relative to the center of mass). what do you guys think about this?
Advertisement
I think each object should have its own meaningful center (for positioning purposes) and a calculated center of mass for physics purposes. This would allow for accurate physics and prevent weird bugs, like objects moving when their CM changes. I don't think transformations or rotations should be a problem, as it should be clear in each case which center they involve. Physics calcs always use the CM, object placement uses the meaningful center position.
Ra
What's wrong with using both?

Each object and object-component has a position, a mass, and a centre of mass. When you attach the components, you recalculate the object's COM by weighted-averaging the component COMs; and the position by whatever fits best.

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.

This topic is closed to new replies.

Advertisement