Debuggable demo of convex raycast against compound [SOLVED]

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Debuggable demo of convex raycast against compound [SOLVED]

Postby pHySiQuE » Sat Jun 03, 2017 3:21 pm

A few months ago I was advised to build Newton as a DLL so that it could be debugged externally. It took a while, but finally I am now using Newton as a DLL, with the latest revision 3659, and my engine physics can now be debugged with Visual Studio.

The problem I have is that convex raycast is not working correctly against compound collisions:


Now I have a debuggable demo showing this:
https://www.leadwerks.com/files/NewtonTest.zip

Thanks for your help.
Last edited by pHySiQuE on Mon Jun 05, 2017 2:05 am, edited 1 time in total.
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Debuggable demo of convex raycast against compound colli

Postby pHySiQuE » Sun Jun 04, 2017 12:16 pm

This example is updated. Press escape to release the mouse, press escape again to go back into FPS control mode. Close the window to exit.
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Debuggable demo of convex raycast against compound colli

Postby Julio Jerez » Sun Jun 04, 2017 12:56 pm

did you try after you made the other fix? also how do you go external view?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Debuggable demo of convex raycast against compound colli

Postby pHySiQuE » Sun Jun 04, 2017 12:59 pm

Yes, this is a separate problem.

This demo is a different download:
https://www.leadwerks.com/files/NewtonTest.zip
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Debuggable demo of convex raycast against compound colli

Postby Julio Jerez » Sun Jun 04, 2017 1:06 pm

I do no see that guard rail in that demo. I see many ramps and obstacles but nothing like in the video

there is a door at the end of the room, but I don know how to get there, the ramp tip toe down want I try get to the door. and it does not jumps high enough.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Debuggable demo of convex raycast against compound colli

Postby pHySiQuE » Sun Jun 04, 2017 1:17 pm

Julio Jerez wrote:I do no see that guard rail in that demo. I see many ramps and obstacles but nothing like in the video

there is a door at the end of the room, but I don know how to get there, the ramp tip toe down want I try get to the door. and it does not jumps high enough.

Ha, that is the physics puzzle! Normally, you would pick up the concrete blocks to weigh down one end of the ramp. :mrgreen:

The machine at the beginning of the map with the controls on it is a compound collision shape, and if you jump on top of it you will see the problem. (Space key jumps).
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Debuggable demo of convex raycast against compound colli

Postby Julio Jerez » Sun Jun 04, 2017 1:35 pm

ok the console in front of the player is a compound I see how dies not look correct.
The demo still has the mouse in exclusive mode, I can't no debug it.

edit: never mind, is ok now
I am debugging it.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Debuggable demo of convex raycast against compound colli

Postby Julio Jerez » Sun Jun 04, 2017 2:29 pm

I have not going in depth yet, but it seem that is generation the contact correctly.
is hard to see because the console shape as complex,
can you do this,

replace the console with a simple box of dimensions 1 x 1 x 1 or something like that. then make that box a compound.
if you can no make a compound of a single shape, you can add another small one an place inside that large box. then test it to see if the bug happens.

This will allow me to make prediction of what should happens, and compare with what is actually happening, at the moment I see that the collision report 4 contacts, but I can't see if they are correct.

when I do that test this is a list of the contact as the object move around

    frame: 2027, param: 0.335125, posit(7.155564 1.000977 3.544889)
    frame: 2027, param: 0.335125, posit(7.335565 1.000977 3.856658)
    frame: 2028, param: 0.338395, posit(6.615564 1.000977 3.856524)
    frame: 2028, param: 0.338395, posit(6.795565 1.000977 4.168294)
    ...
    frame: 2029, param: 0.338395, posit(7.335565 1.000977 3.856524)
    frame: 2030, param: 0.374099, posit(6.974139 2.719478 4.417943)
    frame: 2031, param: 0.362724, posit(6.974062 2.706977 4.441322)
    frame: 2032, param: 0.346654, posit(6.967108 2.687375 4.464640)
    frame: 2041, param: 0.970195, posit(6.973717 3.656548 4.602761)
    frame: 2048, param: 0.827301, posit(7.048620 3.971725 4.820000)
    frame: 2057, param: 0.999487, posit(6.612765 4.231726 4.820000)
    frame: 2057, param: 0.999487, posit(6.785585 4.231726 5.120000)
    frame: 2057, param: 0.999487, posit(7.159560 4.231726 5.120000)
    frame: 2057, param: 0.999487, posit(7.332572 4.231726 4.820333)
    frame: 2070, param: 0.978508, posit(6.612091 4.200046 5.072135)
    frame: 2070, param: 0.978508, posit(6.639726 4.200046 5.120000)
    frame: 2070, param: 0.978508, posit(6.757661 4.200046 4.820000)
    frame: 2070, param: 0.978508, posit(7.186521 4.200046 4.820000)
you can see that when the player is at the floor, is reports contact of elevation 1.0
the as I jump it hit the lower part at 2.71, the another path that has a slanted face at 3.xx
and finally it rest of the back pane; which has a elevation of 4.168

This values seems right to me, by I do not know what to compared them too,

you can actually do that test by hacking the newton DLL and print those values and see why that weird behavior that happens after that, My guess that is has to do with the param hit point whi is 0.9 when it hit.

The function that you can edit to print this values is this.

Code: Select all
dgInt32 dgBroadPhase::ConvexCast(const dgBroadPhaseNode** stackPool, dgFloat32* const distance, dgInt32 stack, const dgVector& velocA, const dgVector& velocB, dgFastRayTest& ray,
                         dgCollisionInstance* const shape, const dgMatrix& matrix, const dgVector& target, dgFloat32* const param, OnRayPrecastAction prefilter, void* const userData, dgConvexCastReturnInfo* const info, dgInt32 maxContacts, dgInt32 threadIndex) const
{
   dgVector boxP0;
   dgVector boxP1;
   dgTriplex points[DG_CONVEX_CAST_POOLSIZE];
   dgTriplex normals[DG_CONVEX_CAST_POOLSIZE];
   dgFloat32 penetration[DG_CONVEX_CAST_POOLSIZE];
   dgInt64 attributeA[DG_CONVEX_CAST_POOLSIZE];
   dgInt64 attributeB[DG_CONVEX_CAST_POOLSIZE];
   dgInt32 totalCount = 0;

   dgAssert(matrix.TestOrthogonal());
   shape->CalcAABB(matrix, boxP0, boxP1);

static int xxx;
xxx ++;

   maxContacts = dgMin (maxContacts, DG_CONVEX_CAST_POOLSIZE);
   dgAssert (!maxContacts || (maxContacts && info));
   dgFloat32 maxParam = *param;
   dgFloat32 timeToImpact = *param;
   while (stack) {
      stack--;

      dgFloat32 dist = distance[stack];

      if (dist > maxParam) {
         break;
      } else {
         const dgBroadPhaseNode* const me = stackPool[stack];

         dgBody* const body = me->GetBody();
         if (body) {
            if (!PREFILTER_RAYCAST(prefilter, body, body->m_collision, userData)) {
               dgInt32 count = m_world->CollideContinue(shape, matrix, velocA, velocB, body->m_collision, body->m_matrix, velocB, velocB, timeToImpact, points, normals, penetration, attributeA, attributeB, maxContacts, threadIndex);

               if (timeToImpact < maxParam) {
                  if ((timeToImpact - maxParam) < dgFloat32(-1.0e-3f)) {
                     totalCount = 0;
                  }
                  maxParam = timeToImpact;
                  if (count >= (maxContacts - totalCount)) {
                     count = maxContacts - totalCount;
                  }

                  for (dgInt32 i = 0; i < count; i++) {
                     info[totalCount].m_point[0] = points[i].m_x;
                     info[totalCount].m_point[1] = points[i].m_y;
                     info[totalCount].m_point[2] = points[i].m_z;
                     info[totalCount].m_point[3] = dgFloat32(0.0f);
                     info[totalCount].m_normal[0] = normals[i].m_x;
                     info[totalCount].m_normal[1] = normals[i].m_y;
                     info[totalCount].m_normal[2] = normals[i].m_z;
                     info[totalCount].m_normal[3] = dgFloat32(0.0f);
                     info[totalCount].m_penetration = penetration[i];
                     info[totalCount].m_contaID = attributeB[i];

// trace the contact point top see if they are valid
dgTrace (("frame: %d, param: %f, posit(%f %f %f)\n", xxx, maxParam, points[i].m_x, points[i].m_y, points[i].m_z));

                     info[totalCount].m_hitBody = body;
                     totalCount++;
                  }
               }
               if (maxParam < 1.0e-8f) {
                  break;
               }
            }
         } else if (me->IsAggregate()) {
            dgBroadPhaseAggregate* const aggregate = (dgBroadPhaseAggregate*)me;
            const dgBroadPhaseNode* const node = aggregate->m_root;
            if (node) {
               dgVector minBox(node->m_minBox - boxP1);
               dgVector maxBox(node->m_maxBox - boxP0);
               dgFloat32 dist1 = ray.BoxIntersect(minBox, maxBox);
               if (dist1 < maxParam) {
                  dgInt32 j = stack;
                  for (; j && (dist1 > distance[j - 1]); j--) {
                     stackPool[j] = stackPool[j - 1];
                     distance[j] = distance[j - 1];
                  }
                  stackPool[j] = node;
                  distance[j] = dist1;
                  stack++;
                  dgAssert(stack < DG_BROADPHASE_MAX_STACK_DEPTH);
               }
            }

         } else {
            dgBroadPhaseTreeNode* const node = (dgBroadPhaseTreeNode*)me;
            const dgBroadPhaseNode* const left = node->m_left;
            dgAssert(left);
            dgVector minBox(left->m_minBox - boxP1);
            dgVector maxBox(left->m_maxBox - boxP0);
            dgFloat32 dist1 = ray.BoxIntersect(minBox, maxBox);
            if (dist1 < maxParam) {
               dgInt32 j = stack;
               for (; j && (dist1 > distance[j - 1]); j--) {
                  stackPool[j] = stackPool[j - 1];
                  distance[j] = distance[j - 1];
               }
               stackPool[j] = left;
               distance[j] = dist1;
               stack++;
               dgAssert(stack < DG_BROADPHASE_MAX_STACK_DEPTH);
            }

            const dgBroadPhaseNode* const right = node->m_right;
            dgAssert(right);
            minBox = right->m_minBox - boxP1;
            maxBox = right->m_maxBox - boxP0;
            dist1 = ray.BoxIntersect(minBox, maxBox);
            if (dist1 < maxParam) {
               dgInt32 j = stack;
               for (; j && (dist1 > distance[j - 1]); j--) {
                  stackPool[j] = stackPool[j - 1];
                  distance[j] = distance[j - 1];
               }
               stackPool[j] = right;
               distance[j] = dist1;
               stack++;
               dgAssert(stack < DG_BROADPHASE_MAX_STACK_DEPTH);
            }
         }
      }
   }
   *param = maxParam;
   return totalCount;
}


I suggest making that test compound shape so that it eassy to compare the results.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Debuggable demo of convex raycast against compound colli

Postby pHySiQuE » Sun Jun 04, 2017 2:35 pm

This is the controller shape file:
controller.zip
(270 Bytes) Downloaded 295 times


This is the shape loading code:
Code: Select all
   bool Shape::Reload(const int flags)
   {
      Stream* stream=NULL;
        Vec3 position;
        Vec3 rotation;
        Vec3 scale;
      Surface* surf=NULL;
        int verts, v, i;
        std::vector<float> vertices;
      iVec3 tri;

      if (path=="")
      {
         //Print("Error: Can't reload shape.  No path specified.");
         return false;
      }

      Reset();

      int newtime = FileSystem::GetFileTime(path);
      stream = FileSystem::ReadFile(path);
      if (stream==NULL)
      {
         System::Print("Error: Failed to read file \""+path+"\".");
         return false;
      }
      time=newtime;

      if (stream->ReadString()!="PHY")
      {
         System::Print("Error: Shape file header not found.");
         delete stream;
         stream = NULL;
         return false;
      }

      switch (stream->ReadInt())
      {
      case 2:
         break;
      default:
         System::Print("Error: Unsupported shape file version.");
         delete stream;
         stream = NULL;
         return false;
      }

        int subshapes = stream->ReadInt();

      //At this time, only convexhulls and polymesh are supported
        for (int k=0; k<subshapes; k++)
        {
            shapeid = stream->ReadInt();
            if (shapeid==SHAPE_BOX)
            {
                position.x = stream->ReadFloat();
                position.y = stream->ReadFloat();
                position.z = stream->ReadFloat();
                rotation.x = stream->ReadFloat();
                rotation.y = stream->ReadFloat();
                rotation.z = stream->ReadFloat();
                scale.x = stream->ReadFloat();
                scale.y = stream->ReadFloat();
                scale.z = stream->ReadFloat();
            ((NewtonDynamicsPhysicsDriver*)driver)->CreateShapeBox((NewtonDynamicsShape*)this, position.x, position.y, position.z, rotation.x, rotation.y, rotation.z, scale.x, scale.y, scale.z);
            }
         if (shapeid == SHAPE_SPHERE)
         {
            position.x = stream->ReadFloat();
            position.y = stream->ReadFloat();
            position.z = stream->ReadFloat();
            rotation.x = stream->ReadFloat();
            rotation.y = stream->ReadFloat();
            rotation.z = stream->ReadFloat();
            scale.x = stream->ReadFloat();
            scale.y = stream->ReadFloat();
            scale.z = stream->ReadFloat();
            ((NewtonDynamicsPhysicsDriver*)driver)->CreateShapeSphere((NewtonDynamicsShape*)this, position.x, position.y, position.z, rotation.x, rotation.y, rotation.z, scale.x, scale.y, scale.z);
         }
         if (shapeid == SHAPE_CONE)
         {
            position.x = stream->ReadFloat();
            position.y = stream->ReadFloat();
            position.z = stream->ReadFloat();
            rotation.x = stream->ReadFloat();
            rotation.y = stream->ReadFloat();
            rotation.z = stream->ReadFloat();
            scale.x = stream->ReadFloat();
            scale.y = stream->ReadFloat();
            scale.z = stream->ReadFloat();
            ((NewtonDynamicsPhysicsDriver*)driver)->CreateShapeCone((NewtonDynamicsShape*)this, position.x, position.y, position.z, rotation.x, rotation.y, rotation.z, scale.x, scale.y, scale.z);
         }
         if (shapeid == SHAPE_CYLINDER)
         {
            position.x = stream->ReadFloat();
            position.y = stream->ReadFloat();
            position.z = stream->ReadFloat();
            rotation.x = stream->ReadFloat();
            rotation.y = stream->ReadFloat();
            rotation.z = stream->ReadFloat();
            scale.x = stream->ReadFloat();
            scale.y = stream->ReadFloat();
            scale.z = stream->ReadFloat();
            ((NewtonDynamicsPhysicsDriver*)driver)->CreateShapeCylinder((NewtonDynamicsShape*)this, position.x, position.y, position.z, rotation.x, rotation.y, rotation.z, scale.x, scale.y, scale.z);
         }
            if (shapeid==SHAPE_CONVEXHULL)
            {
                surf=Surface::Create();
                verts=stream->ReadInt();
                for (v=0; v<verts; v++)
                {
                    position.x = stream->ReadFloat();
                    position.y = stream->ReadFloat();
                    position.z = stream->ReadFloat();
                    surf->AddVertex(position.x,position.y,position.z);
                }
            ((PhysicsDriver*)driver)->CreateShapeConvexHull(surf,this);
                surf->Release();
            }
            else if (shapeid==SHAPE_POLYMESH)
            {
                surf=Surface::Create();
                int verts=stream->ReadInt();
                int tris=stream->ReadInt();
#ifdef DEBUG
            //Debug::Assert(verts < 10000);
            //Debug::Assert(tris < 10000);
            /*if (tris > 10000)
            {
               surf->Release();
               return false;
            }*/
#endif
            int v,t;
            float p, area;
            Vec3 a, b, c;
            float da, db, dc;
            int vertex_count;
                for (v=0; v<verts; v++)
                {
                    position.x = stream->ReadFloat();
                    position.y = stream->ReadFloat();
                    position.z = stream->ReadFloat();
                    surf->AddVertex(position.x,position.y,position.z);
                }
                for (t=0; t<tris; t++)
                {
                    tri.x = stream->ReadInt();
                    tri.y = stream->ReadInt();
                    tri.z = stream->ReadInt();
               if (tri.x != tri.y && tri.x != tri.z && tri.y != tri.z)
               {
#ifdef DEBUG
                  Debug::Assert(tri.x >= 0 && tri.x < verts);
                  Debug::Assert(tri.y >= 0 && tri.y < verts);
                  Debug::Assert(tri.z >= 0 && tri.z < verts);
#endif
                  a = surf->GetVertexPosition(tri.x);
                  b = surf->GetVertexPosition(tri.y);
                  c = surf->GetVertexPosition(tri.z);

                  vertex_count = surf->CountVertices();

                  da = a.DistanceToPoint(b);
                  db = b.DistanceToPoint(c);
                  dc = c.DistanceToPoint(a);
                  p = (da + db + dc) / 2.0;
                  area = sqrt(p * (p - da)*(p - db)*(p - dc));
                  if (area > 0.001) surf->AddTriangle(tri.x, tri.y, tri.z);
               }
                }
            if (surf->CountTriangles())
            {
               ((PhysicsDriver*)driver)->CreateShapePolyMesh(surf, this);
            }
            surf->Release();
            }
        }
        Finalize();
      stream->Release();

      return true;
   }
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Debuggable demo of convex raycast against compound colli

Postby Julio Jerez » Sun Jun 04, 2017 2:38 pm

what do I do with that file?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Debuggable demo of convex raycast against compound colli

Postby pHySiQuE » Sun Jun 04, 2017 2:40 pm

I don't know. But if you want the collision shape info, it's all in there.
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Debuggable demo of convex raycast against compound colli

Postby Julio Jerez » Sun Jun 04, 2017 2:45 pm

no, no I said you need to change the demo so that the compound shape is just a box that we can see if the contacts point and the hit parameter is correct. as it now I do I se returning values than seem right but if there is nothing to compared too, I can't say if this is a bug on the newton side.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Debuggable demo of convex raycast against compound colli

Postby pHySiQuE » Sun Jun 04, 2017 3:01 pm

Okay, I added a copy of the model next to the original, with just a bounding box shape around it:
https://www.leadwerks.com/files/NewtonTest.zip

(Make sure you're running the debug exe.)
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Debuggable demo of convex raycast against compound colli

Postby Julio Jerez » Sun Jun 04, 2017 3:09 pm

not that does not work, The player can't even jump that high, can't you take one of these create and make a compound?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Debuggable demo of convex raycast against compound colli

Postby pHySiQuE » Sun Jun 04, 2017 3:10 pm

Julio Jerez wrote:not that does not work, The player can't even jump that high, can't you take one of these create and make a compound?

There are stairs leading up to the model now so you can jump on top.
Attachments
Image1.jpg
Image1.jpg (40.56 KiB) Viewed 7727 times
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 12 guests

cron