Upgrading from Newton2xx to Newton3xx

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Upgrading from Newton2xx to Newton3xx

Postby Marc » Wed Aug 15, 2012 3:23 am

Hi!

I'm trying to upgrade my code from newton2xx to newton3xx and some things I have trouble with converting:

NewtonSetPlatformArchitecture: it's commented out in newton.h Is it not needed anymore? What plattform is getting used now? I used it to force x87 mode so it gives the same results on all pcs. Can I still do that somehow?

NewtonSetWorldSize: I think I read somewhere that this is not needed anymore and can be removed from my code right?

NewtonMaterialGetContactPositionAndNormal: This now takes an additional body parameter. I always wondered why there was no body parameter in 2xx. I always assumed it's from body0's perspective and if I wanted it from body1's perspective, I'ld have to multiply the normal with -1. Was that correct? Does this assumption still hold for 3xx ?

NewtonReleaseCollision: I see there is NewtonDestroyCollision now. Is it just renamed or do I have to use it differently?

NewtonBodySetCentreOfMass & NewtonBodySetMassMatrix: They are renamed to NewtonBodySetCentreOfMass___ and NewtonBodySetMassMatrix___. Can I still use them?

NewtonCreateSphere: It's not an ellipsoid anymore :(

NewtonMaterialGetBodyCollisionID: This is what bothers me most. I need this in the collision callback to differentiate shapes, but it is commented out in newton.h. Just removing the comment didn't make it work :( I checked the material-tutorial delivered with newton3xx and it still has this code in it:
Code: Select all
id0 = NewtonMaterialGetBodyCollisionID (material, body0);
         if (id0 == 0) {
            id0   = NewtonMaterialGetContactFaceAttribute (material);
         }
         id1 = NewtonMaterialGetBodyCollisionID (material, body1);
         if (id1 == 0) {
            id1   = NewtonMaterialGetContactFaceAttribute (material);
         }

Is this a temporary removal?
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: Upgrading from Newton2xx to Newton3xx

Postby Julio Jerez » Wed Aug 15, 2012 7:03 am

NewtonSetPlatformArchitecture:
with all the different hardwares, sse, x87, avx, gpu, tha fintion is no suffcienet to support all of then
the new functions are:
Code: Select all
int platformsCount = NewtonEnumrateDevices (mainFrame->m_scene->GetNewton());
char platform[256];
NewtonGetDeviceString (mainFrame->m_scene->GetNewton(), i, platform, sizeof (platform));
NewtonSetCurrentDevice (const NewtonWorld* const newtonWorld, int deviceIndex)



NewtonSetWorldSize:
Newton 3.00 does not has world bounres anymore.


NewtonMaterialGetContactPositionAndNormal: the orienation of a normal is no really important for physics calculation basically a conta is a manifold if a body has a contact the oteh bady has a contact pointin in the opososite direction
I adde teh body do that the funtion knows what sign to apply to teh contact normal, for some useres this is important.

NewtonReleaseCollision:
all collision are instances now, when you asign a collsion to a body teh body get a copy of that collision insthjead ofi adding a reffrerence.
you can just call NewtonDestroyCollision

NewtonBodySetCentreOfMass & NewtonBodySetMassMatrix:
They are temprarilly rename to NewtonBodySetCentreOfMass___ and NewtonBodySetMassMatrix___.
yes you cna still use then but I sujjest you us eteh newer method NewtonBodySetMassProperties (const NewtonBody* const body, dFloat mass, const NewtonCollision* const collision);


NewtonCreateSphere: yes this is gone, you can jys make a sphere and se the scale whi apply to all shapes now

NewtonMaterialGetBodyCollisionID:
where were you using that? I can put it back but it will be diffrent because a material may have a diffrent copy of the collision that what teh matrail and the body has.
I can make it work, can you tell me what you were using it for?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Upgrading from Newton2xx to Newton3xx

Postby Marc » Wed Aug 15, 2012 7:52 am

Thx for the insight. That helps. :)

I'm using NewtonMaterialGetBodyCollisionID exactly like in the code I posted from the tutorial. For my character controller I create two cylinders (or capsules). One is for the upper part of the body and one is for the lower part/feet. I give them different shapeids and combine them with a compound collision and attach it to the characters body. In the collision callback, I use the shape ids to identify if something collides with the upper part of the body or the lower part/feet. Depending on what the character is colliding with, I keep the contact or I remove it. So I can have small stuff where the character controller will walk onto like steps and stuff that the character controller will push away like things lying around on the floor. At the same time, larger things that collide with the upper part of the body will always get pushed away as they are too high to automatically walk onto.
Maybe this has to be done differently in newton3xx? But how?
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: Upgrading from Newton2xx to Newton3xx

Postby Julio Jerez » Wed Aug 15, 2012 8:02 am

notice that collison instance now have these functions

void NewtonCollisionSetUserData (const NewtonCollision* const collision, void* const userData);
void* NewtonCollisionGetUserData (const NewtonCollision* const collision);

void NewtonCollisionSetUserID (const NewtonCollision* const collision, unsigned id);
unsigned NewtonCollisionGetUserID (const NewtonCollision* const collision);

would those do the same?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Upgrading from Newton2xx to Newton3xx

Postby Marc » Wed Aug 15, 2012 8:14 am

Oh, I didn't realize there were these functions. That could work. I'll try. Is there any special meaning to the userid or can I set it to whatever I want like the userdata?

I'm also wondering, what shapeids are usefull for now?
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: Upgrading from Newton2xx to Newton3xx

Postby Marc » Wed Aug 15, 2012 8:39 am

Ok it compiles and runs without crashing. :)

But it's behaving completely bogus. I guess I have to change more things. When the compiler told me there is no NewtonUserMeshCollisionCollideDesc::m_userAttribute anymore, I just commented it out. But now, the m_faceVertexIndex needs more information. Didn't newton2xx need normal information or was it automatically calculated somehow? What is A: the estimate larger of the large diagonal of the face? What does that mean? The largest distance between all vertices of the face? That'ld be odd because it's not a floating point value?
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: Upgrading from Newton2xx to Newton3xx

Postby Marc » Wed Aug 15, 2012 9:14 am

Hmm ok I'm stuck.

If I just remove the attributes, collisions work but are bugged. For example a box keeps on top of my user collision but it sinks in a bit an rotates etc. Pretty strange.
I tried adding the additional infos to m_faceVertexIndex like described in newton.h:
Code: Select all
      *ptri++ = tri->vertices[0];
      *ptri++ = tri->vertices[1];
      *ptri++ = tri->vertices[2];
      *ptri++ = -1;               // M
      *ptri++ = normalsoffset + i;   // Normal
      *ptri++ = normalsoffset + i;   // Edge Normals, can be set to Normal
      *ptri++ = normalsoffset + i;
      *ptri++ = normalsoffset + i;
      *ptri++ = 0;               // A

I assumed that M is the shapeid which is not used anymore, so I set it to -1. Then the normals, I added calculation for these and put them at the back of the vertices array. So every triangle has a normal. I use it for the edges too so the normal index goes there 4 times. Then the A where I don't know what it is so I put it to 0.
Sadly, that results in having no collision anymore at all. Everything just falls through the user collision. :(
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: Upgrading from Newton2xx to Newton3xx

Postby Julio Jerez » Wed Aug 15, 2012 10:08 am

I guess you using user mesh colilsion?
to simplify thing first try usin teh collsion tree until you get everything running, then we see hwo to add use mesh collision

I will provide some untility funtions to help populate the usin mesh collsion and calculate the adjacency and face size. those are very important for high quality collsion reponse in newton 300
newtyon 200 sytizice those value for teh face but that was a half cokked result at best. it is better to have a proper infomation.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Upgrading from Newton2xx to Newton3xx

Postby Julio Jerez » Wed Aug 15, 2012 10:19 am

Marc wrote:Oh, I didn't realize there were these functions. That could work. I'll try. Is there any special meaning to the userid or can I set it to whatever I want like the userdata?

I'm also wondering, what shapeids are usefull for now?


shape id, usedadata are all for the end user. teh useData is a pointer just like a usde data of a body.
shape ID can be use for material or anythong else, for exampel you can grop collsion data with same shape id, and you cna use use ID for managing collsion shapes.

in newton 300 all shape are ne intances, so you cna no save a pointe to a shape and hope that you will get teh pointe in a call back. you will not.
however you will get teh same userData.
Collision Instance simplyfyed a great deal the engine internals, basically the engine is almost 100 lock free. plust is also simpfy the scaling and and other things that were to complex in core 200.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Upgrading from Newton2xx to Newton3xx

Postby Marc » Thu Aug 16, 2012 9:24 am

Ok. I exchanged my user collision with a large box and that works for collisions with other boxes.

As you know for my character controller, I also use convex casts which somehow give different results. I don't know what exactly is different, but somehow it leads to my characters always jumping around. I have no idea why that's happening. So either it's the convex cast, or my conversion to the new way of building compound collisions is screwed up. What I do there is this

Code: Select all
#ifdef NEWTON200
   NewtonCollision *cols[2];
   cols[0] = colup;          // has shapeid 1000
   cols[1] = coldown;      // has shapeid 1001
   NewtonCollision *col = NewtonCreateCompoundCollision(nworldcol, 2, cols, 1002);
#else
   NewtonCollisionSetUserID(colup, 1000);
   NewtonCollisionSetUserID(coldown, 1001);
   NewtonCollision *col = NewtonCreateCompoundCollision(nworldcol, 1002);
   NewtonCollisionSetUserID(col, 1002);
   NewtonCompoundCollisionBeginAddRemove(col);
   NewtonCompoundCollisionAddSubCollision(col, colup);
   NewtonCompoundCollisionAddSubCollision(col, coldown);
   NewtonCompoundCollisionEndAddRemove(col);
#endif


I hope the code for 2xx is equivalent to the code below for 3xx. For 3xx I also set the userid to the shapeid so I can get it in the collisioncallback.
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: Upgrading from Newton2xx to Newton3xx

Postby Julio Jerez » Thu Aug 16, 2012 12:17 pm

I am wroking on teh conev cast now, it will not work
the convex cast function will cal this function

Code: Select all
dgInt32 dgCollisionConvex::ConvexCastContacts (const dgMatrix& matrix__, const dgMatrix& invMatrix, const dgVector& veloc, dgFloat32& timeStep, const dgCollisionConvex* const convexShape, dgContactPoint* const contact) const
{
/*
   dgInt32 cicling = -1;
   dgFloat32 minDist = dgFloat32 (1.0e20f);

   dgInt32 index = 1;

   dgVector sum[4];
   dgVector diff[4];
   dgVector v (matrix.m_posit);
   dgFloat32 mag2 = v % v;
   if (mag2 > dgFloat32 (0.0f)) {
      v = v.Scale (dgRsqrt (mag2));
   } else {
      v =  dgVector(dgFloat32 (1.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f));
   }

   dgVector dir0 (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f));
   ConvexConicSupportVertex (v, matrix, convexShape, diff[0], sum[0]);

   for (dgInt32 i = 0; (i < DG_CONNICS_CONTATS_ITERATIONS) && (index < 4); i ++) {
      dgFloat32 dist = v % v;

      if (dist < dgFloat32 (1.0e-9f)) {
         // very deep penetration, resolve with generic minkosky solver
         return -1;
      }

      if (dist < minDist) {
         minDist = dist;
         cicling = -1;
      }

      _ASSERTE (dist > dgFloat32 (1.0e-24f));
      dgVector dir (v.Scale (-dgRsqrt (dist)));
      dist = dir0 % dir;

      ConvexConicSupportVertex (dir, matrix, convexShape, diff[index], sum[index]);
      const dgVector w = diff[index];
      dgVector wv (w - v);
      dist = dir % wv;

      cicling ++;
      if (cicling > 4) {
         dist = dgFloat32 (0.0f);
      }

      dir0 = dir;
      if (dist < dgFloat32 (1.0e-3f)) {
         dgVector d;
         dgVector s;
         switch (index)
         {
            case 1:
            {
               s = sum[0];
               d = diff[0];
               break;
            }
            case 2:
            {
               const dgVector& p0 = diff[0];
               const dgVector& p1 = diff[1];
               dgVector dp (p1 - p0);
               _ASSERTE (dp % dp > dgFloat32 (0.0f));
               dgFloat32 alpha0 = - (p0 % dp) / (dp % dp);
               _ASSERTE (alpha0 <= dgFloat32 (1.0f));
               _ASSERTE (alpha0 >= dgFloat32 (0.0f));
               d = p0 + dp.Scale (alpha0);
               s = sum[0] + (sum[1] - sum[0]).Scale (alpha0);
               break;
            }

            case 3:
            default:
            {
               _ASSERTE (index);
               // I do not know why this works, but Mathematica factor the barycentric position of a point to this sequence of calculations
               const dgVector& p0 = diff[0];
               const dgVector& p1 = diff[1];
               const dgVector& p2 = diff[2];
               const dgVector p (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f));

               dgVector p10 (p1 - p0);
               dgVector p20 (p2 - p0);
               dgVector p_p0 (p - p0);
               dgVector p_p1 (p - p1);
               dgVector p_p2 (p - p2);

               dgFloat32 alpha1 = p10 % p_p0;
               dgFloat32 alpha2 = p20 % p_p0;
               dgFloat32 alpha3 = p10 % p_p1;
               dgFloat32 alpha4 = p20 % p_p1;
               dgFloat32 alpha5 = p10 % p_p2;
               dgFloat32 alpha6 = p20 % p_p2;

               dgFloat32 va = alpha3 * alpha6 - alpha5 * alpha4;
               dgFloat32 vb = alpha5 * alpha2 - alpha1 * alpha6;
               dgFloat32 vc = alpha1 * alpha4 - alpha3 * alpha2;
               dgFloat32 den = dgFloat32(1.0f) / (va + vb + vc);
               dgFloat32 t0 = vb * den;
               dgFloat32 s0 = vc * den;

               _ASSERTE (t0 >= dgFloat32 (0.0f));
               _ASSERTE (s0 >= dgFloat32 (0.0f));
               _ASSERTE (t0 <= dgFloat32 (1.0f));
               _ASSERTE (s0 <= dgFloat32 (1.0f));
               d = p0 + p10.Scale(t0) + p20.Scale (s0);
               s = sum[0] + (sum[1] - sum[0]).Scale(t0) + (sum[2] - sum[0]).Scale (s0);
            }
            break;
         }

         //sum = p + q;
         //diff = p - q;
         dgVector p ((d + s).Scale (dgFloat32 (0.5f)));
         dgVector q ((s - d).Scale (dgFloat32 (0.5f)));
         return CalculateConvexConicContacts (p, q, contact, matrix, invMatrix, convexShape);
      }

      index ++;
      switch (index)
      {
         case 1:
         {
            _ASSERTE (0);
            break;
         }

         case 2:
         {
            v = ReduceLine (index, diff, sum);
            break;
         }

         case 3:
         {
            v = ReduceTriangle (index, diff, sum);
            break;
         }

         case 4:
         {
            v = ReduceTetrahedrum(index, diff, sum);
            break;
         }
      }
   }

   return (index == 4) ? -1 : 0;
*/


   dgVector sum;
   dgVector diff;
   dgMatrix matrix (matrix__);
   dgVector dir (matrix.m_posit);

   dgFloat32 mag2 = dir % dir;
   if (mag2 > dgFloat32 (0.0f)) {
      dir = dir.Scale (dgRsqrt (mag2));
   } else {
      dir =  dgVector(dgFloat32 (1.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f));
   }


   dgFloat32 travelDistance = dgFloat32 (0.0f);
   dgFloat32 maxTravelDistance = dgSqrt (veloc % veloc) * timeStep;
   bool state = SeparatingPlane (matrix, dir, convexShape);
   for (dgInt32 i = 0; (i < DG_SEPARATION_PLANES_ITERATIONS) && state; i ++) {
      dgVector p (SupportVertex(dir));
      dgVector dir1 (matrix.UnrotateVector (dir.Scale (dgFloat32 (-1.0f))));
      dir1 = dir1.Scale (dgRsqrt (dir1 % dir1));
      _ASSERTE (dgAbsf(dir1 % dir1 - dgFloat32 (1.0f)) < dgFloat32 (1.0e-2f));
      dgVector q (matrix.TransformVector (convexShape->SupportVertex (dir1)));
_ASSERTE (0);
/*
      dgFloat32 travelStep = (q - p) % veloc;
      travelDistance += travelStep;
      if (travelDistance > maxTravelDistance) {
         _ASSERTE (0);
         return 0;
      }
      if (travelStep <= dgFloat32 (1.0e-3f)) {
         _ASSERTE (0);
      }
      matrix.m_posit -= dir.Scale(travelDist);
*/

   }

   return 0;
}


I am change it to be faster, I will ahve it working in a day or two because I have to make soem chage to suport this newer version.
Try getting core 300 hgundre inetgarted first, by teh tiemn you ge t that Conev Cast will in wi the teh improve version that is liek you ask before about lath order of magnitu fate that the existing one.
More imprtant is is more acurate too.

I need to get convex cast going because I want to put teh vehiocle joint whi use that function for tires.
I will also look at you controller and see how it work mayeb we can have a best efforst that can be part of the SDK.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Upgrading from Newton2xx to Newton3xx

Postby Marc » Thu Aug 16, 2012 4:20 pm

Ok. I think the only things left for upgrading my code to newton 3xx are the convex cast and the usermeshcollision. Everything else seems to work so far. I might have to change some parameters in the end because the normal collisions seem a bit more bouncy than with 2xx, but it doesn't look wrong.

Just give me a heads up when I should try a new version of the convex cast or usermeshcollision. :)
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: Upgrading from Newton2xx to Newton3xx

Postby Julio Jerez » Thu Aug 16, 2012 4:37 pm

One thing I was thonking abou user mesh collision was that maybe if I add a funtion the can build a mesh form a vertex list index list.
this function will asome tha teh mesh is already optimized and it will no do any of the inertnal optimizations.

do you think this can help with your mesh creation at runtime?
Creating a collsion tree collision is very fast, it is the optmization face that makes it slower that is not practical for real time creation.
This will save a lot of complication, plus it will free the engioe for doing soem of teh stuff I want to add.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Upgrading from Newton2xx to Newton3xx

Postby Marc » Thu Aug 16, 2012 6:34 pm

I think the way it works in 2xx is best for me. Creating a tree collision fast is not helping me. I need have a callback and just generate that part of the mesh as needed because the whole world mesh is much too large to generate upfront - it won't fit in the memory. That's why I always loved this callback. It's not just that I need to change the geometry fast, I also need this "only generate parts on demand"-functionality.

You may think of it as a perlin noise generated terrain. You can generate parts of it really fast on demand with a small amount of memory. But you can't create all of it as a triangle mesh upfront.
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests