Convex Hull Problem

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Convex Hull Problem

Postby telmopereira » Fri May 28, 2010 1:22 pm

Hi everyone,

Well, i am trying to use some objects more complex, so for that i am using the ConvexHull collision. I don't know why but is not working properly, because he treats all the objects as a box ! :S I made a video for you guys understand better what i am saying... http://feupload.fe.up.pt/get/G4NATKvKbOHnBia

I can also post here the code i use...

Code: Select all
NewtonBody* vehi_physics::createCollisionHull(IMesh* mesh, int shapeId)
{
   NewtonCollision* collision = 0;
   dFloat* cloud = 0;
   if( mesh )
   {
      int totalVertices = 0;
      for(int i = 0; i < mesh->getMeshBufferCount(); i++)
         totalVertices += mesh->getMeshBuffer(i)->getVertexCount();

      cloud = new dFloat[totalVertices*3];
                if( cloud )
      {
         int index = 0;
         for(int i = 0; i < mesh->getMeshBufferCount(); i++)
         {
            IMeshBuffer* mb = mesh->getMeshBuffer(i);
            S3DVertex* mb_vertices = (S3DVertex*)mb->getVertices();
            
            if( mb->getVertexType() == EVT_2TCOORDS )
            {
               S3DVertex2TCoords* mb_vertices = (S3DVertex2TCoords*)mb->getVertices();

               for(int j = 0; j < mb->getVertexCount(); j++, index+=3)
               {
                  cloud[index  ] = (dFloat)mb_vertices[j].Pos.X;
                  cloud[index+1] = (dFloat)mb_vertices[j].Pos.Y;
                  cloud[index+2] = (dFloat)mb_vertices[j].Pos.Z;
               }

            }
            else if( mb->getVertexType() == video::EVT_STANDARD )
            {
               S3DVertex* mb_vertices = (S3DVertex*)mb->getVertices();

               for(int j = 0; j < mb->getVertexCount(); j++, index+=3)
               {
                  cloud[index  ] = (dFloat)mb_vertices[j].Pos.X;
                  cloud[index+1] = (dFloat)mb_vertices[j].Pos.Y;
                  cloud[index+2] = (dFloat)mb_vertices[j].Pos.Z;
               }
            }
            else if( mb->getVertexType() == EVT_TANGENTS )
            {
               S3DVertexTangents* mb_vertices = (S3DVertexTangents*)mb->getVertices();

               for(int j = 0; j < mb->getVertexCount(); j++, index+=3)
               {
                  cloud[index  ] = (dFloat)mb_vertices[j].Pos.X;
                  cloud[index+1] = (dFloat)mb_vertices[j].Pos.Y;
                  cloud[index+2] = (dFloat)mb_vertices[j].Pos.Z;
               }
            }
         }
         collision = NewtonCreateConvexHull(p_world, totalVertices, cloud, sizeof(dFloat)*3, 0.0002, shapeId, NULL);
      }
   }

   NewtonBody* body = NewtonCreateBody(p_world, collision);
   NewtonReleaseCollision(p_world, collision);
   delete cloud;
   return body;
}


I already try out many different values for the tolerance...and didn't fix the problem...
Can you help me with this problem please?

Thanks,
Telmo
telmopereira
 
Posts: 29
Joined: Thu Apr 15, 2010 12:52 pm

Re: Convex Hull Problem

Postby Julio Jerez » Fri May 28, 2010 1:34 pm

I can not see the video.

One thing that helps a lot is implementing debug display, so that you can see how the collision looks like.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Convex Hull Problem

Postby telmopereira » Fri May 28, 2010 1:52 pm

Try now this video please: http://feupload.fe.up.pt/get/2MHjtxdSkjBGBBb

How can i implement the debug display?

And did you take a look on the code i post? Did you saw something wrong ?

Thanks,

Telmo
telmopereira
 
Posts: 29
Joined: Thu Apr 15, 2010 12:52 pm

Re: Convex Hull Problem

Postby Julio Jerez » Fri May 28, 2010 1:56 pm

I get the same message

O feupload está ligeiramente indisposto.
Envia um email a relembrar-nos para ni@aefeup.pt, vai beber uma cerveja, e quando voltares estará tudo como novo.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Convex Hull Problem

Postby telmopereira » Fri May 28, 2010 2:01 pm

Oh ok, so problem with people that are not register on server...

try this one ... http://dl.dropbox.com/u/1843380/convexHull.7z

Should be no problem i think this time.
telmopereira
 
Posts: 29
Joined: Thu Apr 15, 2010 12:52 pm

Re: Convex Hull Problem

Postby Carli » Sat May 29, 2010 2:38 am

You should know what a convex hull is.

A convex hull is convex, that means, if you want to have concave shapes, you have to use convex decomposition to get better results. I'm researching in convex decomposition, too, but there are still some problems in my algorithm.
Carli
 
Posts: 245
Joined: Fri Oct 02, 2009 5:28 am

Re: Convex Hull Problem

Postby Carli » Sat May 29, 2010 2:38 am

You should know what a convex hull is.

A convex hull is convex, that means, if you want to have concave shapes, you have to use convex decomposition to get better results. I'm researching in convex decomposition, too, but there are still some problems in my algorithm.
Carli
 
Posts: 245
Joined: Fri Oct 02, 2009 5:28 am

Re: Convex Hull Problem

Postby JernejL » Sat May 29, 2010 3:59 am

There is a popular decomposition library written by John Ratcliff, try that, i used it a bunch of times, it's ok as long as the shapes are not TOO complex.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Convex Hull Problem

Postby Carli » Sat May 29, 2010 8:23 am

Delfi wrote:There is a popular decomposition library written by John Ratcliff, try that


As I see, it's written in C++ --> incompatible to other languages,
I would have to port it to all platforms as a binary and an additional C interface....
too much work for a too small effect
Carli
 
Posts: 245
Joined: Fri Oct 02, 2009 5:28 am

Re: Convex Hull Problem

Postby JernejL » Sat May 29, 2010 1:24 pm

I built a windows DLL of it, which uses standard C api to interface with an app, but it's not cross platform.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Convex Hull Problem

Postby telmopereira » Sun May 30, 2010 1:41 pm

Hi guys,

Well, the question here is this: Newton as one function NewtonCollision* NewtonCreateConvexHull (const NewtonWorld* newtonWorld, int count, const dFloat* vertexCloud, int strideInBytes, dFloat tolerance, const dFloat *offsetMatrix); So, supposing that i pass all the arguments that this function requires, that should work more or less properly and that is not happenning, as you can see in my video... I try also the NewtonTreeCollision and it did a correct limits of the body and dont treat the mesh i use as a box.

So, can someone please explain me why the NewtonCreateConvexHull is not working well in my application?

Here is the code that i use to try to use the convexHull:

Code: Select all
   NewtonBody* vehi_physics::createCollisionHull(IMesh* mesh, int shapeId)
    {
       NewtonCollision* collision = 0;
       dFloat* cloud = 0;
       if( mesh )
       {
          int totalVertices = 0;
          for(int i = 0; i < mesh->getMeshBufferCount(); i++)
             totalVertices += mesh->getMeshBuffer(i)->getVertexCount();

          cloud = new dFloat[totalVertices*3];
                    if( cloud )
          {
             int index = 0;
             for(int i = 0; i < mesh->getMeshBufferCount(); i++)
             {
                IMeshBuffer* mb = mesh->getMeshBuffer(i);
                S3DVertex* mb_vertices = (S3DVertex*)mb->getVertices();
               
                if( mb->getVertexType() == EVT_2TCOORDS )
                {
                   S3DVertex2TCoords* mb_vertices = (S3DVertex2TCoords*)mb->getVertices();

                   for(int j = 0; j < mb->getVertexCount(); j++, index+=3)
                   {
                      cloud[index  ] = (dFloat)mb_vertices[j].Pos.X;
                      cloud[index+1] = (dFloat)mb_vertices[j].Pos.Y;
                      cloud[index+2] = (dFloat)mb_vertices[j].Pos.Z;
                   }

                }
                else if( mb->getVertexType() == video::EVT_STANDARD )
                {
                   S3DVertex* mb_vertices = (S3DVertex*)mb->getVertices();

                   for(int j = 0; j < mb->getVertexCount(); j++, index+=3)
                   {
                      cloud[index  ] = (dFloat)mb_vertices[j].Pos.X;
                      cloud[index+1] = (dFloat)mb_vertices[j].Pos.Y;
                      cloud[index+2] = (dFloat)mb_vertices[j].Pos.Z;
                   }
                }
                else if( mb->getVertexType() == EVT_TANGENTS )
                {
                   S3DVertexTangents* mb_vertices = (S3DVertexTangents*)mb->getVertices();

                   for(int j = 0; j < mb->getVertexCount(); j++, index+=3)
                   {
                      cloud[index  ] = (dFloat)mb_vertices[j].Pos.X;
                      cloud[index+1] = (dFloat)mb_vertices[j].Pos.Y;
                      cloud[index+2] = (dFloat)mb_vertices[j].Pos.Z;
                   }
                }
             }
             collision = NewtonCreateConvexHull(p_world, totalVertices, cloud, sizeof(dFloat)*3, 0.0002, shapeId, NULL);
          }
       }

       NewtonBody* body = NewtonCreateBody(p_world, collision);
       NewtonReleaseCollision(p_world, collision);
       delete cloud;
       return body;
    }


Thanks,

Telmo
telmopereira
 
Posts: 29
Joined: Thu Apr 15, 2010 12:52 pm

Re: Convex Hull Problem

Postby Julio Jerez » Sun May 30, 2010 3:12 pm

The video I saw deos no indicate a faliue of a conve hull in any way.
I just saw a red Boix and few othe sphere in some kind of level.

I told you implement debug display so that you can see hwo the shape of the collision look like.

Usually the convex hull function is very safe and rubust, it only fail for degenerated points.
I asume you are trying to make a Box, so that should work.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Convex Hull Problem

Postby telmopereira » Mon May 31, 2010 4:58 am

Hi,

Julio you said "I just saw a red Boix and few othe sphere in some kind of level." That is exactly the problem ... there is a kind of Labyrinth and there is "holes", its like a few walls attached each other, and that red box that you said should fall !!! Instead of that, the box is like in a level, i tried out many times and that Labyrinth is treated basically like a box... If i try out a table with four simple legs it also happen be treated basically like a box ! :S

Did you understood now my problem ? :S Is some kind of error in my code that i post here, that makes that happen?

Thanks,
Telmo
telmopereira
 
Posts: 29
Joined: Thu Apr 15, 2010 12:52 pm

Re: Convex Hull Problem

Postby Stucuk » Mon May 31, 2010 5:53 am

If you implement a Debug Display like Julio keeps telling you to do then it would make it FAR EASIER for him to give you an idea of what is wrong.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: Convex Hull Problem

Postby telmopereira » Mon May 31, 2010 6:20 am

And how can I "implement a Debug Display" ? I never did something like that and i am running out of time ...

Can u please help me on that ? Or for example, can someone show me one example where are using convexHull (that is working fine) so i can compare with what i did and see if is my code that is wrong? Or did someone detect something wrong on my code ?

thanks,
telmo
telmopereira
 
Posts: 29
Joined: Thu Apr 15, 2010 12:52 pm

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests

cron