Inertia tensor

HerrUppoHoppa

12-04-2007 12:34:14

Dear fellow code monkeys, :wink:

I'm currently working on a research project where I'm conjuring up a technique for animating ragdolls.

I have run into the problem that I need the inertia tensor of the rigid bodies making up the ragdoll. It seems however that there currently is no way to do this in OgreOde even though ODE permits it. Currently I am about to make a getter function in OgreOde::Mass to retrieve the inertia matrix.

I would like for someone to tell me that I have overlooked some member function somewhere that already does this so I don't need to recompile OgreOde. If not, is there really any good reason not to allow this?

Sincerely,
Pontus

rewb0rn

13-04-2007 09:49:26

OgreOde is work in progress, so its possible that noone has done it yet. Post your results here and hopefully tuan will add it to cvs :)

HerrUppoHoppa

13-04-2007 11:17:49

Alright, well I'll post the code and hope for some feedback. I'm not sure as to the matrix convention differences between Ogre and ODE though. If you happen to notice that I screwed up the matrix conversion please say so.

OgreOdeMass.h

namespace OgreOde
{
class _OgreOdeExport Mass
{
friend class Body;

public:
....


Ogre::Matrix3 getLocalInertiaTensor() const;
.....
};


OgreOdeMass.cpp

Ogre::Matrix3 Mass::getLocalInertiaTensor() const
{
return Ogre::Matrix3( _mass.I[0], _mass.I[3], _mass.I[6],
_mass.I[1], _mass.I[4], _mass.I[7],
_mass.I[2], _mass.I[5], _mass.I[8]);
}

HerrUppoHoppa

15-04-2007 23:23:09

I think the code above is bad, don't use it until further notice.

The following quote I took from the ODE user manual, chapter 14.1. Matrix storage conventions : http://www.ode.org/ode-latest-userguide.html#sec_14_1_0.
Matrix operations like factorization are expensive, so we must store the data in a way that is most useful to the matrix code. I want to do 4-way SIMD optimizations later, so the format is this: store the matrix by rows, and each row is rounded up to a multiple of 4 elements. The extra "padding" elements at the end of each row/column must be set to 0. This is called the "standard format". Hopefully this decision will remain good in the future, as more and more processors have 4-way SIMD (especially for fast 3D graphics).

This kind of says that the indexing is wrong, according to my amazing lin.alg. knowledge I think it should be like this.

OgreOdeMass.cpp
Ogre::Matrix3 Mass::getLocalInertiaTensor() const
{
return Ogre::Matrix3( _mass.I[0], _mass.I[1], _mass.I[2],
_mass.I[4], _mass.I[5], _mass.I[6],
_mass.I[8], _mass.I[9], _mass.I[10]);
}


I'd like some comments on it though.