FaceAttribute and NewtonCollisionCollide

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: FaceAttribute and NewtonCollisionCollide

Postby Julio Jerez » Sat Apr 14, 2012 8:37 am

I am going to make that a test demo wit teh same setting you psted at teh beginning of the thread, that looks very bad there, most be some bug some where.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: FaceAttribute and NewtonCollisionCollide

Postby Julio Jerez » Sun Apr 15, 2012 2:22 pm

Ok I start adding serialization already, I added collision tree and height filed terrains, it is checked in. This afternoon I will complete the rest this afternonn, but now I need to leave.

I also make the parallel solver functional again, and when doing that I want comparing to the all solver.
I could not find anything wrong with it. If anything it would be the core 200 solve that would be wrong.

I did not make the test yet, because I am confident that I will find that bug sooner all later, but I start to think if it is something wrong with the contacts generation, and I just realized that I think what the problem is.

In core 200, and older the default mode of the solve is exact solver.
Newton has two type of solvers of lineal system of equation.

one that is exact in the sense that giver a linear system with a condition number lower that what can be hold with a 24 bit mantissa, the solver will find the solution in a finite number of iterations.

This is base on Bi-conjugate decent method which has a time cubic time complexity.
whoever because the matrix that represented and bilateral system has a special structure that allow then to be multiplied by a vector in linear time, this make the solver quadratic in the best case and cubic in the worse case.
Condition number is very important, when the matrix has extreme mass or inertia ratio, the condition number is very high. what this does is that the algorithm still finish in a fix number of step,
but the noise added to by the lost of numerical Presidion makes the solution complete unreliable.

you can read about condition number internet or any book in numerical analysis, here is a good reference http://teal.gmu.edu/ececourses/ece699/notes/note4.html

with a 24 bit the condition number of a matrix condition down to roughfully the number the you can code with half the number of bits. this is about 2^ 11 (meaning value that can be 2048 time large that the minum),
for some reason when I was doing these test the value is much lower and it come to about 2, to 300 time. mass ration. the reason for this is the it is not only the mass that make the element o the system matrix,
it also the shape with influence the inertia matrix.

The other solver in Newton is base of Gauss Sidle iterations.
This solve have poor convergence rate but it is very fast when dealing with system with lot of rows.
This suffer a lot more from poor condition number, however, an condition number of 10, make bad. while the other you can easily use 100 or more.

Her is when is different between core 200 and core 300.

In core 300 the default solver is the iterative solver, while in core 200 it is the exact solver.
you said you did no calibrate anything when you run the test, so you were running the exact solve in core 200, and the iterative solve in core 300.

when you run this test again, see if you can initialize the engine to the exact solver and let us see what happens.


Here is what is intersecting about the exact solver. when the system matrix is small, (a few dozen rows, it is actually faster that the iterative solver) this is similar to sorting algorithms.
for example quick sort is faster than insertion or bubble sort for large number of elements.
but insertion and bubble sorts are faster that quick sort for small number of element.
because of this fact, must implementation of quick sort do no sort the entire array, instead they do a partial sort and finished it up with and insertion source.

Newton core 300 is using fact also as a feature, so fat only joint do it, because for contacts it more elaborated to do, but it will also be an option.

basically the joint has a function that the tell the engine the cut up for deciding better exact and iterative solver.
for contact joint I will add that option to the Material, to you will have the option to decide when to use better more accuracy or more speed in input sensitive way.

by first we need to determine is it I am correct or not, please when you have time see if the solve more is set to exact in you test.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: FaceAttribute and NewtonCollisionCollide

Postby Julio Jerez » Sun Apr 15, 2012 3:21 pm

Ok serialization of all the standard type are in, I have to write the new funtion for the two new shapes,(tapered capules and tapered cylinders) but that is eassy.

I will aso going to add serialization to rigid bodies, joint and the entire world.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: FaceAttribute and NewtonCollisionCollide

Postby Yezide » Mon Apr 16, 2012 1:36 am

Thanks for the detailed explanation!

Will try the exact solver for 300 and see what happens and since serialization is in, I might as well update the game too now :) Will hopefully do this on tuesday as I have other stuff today.
User avatar
Yezide
 
Posts: 173
Joined: Tue Oct 18, 2005 4:31 am

Re: FaceAttribute and NewtonCollisionCollide

Postby Yezide » Tue Apr 17, 2012 2:10 am

Tried exact solver, ie:
Code: Select all
NewtonSetSolverModel(mpNewtonWorld,0);
NewtonSetFrictionModel(mpNewtonWorld,0);


and the result is still the same as the other 300 videos. Also tried to change solver mode to 1,2 and 10 to see if there was any change, but it looked exactly the same.
User avatar
Yezide
 
Posts: 173
Joined: Tue Oct 18, 2005 4:31 am

Re: FaceAttribute and NewtonCollisionCollide

Postby Yezide » Tue Apr 17, 2012 3:35 am

Trying newton 300 in the game now, and getting some bugs:

1) Continuous collision is not working for mesh collisions.

2) To spin a cylinder around its axis I need to have 100 times the torque that I needed with newton 200 to get it moving as much. Something different in the inertia calculation?
User avatar
Yezide
 
Posts: 173
Joined: Tue Oct 18, 2005 4:31 am

Re: FaceAttribute and NewtonCollisionCollide

Postby Julio Jerez » Tue Apr 17, 2012 6:58 am

Oh it does no work with solve mode 0 either, ok I will verify that by making the test

yes continue collision is no ready yet.
what size is the cylinder? I had notice that, and I though it wil because of the scale. In core 300 intetai is affectd by teh shape scale, bu I am guesstying you are nit scaling yopuu shape.
I will make soem comparizon to core 200 to see what is going on.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: FaceAttribute and NewtonCollisionCollide

Postby Yezide » Tue Apr 17, 2012 7:30 am

Actually turns out the body I had an issue with had consisted of 3 shapes, all cylinders:
- Rotation="1.5708 -0 0" Translation="0 0 0.024399" Size="0.021 0.096" Pos="0 0 0.115947"
- Rotation="1.5708 -0 0" Translation="0 0 0.056366" Size="0.195 0.024" Pos="0 0 0.147914"
- Rotation="1.5708 -0 0" Translation="0 0 -0.056366" Size="0.0065 0.07 Pos="0 0 0.035182"

Perhaps it was different because it was a compound?
User avatar
Yezide
 
Posts: 173
Joined: Tue Oct 18, 2005 4:31 am

Re: FaceAttribute and NewtonCollisionCollide

Postby Julio Jerez » Tue Apr 17, 2012 7:33 am

yes the inreta probme seenc eto happen with the calculation of the interta of a compound shape. In teh demos I noticed that big resistance as weel.
I am checking it out.

are these three very small cylnders wit teh same orientaion? it look they are almost in the same position
- Rotation="1.5708 -0 0" Translation="0 0 0.024399" Size="0.021 0.096" Pos="0 0 0.115947"
- Rotation="1.5708 -0 0" Translation="0 0 0.056366" Size="0.195 0.024" Pos="0 0 0.147914"
- Rotation="1.5708 -0 0" Translation="0 0 -0.056366" Size="0.0065 0.07 Pos="0 0 0.035182"


In the compound shape I am replacing the compound with those shape and see what happens.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: FaceAttribute and NewtonCollisionCollide

Postby Yezide » Tue Apr 17, 2012 7:59 am

are these three very small cylnders wit teh same orientaion? it look they are almost in the same position

yes, I think there might be some strange collider placement there, it being artist made and all ;)
User avatar
Yezide
 
Posts: 173
Joined: Tue Oct 18, 2005 4:31 am

Re: FaceAttribute and NewtonCollisionCollide

Postby Julio Jerez » Tue Apr 17, 2012 8:17 am

ok I pasted in teh compund demo, and I see what it is.

Code: Select all
   //test Yeside compound shape shape
   //   - Rotation="1.5708 -0 0" Translation="0 0 0.024399" Size="0.021 0.096" Pos="0 0 0.115947"
   //   - Rotation="1.5708 -0 0" Translation="0 0 0.056366" Size="0.195 0.024" Pos="0 0 0.147914"
   //   - Rotation="1.5708 -0 0" Translation="0 0 -0.056366" Size="0.0065 0.07 Pos="0 0 0.035182"

   NewtonCompoundCollisionBeginAddRemove(compound);   

   dMatrix offsetMatrix (dPitchMatrix(1.5708f));
   offsetMatrix.m_posit.m_z = 0.115947f;
   NewtonCollision* collision = NewtonCreateCylinder (world, 0.021f, 0.096f, 0, &offsetMatrix[0][0]) ;
   NewtonCompoundCollisionAddSubCollision (compound, collision);
   NewtonDestroyCollision(collision);

   offsetMatrix.m_posit.m_z = 0.147914f;
   collision = NewtonCreateCylinder (world, 0.195f, 0.024f, 0, &offsetMatrix[0][0]) ;
   NewtonCompoundCollisionAddSubCollision (compound, collision);
   NewtonDestroyCollision(collision);

   offsetMatrix.m_posit.m_z = 0.035182f;
   collision = NewtonCreateCylinder (world, 0.0065f, 0.07f, 0, &offsetMatrix[0][0]) ;
   NewtonCompoundCollisionAddSubCollision (compound, collision);
   NewtonDestroyCollision(collision);

   NewtonCompoundCollisionEndAddRemove(compound);   

it is a funny little object that look like a spinning toy. Oh I see what it is, it is a wheel with a handle not. cool.
you are right the inertia is wrong, it makes it behave like a very heavy brick. there is definitelly a bug in the inertia, it is time to fix it now.

you are right if you are going to have objects this small you will need the contine collision, I will add that part this comming week. it is almost done, but I need to glue it with the new collision instance object.
I also need to fix a bug that I see in the convex cast. the bug shows as a flash in the convex cast demo. this means it is faling in some cases and I need to fix that before implemention the CC on dynamics bodies.

anyway let me see what is wrong with intertia with compoind collision shapes.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: FaceAttribute and NewtonCollisionCollide

Postby Yezide » Tue Apr 17, 2012 8:20 am

Great! Other than this, 300 seemed to be working fine! So will do another round of test when fixed-
User avatar
Yezide
 
Posts: 173
Joined: Tue Oct 18, 2005 4:31 am

Re: FaceAttribute and NewtonCollisionCollide

Postby Julio Jerez » Tue Apr 17, 2012 9:34 am

Ok I fixed the inertia bug. when i adde dteh intance, I ha has to modifi teh mass propertie calaculation for every collision shape.
in the compound the problems is complex enough that it is simpler to just do it by Divergence and teh teh Green threme of calculus.
whover I forge teh taht teh final resul is scale by teh volume of the indes teh shape. so all intetia where scale bu teh volume making small volume shape veryu ver small, and lareg volme shape very, bery large
after apply the scale it si back to normal.

It is all check in now.
It remaind the Continue collision and the jitter bug, I will go over that this weekend, afet I compel the serailzation and teh last Scene collision.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: FaceAttribute and NewtonCollisionCollide

Postby Julio Jerez » Wed Apr 18, 2012 11:06 am

now I added someting that will meke life eassy for me and many people, Seralization for everything (joint still pending)

basically if an application add this bit of glue code to the code

Code: Select all
void DemoEntityManager::SerializeFile (void* const serializeHandle, const void* const buffer, int size)
{
   // check that each chunk is a multiple of 4 bytes, this is useful for easy little to big Indian conversion
   _ASSERTE ((size & 0x03) == 0);
   fwrite (buffer, size, 1, (FILE*) serializeHandle);
}

void DemoEntityManager::DeserializeFile (void* const serializeHandle, void* const buffer, int size)
{
   // check that each chunk is a multiple of 4 bytes, this is useful for easy little to big Indian conversion
   _ASSERTE ((size & 0x03) == 0);
   fread (buffer, size, 1, (FILE*) serializeHandle);
}


void DemoEntityManager::BodySerialization (NewtonBody* const body, NewtonSerializeCallback serializeCallback, void* const serializeHandle)
{
   // here the use can save information of this body, ex:
   // a string naming the body, 
   // serialize the visual mesh, or save a link to the visual mesh
   // save labels for looking up the body call backs

   // for the demos I will simple write three stream to identify what body it is, the application can do anything
   const char* const bodyIndentification = "gravityBody\0\0\0\0";
   int size = (strlen (bodyIndentification) + 3) & -4;
   serializeCallback (serializeHandle, &size, sizeof (size));
   serializeCallback (serializeHandle, bodyIndentification, size);
}


void DemoEntityManager::BodyDeserialization (NewtonBody* const body, NewtonDeserializeCallback serializecallback, void* const serializeHandle)
{
   int size;
   char bodyIndentification[256];
   
   serializecallback (serializeHandle, &size, sizeof (size));
   serializecallback (serializeHandle, bodyIndentification, size);


   // get the world and the scene form the world user data
   NewtonWorld* const world = NewtonBodyGetWorld(body);
   DemoEntityManager* const scene = (DemoEntityManager*)NewtonWorldGetUserData(world);

   // here we attach a visual object to the entity,
   dMatrix matrix;
   NewtonBodyGetMatrix(body, &matrix[0][0]);
   DemoEntity* const entity = new DemoEntity(matrix, NULL);
   scene->Append (entity);

   NewtonBodySetUserData (body, entity);
   NewtonBodySetTransformCallback(body, DemoEntity::TransformCallback);
   NewtonBodySetForceAndTorqueCallback(body, PhysicsApplyGravityForce);


   //for visual mesh we will collision mesh and convert it to a visual mesh using NewtonMesh
   NewtonCollision* const collision = NewtonBodyGetCollision(body);
   int collisionID = NewtonCollisionGetType(collision) ;

   DemoMesh* mesh = NULL;
   switch (collisionID)
   {
      case SERIALIZE_ID_HEIGHTFIELD:
      {
         NewtonCollisionInfoRecord info;
         NewtonCollisionGetInfo(collision, &info);

         const NewtonHeightFieldCollisionParam& heighfield = info.m_heightField;
         mesh = new DemoMesh ("terrain", heighfield.m_elevation, heighfield.m_width, heighfield.m_horizonalScale, 1.0f/16.0f, 128);
         break;
      }
      
      default:
         mesh = new DemoMesh("cylinder_1", collision, NULL, NULL, NULL);
         break;
   }

   entity->SetMesh(mesh);
   mesh->Release();
}

}



then by colling
NewtonSerialize (m_world, BodySerialization, SerializeFile, file);

or
NewtonDeserialize (m_world, BodyDeserialization, DeserializeFile, file);

the copmple worlkd will be serialized to any meda th aapplication decide.
In the SDK they is a menu option for serializ any type of demo scene. The wapplication cna autor teh serialzation by addin some extrat information.
for exampel when I save teh rigi body, inteh call back I save a nem only, then I us eteh name to inititializ ethe body.
an applycation can same a special name to look up teh visual mesh an dteh tyep of bopdy it is.

here is a code that I use for serializing and deseralizing

Code: Select all
void DemoEntityManager::DeserializedPhysicScene (const char* const name)
{
   // add the sky
   CreateSkyBox();

   FILE* const file = fopen (name, "rb");

   // read the application data use to initialize the engine and other application related stuff.
   // reading the camera orientation
   dMatrix camMatrix;
   DeserializeFile (file, &camMatrix, sizeof (camMatrix));
   SetCameraMatrix(dQuaternion (camMatrix), camMatrix.m_posit);

   NewtonDeserialize (m_world, BodyDeserialization, DeserializeFile, file);
   fclose (file);
}


void DemoEntityManager::InterpolateMatrices ()
{
   // calculate the fraction of the time step for interpolations
   unsigned64 timeStep = dGetTimeInMicrosenconds () - m_microsecunds;      
   dFloat step = (dFloat (timeStep) * MAX_PHYSICS_FPS) / 1.0e6f;
   _ASSERTE (step >= 0.0f);
   if (step > 1.0f) {
      step = 1.0f;
   }

   // interpolate the Camera matrix;
   m_camera->InterpolateMatrix (*this, step);

   // interpolate the location of all entities in the world
   for (NewtonBody* body = NewtonWorldGetFirstBody(m_world); body; body = NewtonWorldGetNextBody(m_world, body)) {
      DemoEntity* const entity = (DemoEntity*)NewtonBodyGetUserData(body);
      if (entity) {
         entity->InterpolateMatrix (*this, step);
      }
   }
}





This is no only good for serialtion file, it can be use to make copy of a world , for network game, or for savin to memopy to regreate wothe for dirrent porposes.
For me this is the preambule of the Visual debugger.

also nwo any clint app that add that code to theis game, if can simpel send me teh serialized data, and I will be able to reproduc the bug in teh tool by simplyt load teh data.
no more asking how the scene was done of people having to send me demos.

and teh more imprtnat feature is that teh application only need to share when teh wnat to share, since it is teh client who decide to to save or not top save.
I hope people find this usefull.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: FaceAttribute and NewtonCollisionCollide

Postby Yezide » Wed Apr 18, 2012 11:21 am

cool, still possible to serialize individual bodies/shapes/etc I take it?
User avatar
Yezide
 
Posts: 173
Joined: Tue Oct 18, 2005 4:31 am

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests