Strange effect of cylinder nested inside a compound shape...

allsey87
Posts: 33
Joined: Fri Oct 26, 2012 1:50 pm

Strange effect of cylinder nested inside a compound shape...

Post by allsey87 »

Hi All,

I'm using compound shapes in my simulation to position both single and multi-body objects relative to the point where they touch the ground. In this example (see the attached BasicDemo.cpp) I have created a cylinder using a cylinder collision shape, which is nested inside a compound shape with a transformation of the half height in the upwards (Y) direction, i.e. so that (0,0,0) point inside the compound shape is where the cylinder touches the ground.

The compound shape is behaving as expected with the exception of one little thing, the shape has a very unusual bias to stand upright, even if it is almost lying completely on its side, as much as 80 degrees! I believe that this might have something to do with the inertia of the compound shape, although I'm really not sure. I have tried calculating the inertia from both the compound shape and also the base cylinder shape, and get visually identical results. I have put a video of this bug on youtube that you can watch.

Please see the attached BasicDemo.cpp, and let me know if this bug is also present on your system/configuration.

All the best,

allsey87
You do not have the required permissions to view the files attached to this post.
STTrife
Posts: 109
Joined: Tue May 01, 2012 10:42 am

Re: Strange effect of cylinder nested inside a compound shap

Post by STTrife »

When I messed around with compound shapes quite a while ago, I remember I had to calculate the center of gravity myself first, then change the local coordinates off all child shapes, so that (0,0,0) coincides with the center of gravity. So if for example you'll find the center of gravity at (0,2,2) in local coordinates, you need to substract (0,2,2) from the local position of all child shapes first. Then you need to call the function that (re)calculates the inertia to make sure that is correct also.

If I did not do these steps I would also get incorrect 'rotational behavarior'... but I must say it was quite a while ago, I hope I remember correctly :)
allsey87
Posts: 33
Joined: Fri Oct 26, 2012 1:50 pm

Re: Strange effect of cylinder nested inside a compound shap

Post by allsey87 »

Hi STTrife,

Thanks for answering, although I'm having a little trouble understanding your response. Could you clarify when you are referring the local coordinate system, whether you mean a/ 'the local coordinate system of the child shape' or b/ 'the local coordinate system of the compound shape' ?

Cheers,

allsey87
allsey87
Posts: 33
Joined: Fri Oct 26, 2012 1:50 pm

Re: Strange effect of cylinder nested inside a compound shap

Post by allsey87 »

Actually in retrospect, I understand exactly what you are saying. Basically you need to position the all the objects within the child shape such that the centre of gravity occurs at 0,0,0 with respect to the coordinate system of the compound shape.

Unfortunately, if this is the only way of solving this problem, it means the solution regarding using compound shapes to change the reference points of compound objects fails, due to the centre of gravity being forced to 0,0,0...
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Strange effect of cylinder nested inside a compound shap

Post by Flix »

I remember this point has already been discussed in many forum posts over the years, so you can search the forum to get further info, but basically:

1) the center of mass of the body is placed in (0,0,0) and this is true for both compound shapes and convex hull shapes (i.e. if you create a convex hull shape with vertices centered in (10,10,10), the center of mass will stay at (0,0,0), producing a center of mass offset).
2) You can exploit this fact to create bodies with a center of mass offset (as noted above and like you unintentionally did).
3) One way to simplify this issue if to create bodies with center of mass centered in the geometric center, and embed them in one (or another) compound shape to add a center of mass offset to them.

Please note that depending on how you draw the geometry, you may need to embed a "graphic offset" in the body motion state (in the Bullet Demos (libBulletOpenGL) this is not necessary, but remember that you get/set the body position in its (0,0,0) point, not in the body geometric center).

I still suggest you to search the forum for further info.
STTrife
Posts: 109
Joined: Tue May 01, 2012 10:42 am

Re: Strange effect of cylinder nested inside a compound shap

Post by STTrife »

allsey87 wrote: Unfortunately, if this is the only way of solving this problem, it means the solution regarding using compound shapes to change the reference points of compound objects fails, due to the centre of gravity being forced to 0,0,0...
Must say I don't fully understand what you mean with using compound shapes to change the reference points of compound objects. What exactly is your goal? There problably is some workaround, but I'm not sure sure what you are trying to accomplish or what the problem is.

In general: I also have a project where I just add child-shapes whereever I want, in a way which is logical for my game, but right before it's added to the bullet world, it will offset all child shapes to make the COG correct, but also it remembers how much offset was used, so the original positioning is saved too and can be reused.

Cheers,

STTrife