Debug rendering

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Debug rendering

Postby Slick » Mon Oct 29, 2018 7:20 am

I am trying to work out why my manually created object doesn't work. I have been digging into the debug rendering.

The OnDrawFace callback seems to return a quad or four vertices at a time. Is that right?

Does it return all the vertices for each body?
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: Debug rendering

Postby Julio Jerez » Mon Oct 29, 2018 10:02 am

I do no remember function OnDrawFace, on what file is that?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Debug rendering

Postby Slick » Mon Oct 29, 2018 10:25 am

Code: Select all
void dNewtonCollision::DebugRender (void* userData, int vertexCount, const dFloat* faceVertec, int id)
{
   dDebugRenderer* const renderer = (dDebugRenderer*) userData;
   renderer->OnDrawFace (vertexCount, faceVertec, id);
}


I think it does return all faces but I'm still curious about my original questions.
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: Debug rendering

Postby Slick » Mon Oct 29, 2018 10:30 am

It is probably a bug in my code but it is weird that I get this in my debug view for a sphere:

Image

The sphere was created by:

Code: Select all
dNewtonCollisionSphere collision(world, 1.0f, 1);
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: Debug rendering

Postby Julio Jerez » Mon Oct 29, 2018 10:46 am

the debug callback report convex polygons, you must triangulate them if you want to displat triangles, look at the second part of function

Code: Select all
void DebugShowGeometryCollision (void* userData, int vertexCount, const dFloat* const faceVertec, int id)
{
   //DEBUG_DRAW_MODE mode = (DEBUG_DRAW_MODE) ((int)userData); //NOTE error: cast from ‘void*’ to ‘int’ loses precision
   DEBUG_DRAW_MODE mode = (DEBUG_DRAW_MODE) ((intptr_t)userData);
   
   if (mode == m_lines) {
      int index = vertexCount - 1;
      dVector p0 (faceVertec[index * 3 + 0], faceVertec[index * 3 + 1], faceVertec[index * 3 + 2]);
      for (int i = 0; i < vertexCount; i ++) {
         dVector p1 (faceVertec[i * 3 + 0], faceVertec[i * 3 + 1], faceVertec[i * 3 + 2]);
         glVertex3f(GLfloat(p0.m_x), GLfloat(p0.m_y), GLfloat(p0.m_z));
         glVertex3f(GLfloat(p1.m_x), GLfloat(p1.m_y), GLfloat(p1.m_z));
         p0 = p1;
      }
   } else {
      dVector p0 (faceVertec[0 * 3 + 0], faceVertec[0 * 3 + 1], faceVertec[0 * 3 + 2]);
      dVector p1 (faceVertec[1 * 3 + 0], faceVertec[1 * 3 + 1], faceVertec[1 * 3 + 2]);
      dVector p2 (faceVertec[2 * 3 + 0], faceVertec[2 * 3 + 1], faceVertec[2 * 3 + 2]);

      dVector normal ((p1 - p0).CrossProduct(p2 - p0));
      normal = normal.Scale (1.0f / dSqrt (normal.DotProduct3(normal)));
      glNormal3f(GLfloat(normal.m_x), GLfloat(normal.m_y), GLfloat(normal.m_z));
      for (int i = 2; i < vertexCount; i ++) {
         p2 = dVector (faceVertec[i * 3 + 0], faceVertec[i * 3 + 1], faceVertec[i * 3 + 2]);
         glVertex3f(GLfloat(p0.m_x), GLfloat(p0.m_y), GLfloat(p0.m_z));
         glVertex3f(GLfloat(p1.m_x), GLfloat(p1.m_y), GLfloat(p1.m_z));
         glVertex3f(GLfloat(p2.m_x), GLfloat(p2.m_y), GLfloat(p2.m_z));
         p1 = p2;
      }
   }
}
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 15 guests

cron