ConvexCast not always working with TreeCollisions

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

ConvexCast not always working with TreeCollisions

Postby Markus » Sat Jun 04, 2011 7:55 am

Hey,

I'm using the convex cast to place my objects vertically in my world with the code below (It is adapted from the tutorials). It works well with "normal" collision shapes, but when I add a TreeCollision as the ground, the ConvexCast returns some confusing values. When I cast sphere shapes, it *always* returns the correct value, but when I cast other primitives or convex hulls, the result is unpredictable. There are faces of the TreeCollision that always work, and faces that never work. And there are faces (see the picture) that work only in a special range. Again, when I cast spheres, it always works, regardless of the face.

In the black areas of the picture, the objects are placed at the ground level (below the ramp).

Code: Select all
static unsigned ConvexCastCallback(const NewtonBody* body, const NewtonCollision* collision, void* userData)
{
   std::cout << body << std::endl;
   NewtonBody* other = (NewtonBody*)userData;
   return (other == body) ? 0 : 1;
}

float getConvexCastPlacement(NewtonBody* body)
{
   Mat4f matrix;
   NewtonBodyGetMatrix(body, matrix[0]);
   matrix._42 += 200.0f;
   Vec3f p(matrix.getW());
   p.y -= 400.0f;

   NewtonWorld* world = NewtonBodyGetWorld(body);
   NewtonCollision* collision = NewtonBodyGetCollision(body);

   float param = 0.0f;
   NewtonWorldConvexCastReturnInfo info[16];

   NewtonCollisionInfoRecord collisionInfo;
   NewtonCollisionGetInfo(collision, &collisionInfo);

   if (collisionInfo.m_collisionType == SERIALIZE_ID_COMPOUND) {
      float maximum = -200.0f;
      // the nodes of my compounds to not have a special offset matrix, so use the normal one
      for (int i = 0; i < collisionInfo.m_compoundCollision.m_chidrenCount; ++i) {
         NewtonCollision* node = collisionInfo.m_compoundCollision.m_chidren[i];
         NewtonWorldConvexCast(world, matrix[0], &p[0], node, &param, body, ConvexCastCallback, info, 16, 0);
         float current = matrix._42 + (p.y - matrix._42) * param;
         if (current > maximum) maximum = current;
      }
      return maximum;
   } else {
      NewtonWorldConvexCast(world, matrix[0], &p[0], collision, &param, body, ConvexCastCallback, info, 16, 0);

      matrix._42 += (p.y - matrix._42) * param;
      return matrix._42;
   }
}
Attachments
convexcast.jpg
convexcast.jpg (97.28 KiB) Viewed 3721 times
Markus
 
Posts: 52
Joined: Sat Mar 19, 2011 6:31 am

Re: ConvexCast not always working with TreeCollisions

Postby Julio Jerez » Sat Jun 04, 2011 10:03 am

It looks like there is a problem there yes. I can no detremine what it is since convex cast use the same low lever collision function, so it convex cast fail then collision also fail, but it does no seems to be the case

I have tryied to find what teh bug is but I have not being able to insulated it,
I see you have a good test case can you provide it as an debug test?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: ConvexCast not always working with TreeCollisions

Postby Markus » Sat Jun 04, 2011 11:47 am

I'll try to do that. The problem is that there are many third party libraries in the program, so it will take a while to make a simple demo out of it. If you don't have a problem with it, I can give you the entire code, you just have to figure out how to compile it. Instructions on how to do that are here: https://github.com/Markush2010/dominato ... stallation You can download the source from the same page.

Let me know if that's OK (then I can tell you how to reconstruct the bug) or if I should make a simple demo.
Markus
 
Posts: 52
Joined: Sat Mar 19, 2011 6:31 am

Re: ConvexCast not always working with TreeCollisions

Postby Julio Jerez » Sat Jun 04, 2011 3:00 pm

Oh it is a linux build, I do not have linu installed now.

can you you export the mesh maybe I can load it in one o fteh test demos and try with the same settings.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: ConvexCast not always working with TreeCollisions

Postby Markus » Sat Jun 04, 2011 3:41 pm

It actually runs under Windows, too. But I don't recommend it since it is a pain to set it up. You can download the mesh here: http://dl.dropbox.com/u/7650790/env.3ds

I basically create a primitive/convex hull at the camera position and use the code above to determine the vertical position.
Markus
 
Posts: 52
Joined: Sat Mar 19, 2011 6:31 am


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 5 guests