Bit of a complex and lengthy question that, I'll admit, I don't quite understand very well yet so I will try and explain as best as I can.
Short Version: Is there a general c++/physx formula out there to calculate inertia tensors based off an objects shape?
Long Version: For our physics, we need to specify x, y and z inertia tensors. Currently the way we do it is pretty much just a ratio based off of mass. So if an object is long on the X axis and thin on Y and Z, and the mass is 10000, we will set Z and Y to 7000 and X to 3000. (This isn't exact, but just to give an idea)
This works relatively well but our biggest problem is when there is joint instability somewhere, we have to keep guessing at tensors until we figure out what works best. This can become very time consuming if we have a very big physics simulation and one out of 20+ joints is causing all the others to lose stability.
What I am working on is a function that will take the bounding box of an object and hopefully calculate relatively accurate tensors. I have taken some of the math from http://en.wikipedia.org/wiki/List_of_moment_of_inertia_tensors and made a function that basically works like the following for similar rotations below.
Or if the rotation is on an end, like this:
So, this seems to give me results that are similar to the way we have been doing it, but I dont want to switch to this way without making sure that it will work for general use. Below is the code for my function based on the first image with a cube and center pivot.
NxVec3 CalculateInertiaTensor( VisBoundingBox_cl boundingBox, float m )
{
float width = boundingBox.GetSizeX();
float height = boundingBox.GetSizeZ();
float depth = boundingBox.GetSizeY();
float xTensor = 0.083f * m*(height*height + depth*depth);
float yTensor = 0.083f * m*(width*width + depth*depth);
float zTensor = 0.083f * m*(width*width + height*height);
return NxVec3(xTensor, yTensor, zTensor);
}
I can't guarantee that this is the right way to do it (as the most accurate way is to use the actual shape instead of a bounding box) and i am not very familiar with inertia tensors and the math but it seems to return numbers fairly similar to what we were using. Anyone here happen to know if there is a better way to do this?