Compound collision and center of mass

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Compound collision and center of mass

Postby Julio Jerez » Thu Jul 26, 2012 11:59 am

wow I realize that this function is misleading NewtonConvexCollisionCalculateInertialMatrix
basically that function calculate inertia relative to the origin of the shape, but that is not right. this is only correct when the center of mass and the origin of a body coincide.

here is an example say we have a big centered at the of the box.
function NewtonConvexCollisionCalculateInertialMatrix will give the Initia of a box with cent at the origin and the is correct.

now let us say the box has an origin at the lower bottom, the above function will report the inertia of a box with origin and the bottom and the origion at the lower bottom.
but the could be a problems if it si use wrong.

if we set the body cog at the center of the box, the above inertia is correct, but if we set the center at the origin reported by function NewtonConvexCollisionCalculateInertialMatrix
the this is a body that just happen to be a graphics origin different that the inertia center, but it inertia should be the inertia of a centered box.
when I set this I get it right, however I can how this can lead to many error

I will remove that function all together. and instead the inertia of the shape will allay be a property of the shape calculate at the time of creations.

The shape will have a Get Origin function in the shape, that can be use to set the COG of the body.
but the COG of a body can be set to any other value, if the user chooses to do so.

Then NewtonCalculateInertialMatrix will be a function of the Body that will calculate the inertia using the local inertia volume integral of each sub shape and build total instead using the central theorem for calculation offset inertia. This will be right in all cases all the time

I will do this two steps.
first complete changing the scale from global to local and check in. (almost ready)
then go over the inertia calculation.
and I will also add a density to the shape, so that the inertia takes that into account for heterogeneous mass distribution of inertia of compound collisions.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Compound collision and center of mass

Postby PJani » Thu Jul 26, 2012 12:26 pm

Nice!!! Can't wait :D
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
User avatar
PJani
 
Posts: 448
Joined: Mon Feb 02, 2009 7:18 pm
Location: Slovenia

Re: Compound collision and center of mass

Postby Sweenie » Thu Jul 26, 2012 4:29 pm

wow I realize that this function is misleading NewtonConvexCollisionCalculateInertialMatrix


Is this something that started since the collisions became instanced based?

Because recently I realized that my bodies have been acting a bit weird. Slower falling and wobbling alot more.
Just to test this I checked out an earlier revision(rev 1200) before the collisions became instance based then I ran the exactly same scene with revision 1200 and then with revision 2347.
There is a big difference... --> Inertia test
After I recorded that movie I checked the inertia values of the bodies...

With revision 1200 the values are(as calculated by NewtonConvexCollisionCalculateInertialMatrix)
Code: Select all
Tall compound body = 1.758f   1.743f   0.247f
Small compound body = 0.262f   0.209f   0.267f


With revision 2347 the values are
Code: Select all
Tall compound body = 12.422f   12.406f   1.687f
Small compound body = 1.702f   1.649f   1.707f


The calculated inertia is much larger with rev 2347

The only changes I did with the code between the two revisions was to replace NewtonDestroyCollision with NewtonReleaseCollision
Sweenie
 
Posts: 503
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Compound collision and center of mass

Postby PJani » Thu Jul 26, 2012 5:14 pm

Yep i got the same filling like bodies are acting strange when resting and other stuff!
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
User avatar
PJani
 
Posts: 448
Joined: Mon Feb 02, 2009 7:18 pm
Location: Slovenia

Re: Compound collision and center of mass

Postby Julio Jerez » Thu Jul 26, 2012 6:03 pm

yes this starter happenning with the collision instance.
if the origin of the body is zero and the offset matrix does no rotate the body it is be fine.
but otherwise it is not.
This was working in core 200 because the shape do no have scale, bu I suspect that teh trnasform modifiec will have similar errors.

I noticed when I made a cone rotate 90 degree so that it is upright. afte doin that I notice that i wobble, and tha is becaus ethe Inertal is rotated. and shoudl no be. I will solver it all this weekend.

basically the inertia will be a fix property of the shapes regaless of oriention and scale.
the body sodul so teh convetion base on teh fix values and the body CG.

The body soudl also have a general 3 x 3 inertia tensor, we no loger can asume that a body will be centered at the origin and the ofsset matrix will diginalize the inerta. Instead the diagonal ineratia will be a shape prorperty and the body will have it genrale 3 x 3 inertation.
The engone every where does that calculation asuming general ineratin, so thsi si just chengine teh inerat type form vetc to matis and compiel all eh compile error.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Compound collision and center of mass

Postby Julio Jerez » Fri Jul 27, 2012 10:54 am

I think I made the conversion to use local scale onle now. I thin there is a bug with when using no uniform scale on static meshes.
I beleive is the normal calculation, I did no write the math to make the changes I did it by intuition and I think I have a normal rotated wrong somewhere
people rare use non uniform scale mesh so I will debug that later. I will wait unti better test case in made.

I run this for soem time before check in. and Tomorrow I will fix the inertia calculation.

Maybe now is a good time to make more progress on the visual debugger, I had a hacked pseudo movie by saving the key and mouse strokes,
but after I switch from asyncronuskey to the GUI input functions, it is not longer deterministic and that makes it hard to find bugs.
I am sick and tired of hacking so much to find bugs, I need to complete the debbuger so that I can save movies tna can be replay later.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Compound collision and center of mass

Postby Julio Jerez » Fri Jul 27, 2012 2:17 pm

Oh after debugging I think I fond the culprix of the Bug with the inertia. It is not the inertia taht is wrong it is the local center of mass.

The best shape to reproduce this but is the cone. becaus the cone is the only convex shape that do no have teh oring at location 0,0,0
so if you take a cone and you rotate the locat matrix, the cone wobble when it should no,
this because the local origin is still point along the x vector.
this is because the local origin is generated in teh loca space of the shape but it should be in the global space of the shape.

This is all a mess now, but I will correct this weekend.

and yes this happened with the introduction of the collision intance.
anyway I know what the bug is now and I will fix it and improve it as well.

basciall teh funtion NewtonSetMassmatrix well be shage to.
NewtonSetMassmatrix (mass, Ixx, Iyy, Izz)
will shange to
NewtonSetMassmatrix (mass, collison)

the function set center of mass will be removed

this will solve all prooblems, when teh end user use the body shape teh center will be alway what it soudl be.
but if the user wants to set a different local origin, or inertia he can use a different collision as an auxiliary helper.
I will make a demo for demotrations.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Compound collision and center of mass

Postby PJani » Fri Jul 27, 2012 3:03 pm

That would be much better because i am sometimes confused
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
User avatar
PJani
 
Posts: 448
Joined: Mon Feb 02, 2009 7:18 pm
Location: Slovenia

Re: Compound collision and center of mass

Postby Julio Jerez » Sat Jul 28, 2012 5:21 pm

Ok I check in a bunch of changes

convert to local scale only for collision instances.
Still need to go over compound collision.

also deprecated function (for now, later I will re enable them again)
Code: Select all
void  NewtonBodySetCentreOfMass___ (const NewtonBody* const body, const dFloat* const com);
void  NewtonBodySetMassMatrix___ (const NewtonBody* const body, dFloat mass, dFloat Ixx, dFloat Iyy, dFloat Izz);

instead now we use
Code: Select all
void NewtonBodySetMassProperties (const NewtonBody* const body, dFloat mass, const NewtonCollision* const collision);

when using the same collision assigned to the body this is a perfect body with Center of mass at the center of the collision
this is the most common use.
For setting inertia decoupled from the center of mass the using can use and auxiliary collision shape.

I still need to work on the compound, but I do that later.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Compound collision and center of mass

Postby Julio Jerez » Sun Jul 29, 2012 8:21 am

there is still a bug when using non uniform scale. my hacked replay is not deterministic, and that makes it imposible to debug.

what I am going to to if to complete the compound collision first, and this comming week avance the visual debugger to debug that problem.
This is a very big bug that I did not notice before, but tha was not ther before the collision instance.
anyway I put the rest on hold, and andvance the visual debugger so tah I can make movies that can faithfully reproduce bugs and allow inspection of the scene.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Compound collision and center of mass

Postby Julio Jerez » Sun Jul 29, 2012 10:01 am

al right compound collision usin local scale is in.
The cool thing is that now the inertal is calculate in liniar time, whi men is can be use at runtime at will for compounds

There is no convex shape densitity yet, I do no wnat fo ad that element yet bofere I complete debug the bug.
but teh density si very eassy to add. bascially in theis funtion that compuet an inerat of a solid base on teh center of mass and teh inertia relative to teh center of mass

Code: Select all
void dgCollision::MassProperties ()
{
   // using general central theorem, to extract the Inertia relative to the center of mass
   //IImatrix = IIorigin + unitmass * [(displacemnet % displacemnet) * identityMatrix - transpose(displacement) * displacement)];
   //IIorigin = IImatrix - unitmass * [(displacemnet % displacemnet) * identityMatrix - transpose(displacement) * displacement)];

   dgMatrix inertia (dgGetIdentityMatrix());
   inertia[0][0] = m_inertia[0];
   inertia[1][1] = m_inertia[1];
   inertia[2][2] = m_inertia[2];
   inertia[0][1] = m_crossInertia[2];
   inertia[1][0] = m_crossInertia[2];
   inertia[0][2] = m_crossInertia[1];
   inertia[2][0] = m_crossInertia[1];
   inertia[1][2] = m_crossInertia[0];
   inertia[2][1] = m_crossInertia[0];

   dgVector origin (m_centerOfMass);
   dgFloat32 mag = origin % origin;

   dgFloat32 unitMass = dgFloat32 (1.0f);
   for (dgInt32 i = 0; i < 3; i ++) {
      inertia[i][i] -= unitMass * (mag - origin[i] * origin[i]);
      for (dgInt32 j = i + 1; j < 3; j ++) {
         dgFloat32 crossIJ = unitMass * origin[i] * origin[j];
         inertia[i][j] += crossIJ;
         inertia[j][i] += crossIJ;
      }
   }

   m_inertia[0] = inertia[0][0];
   m_inertia[1] = inertia[1][1];
   m_inertia[2] = inertia[2][2];
   m_crossInertia[0] = inertia[2][1];
   m_crossInertia[1] = inertia[2][0];
   m_crossInertia[2] = inertia[1][0];
}


you can see the variable unitMass, to add shape dentity all we need to do is to replace unitMass by and argumen to teh function, and replace all teh place forme whe the function is called.
whne teh shape is a single shapem, teh interia is teh same regarless of the dentity, but when teh shape is part of a compound. the calling code keep the sum of the mass by adding
mass += shapeDentity * shapeVolume);
and the deviding by the final mass. That will automallically consider eterognerus mass distribution for compound collsion.

but fo now let me fidn out tha collision bug.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Compound collision and center of mass

Postby Julio Jerez » Mon Jul 30, 2012 9:38 am

Ok I think I got it to teh point that is was before.
however I end up with a seriues function that are osolete and confusing. I will refacter it so that the class only have one, function

Code: Select all
   virtual void MassProperties ();
   virtual dgFloat32 CalculateMassProperties (const dgMatrix& offset, dgVector& inertia, dgVector& crossInertia, dgVector& centerOfMass) const {_ASSERTE (0); return 0;}
   virtual dgMatrix CalculateInertiaAndCenterOfMass (const dgVector& localScale, const dgMatrix& matrix) const {_ASSERTE (0); return dgGetZeroMatrix();}


They do teh exact same thong bu take diffrent arguments.
I will clean that up. next time
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Compound collision and center of mass

Postby PJani » Sun Aug 12, 2012 1:00 pm

Hey i am back from vacation :D.
I updated newton source from repo. Are there any updates about compound collision?
Last edited by PJani on Sun Aug 12, 2012 1:09 pm, edited 1 time in total.
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
User avatar
PJani
 
Posts: 448
Joined: Mon Feb 02, 2009 7:18 pm
Location: Slovenia

Re: Compound collision and center of mass

Postby Julio Jerez » Sun Aug 12, 2012 1:03 pm

I think it is all in now.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Compound collision and center of mass

Postby PJani » Sun Aug 12, 2012 4:42 pm

Hmm are you sure? I was testing this and mass is only set from first sub collision. Center of mass is at the center of first sub collision.

I do this this way each time i add new sub collision.
Code: Select all
      ci.node = NewtonCompoundCollisionAddSubCollision(m_compound, sub_col);

      NewtonDestroyCollision(sub_col);

      NewtonBodySetMassProperties( m_body->getNewtonBody(), ci.density * ci.volume, NewtonCompoundCollisionGetCollisionFromNode(m_compound, ci.node));
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
User avatar
PJani
 
Posts: 448
Joined: Mon Feb 02, 2009 7:18 pm
Location: Slovenia

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests