Collision between box and cylinder give wrong normals

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Collision between box and cylinder give wrong normals

Postby Rasarasa » Fri Dec 31, 2010 10:28 pm

I use a collision test between a cylinder and a box. to get the normals from the box. The normals are then used to make the cylidenr slide against the box side. It woks on two of the edges on the box. but the other two the cylinder just walks through (which means that the normals are inverted). I tried replacing the cylider with a sphere, capsule and box (Axis aligned). The sphere and box worked like i want it to. but the capsule shows the same error as the cylinder.

ConvexCast Callback:
Code: Select all
void ListCollisionsAndNormals(const NewtonBody* body, void* data)
{
   CollisionsWithNormals* collisionList = (CollisionsWithNormals*)data;

   //If it isn't the player
   if(body != collisionList->body)
   {
      dMatrix matrixA;
      dMatrix matrixB;
      NewtonBodyGetMatrix(collisionList->body, &matrixA[0][0]);
      NewtonBodyGetMatrix(body, &matrixB[0][0]);

      float contacts[3*4];
      float normals[3*4];
      float penetration[1*4];

      //See if the player collides
      int collisions = NewtonCollisionCollide(NewtonBodyGetWorld(body), 4, NewtonBodyGetCollision(collisionList->body),
         &matrixA[0][0], NewtonBodyGetCollision(body), &matrixB[0][0], contacts, normals, penetration, 0);

      //int collisions = NewtonCollisionCollide(NewtonBodyGetWorld(body), 4,  NewtonBodyGetCollision(body),
         //&matrixB[0][0],NewtonBodyGetCollision(collisionList->body), &matrixA[0][0], contacts, normals, penetration, 0);

      //They collide
      if(collisions > 0)
      {
         dVector separation = dVector(0.0f, 0.0f, 0.0f);
         
         //Get the separation normal
         for(int i = 0; i < collisions; i++)
         {
            
            //invert the normal
            dVector invNormal = dVector(normals[i] ,normals[i+1] ,normals[i+2], 0.0f);

            //dVector norm(contacts[i], contacts[i+1], contacts[i+2]);
            /*dVector temp = norm;

            norm -= matrixA.m_posit;

            norm += temp;
            */
            
            //NewtonWorldRayCast(NewtonBodyGetWorld(collisionList->body), &matrixA.m_posit[0], &norm[0], RayCastNormalFilter, &invNormal,
            //NotSelfRayCastPrefilter);
            
            //Apply penetration
            //invNormal = invNormal.Scale(penetration[i]);

            //See if the axis lenghts is longer than the last         
            //////

            //Check X
            if(abs(separation.m_x) < abs(invNormal.m_x))
               separation.m_x = invNormal.m_x;

            //Check Y
            //if(abs(pushBackData->pushBack.m_y) < abs(invNormal.m_y))
               //pushBackData->pushBack.m_y = invNormal.m_y;

            //Check Z
            if(abs(separation.m_z) < abs(invNormal.m_z))
               separation.m_z = invNormal.m_z;
               
         }

         collisionList->bodies.push_back(BodyNormal((NewtonBody*)body, separation));
      }
   }
}


Debug file:
http://www.megaupload.com/?d=30KJUUHW
Rasarasa
 
Posts: 8
Joined: Tue Dec 21, 2010 7:34 pm

Re: Collision between box and cylinder give wrong normals

Postby Julio Jerez » Sat Jan 01, 2011 10:08 am

Ther are 4 special case collision routine in teh engine
sphere/sphere (whis handle all cobination of capsule, sphere, liek sphere/capsule /capsule capsule, etc)
shere/box
sphere/polygon
capsule/polygon

all teh rest is the same funtion convex/ convex
it is the the function supportvertex that make the funtion behave different.

Ther is not Capsule/Box special collision
therfore if teh normal was wrong in one edge it will also be wrong in many other configuration

Any way I will test teh demo. But I do no see hwo to run it
I says D3dx9d_43.dll not found

also are you using Newton 2.29? since this demo is an exe I may no be able to debug it with lates newton because in 2.29
funtion CreateBody now take the Matrix as an argument.

How do I get d3dx9d_43?

Ok I installed DXSDK_Jun10.exe and now I can run the test.

I see a red Box ove a large Box the looks liek teh floor.
How do I reproduce the Bug?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Collision between box and cylinder give wrong normals

Postby Rasarasa » Sat Jan 01, 2011 12:53 pm

You correctly collide with corners C and B. pushing you away. But you can wallk right through the cube form A to D or D to A.

Also whei i run right into the cube(only colliding with one side of it) i get normals pointing along the wall( runing into side C-D i get normas pointing away, and normals pointing along C-D).
Tried making the cube bigger because i thoght i always colide with several sides at a time. But even with a huge box where the player only can collide with one side i get those faulty normals.

Also im using newton 2.26.

------------------
Seen from the start viewpoint but from above:

A--------------B
I I
I I
I I
C-------------D



player
Rasarasa
 
Posts: 8
Joined: Tue Dec 21, 2010 7:34 pm

Re: Collision between box and cylinder give wrong normals

Postby Julio Jerez » Sat Jan 01, 2011 1:53 pm

who do I test that all I see is tow red cubes, how to I make what you say happens.
I do no undernd what the demo is suppose to do.
Can you make eso that is show the normals? because i do nor really see what is going on.

also you need to download 2.29 I cannot debug it because it crashs when I run with newton 2.29 dll.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Collision between box and cylinder give wrong normals

Postby Rasarasa » Sat Jan 01, 2011 5:18 pm

What my code does is get athe normals from the collision test , and use that normal to slide the cylindrical player along the wall. But since i get the wrong normals in two of the corners. The player just wallks throgh, there. Just try to wallk into the box and se how the player reacts. nad most inportantly the normals.

I have updated the code to work with newton-2.29. I have also added test in the corner(Apear after collision) for the normals from the collision. The first 4 are from the test, the fift and last one is a summarised vector based on the longest separate axes from the collision test(Y excluded as the push bakc should be on the XZ plane), It is used for the wall sliding. And i have also made the cylinder collision shape look like cylinder(I was to lazy to make a cylinder form my personal tests).

http://www.megaupload.com/?d=25BPAG8X

A correction to one of my previous statements: The only player shape that works as it should is the sphere. I have not tried it with other shapes to run into though.
Rasarasa
 
Posts: 8
Joined: Tue Dec 21, 2010 7:34 pm


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 11 guests

cron