Sliding Object Behavior

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Sliding Object Behavior

Postby michDS » Fri Aug 12, 2011 4:22 pm

Hi,

In my shuffleboard game, I'm seeing strange behavior when a puck slides down the surface of the table. The puck (a cylinder) is given a velocity parallel to the table surface (a box). As it slides down the table, the puck sometimes veers to the left or right without having collided with any dynamic objects. Sometimes it also rotates as it slides down, even though no angular velocity has been applied. Here's two videos of it happening:

Notice the puck veering right midway down the table:
http://www.digitalsmoke.us/ISUHD8.mov

Notice the #1 symbol on the puck end up in a rotated position:
http://www.digitalsmoke.us/ISUHD4.mov

Any idea why this could be happening and how to apply a fix? I suspect it has to do with the puck penetrating the table, but it shouldn't be causing any direction or rotation changes.
michDS
 
Posts: 33
Joined: Fri Aug 12, 2011 3:47 pm

Re: Sliding Object Behavior

Postby Julio Jerez » Sat Aug 13, 2011 11:21 am

that is because the contacts tangent dirention are no alignet to the direction of the velocity.

you need to set a callback between the Pocke Lane an dteh Pocket and there

-Read the contact point, and for each contact the has a vertical normal align it so that the first tangent is paraller to teh lane direction

the function fo that is this.
void NewtonMaterialContactRotateTangentDirections (const NewtonMaterial* const material, const dFloat* const directionVector);


a funtion to do that woudl be like this
Code: Select all
void GenericContactProcess (const NewtonJoint* contactJoint, dFloat timestep, int threadIndex)
{
   // read the table direction
   dVector dir (tableDir);

   // table verical dir
   dVector updir (TableDir);

   NewtonBody* const body = NewtonJointGetBody0(contactJoint);
   for (void* contact = NewtonContactJointGetFirstContact (contactJoint); contact; contact = NewtonContactJointGetNextContact (contactJoint, contact)) {
      dFloat speed;
      dVector point;
      dVector normal;   
      dVector dir0;   
      dVector dir1;   
      dVector force;
      NewtonMaterial* material;

      material = NewtonContactGetMaterial (contact);
      NewtonMaterialGetContactPositionAndNormal (material, body, &point.m_x, &normal.m_x);

      // if the normal is vertical is large the say 40 degrees
      if (fabsf (normal % upDir) > 0.7f) {
         // rotate the normal to be aligned with the table direction
         NewtonMaterialContactRotateTangentDirections (material, dir);
      }
   }
}
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Sliding Object Behavior

Postby michDS » Tue Aug 16, 2011 2:23 am

Thanks Julio.

Your solution fixed some cases, but I'm still seeing the issue when a puck is launched with part of the puck hanging off the edge of the table:

In this video, the puck is launched with velocity (0, 0, -1) straight down the left of the table, but still veers to the right.
http://www.digitalsmoke.us/ISUHD1.mov

In this video, the puck is launched with velocity (0, 0, -1) straight down the left of the table, but falls off the left edge of the table.
http://www.digitalsmoke.us/ISUHD2.mov

Any idea how to fix these issues?
michDS
 
Posts: 33
Joined: Fri Aug 12, 2011 3:47 pm

Re: Sliding Object Behavior

Postby Julio Jerez » Tue Aug 16, 2011 9:18 am

can you add some debug code that show the contact and the contact tangents as teh puck moves?

to fix that problem you will have to add some posproccesing to the contacts,
basically the problem happens because the contact distribution is not symetric over teh surface of the puck.
Physics engines are an abtraction of reality, they represent friction by sampling a minimal set of contact points over the surface on contact with another surface.
in the case of the Puck, when the contacts sample is not ditributed symetrically over the surface of the puck,
then the friction forces calculated by the solver have some asymetry that is converted to a center force that is not aligned with the diretion of motion.

if you add the debug function do display the contacts and the tangent direction, we can see how bad the distribution is and take action to correct it.
you can read the contact and the sufarce contact using and contact iterations, here is function you cna adpat to draw them,

Code: Select all
void RenderBodyContactsAndTangentDiretions (NewtonBody* const body, float length)
{
   for (NewtonJoint* joint = NewtonBodyGetFirstContactJoint(body); joint; joint = NewtonBodyGetNextContactJoint(body, joint)) {
      for (void* contact = NewtonContactJointGetFirstContact (joint); contact; contact = NewtonContactJointGetNextContact (joint, contact)) {
         dVector point;
         dVector normal;   
         NewtonMaterial* const material = NewtonContactGetMaterial (contact);
         NewtonMaterialGetContactPositionAndNormal (material, body, &point.m_x, &normal.m_x);

         dVector tangnetDir0;
         dVector tangnetDir1;
         NewtonMaterialGetContactTangentDirections(material, body, &tangnetDir0[0], &tangnetDir1[0]);
                                                // draw the tangent dir here.

         // if we are display debug info we need to block other threads from writing the data at the same time
         dVector p0 (point + normal.Scale (length));
         dVector p1 (point - normal.Scale (length));
         glVertex3f (p0.m_x, p0.m_y, p0.m_z);
         glVertex3f (p1.m_x, p1.m_y, p1.m_z);
      }
   }
}


you can call it with the poiter to the puck body in each frame, and then we can see what is going on.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Sliding Object Behavior

Postby michDS » Tue Aug 16, 2011 7:15 pm

Here are the two videos displaying contacts and tangents:
(red = contacts, green = primary tangent, blue = secondary tangent)

http://www.digitalsmoke.us/ISUHDA.mov

http://www.digitalsmoke.us/ISUHDB.mov

Let me know if there's anything else that would help debug.
michDS
 
Posts: 33
Joined: Fri Aug 12, 2011 3:47 pm

Re: Sliding Object Behavior

Postby michDS » Wed Aug 17, 2011 2:35 am

One other strange behavior we're seeing is when a puck hits another dynamic body. Sometimes the puck flies backwards as if it has hit a wall.

Here's a video of a puck and pin colliding with explosive force:
http://www.digitalsmoke.us/ISUHDC.mov

The current release of our game uses the old Newton library (1.53), and does not have this issue. It has only come up after updating to Newton 2.x.

Any ideas what could be causing this?
michDS
 
Posts: 33
Joined: Fri Aug 12, 2011 3:47 pm

Re: Sliding Object Behavior

Postby Julio Jerez » Wed Aug 17, 2011 1:30 pm

On the third video, that ussually happned because teh diffrence on masses beteen teh Puck and the Pins.

On the first two videos, the frition forces since to be aligned enough to not produce the side move. Tha par since correct.
let us now add more debug infomation,

Let us display the magnitud and the diretion of the Net Forces on the Puck generate by teh friction on each contact.
My guess is that the frictions values on each force umbalanced, leadin to and unligned net force.

There is a function to read it in the engine, but I do not remember the name now, and I can no search for it from where I am now.
If you do not find it remind me tonigh and I will post code to display the net force on the puck decompose along the diretion of motion.

if there is a residual side force, we sodul check what is causing it.

Code: Select all
The current release of our game uses the old Newton library (1.53), and does not have this issue. It has only come up after updating to Newton 2.x.

those issues are typical of a iterative solver.
Basically an iterative des no alway generate the best set of forces fopr teh reaction force, it generate a solution, no the best.
Newton 1.53 only have a Least square Conver Cuadratic solve that goratee teh Best Possible solution but it is slow.
newton 2.0 also has tha solve, (solver mode 0)
The iterative solve is fast, but does not produces the minimal set of forces. but we can work on that and have a acceptable solution using the iterative solver.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Sliding Object Behavior

Postby michDS » Wed Aug 17, 2011 4:47 pm

Here are the two videos with the net force drawn in Yellow. I'm not sure if I did it correctly, but I used the function NewtonBodyGetForce() which returns m_netForce for the body. I drew a vector from the center of the puck.

http://www.digitalsmoke.us/ISUHDL.mov

http://www.digitalsmoke.us/ISUHDR.mov
michDS
 
Posts: 33
Joined: Fri Aug 12, 2011 3:47 pm

Re: Sliding Object Behavior

Postby michDS » Wed Aug 17, 2011 5:21 pm

I just checked, and I'm actually using the default solver and friction modes which are both set to 0.
michDS
 
Posts: 33
Joined: Fri Aug 12, 2011 3:47 pm

Re: Sliding Object Behavior

Postby Julio Jerez » Wed Aug 17, 2011 5:32 pm

I believe the defualt is the same as 1.53,
just make sure you ste the mode manually, set to mode 0, and see what happens.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Sliding Object Behavior

Postby michDS » Wed Aug 17, 2011 5:54 pm

I set the mode manually to 0, and am getting the same results. I also stepped through the code, and confirmed that the mode is set to 0 (with or without calling NewtonSetSolverModel()).
michDS
 
Posts: 33
Joined: Fri Aug 12, 2011 3:47 pm

Re: Sliding Object Behavior

Postby Julio Jerez » Wed Aug 17, 2011 6:21 pm

ok then it is the right solver.
do teh force display if you can, if the puck deviate is because the force must have a non zero componet sideway to teh diretion of motion.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Sliding Object Behavior

Postby michDS » Wed Aug 17, 2011 6:49 pm

Hi, I posted the force videos. Is this what you were expecting:

Here are the two videos with the net force drawn in Yellow. I'm not sure if I did it correctly, but I used the function NewtonBodyGetForce() which returns m_netForce for the body. I drew a vector from the center of the puck.

http://www.digitalsmoke.us/ISUHDL.mov

http://www.digitalsmoke.us/ISUHDR.mov
michDS
 
Posts: 33
Joined: Fri Aug 12, 2011 3:47 pm

Re: Sliding Object Behavior

Postby Julio Jerez » Wed Aug 17, 2011 10:30 pm

Ok I see that when teh puck is moving alon the edge, teh net fors do have a sizeway component
that is what is miving teh puck to the teh size.

There must be a force component that is maki the net force value to go sideway.

Are you applying any force on the force and trtoque callback? or is a simple downward gravity value?

the next test we want to do is to zero out all of the sideway friction forces and see if the puck moves straight.
for that you can set the dynamics friction coeficcient to zero on the secund tangent to zero. that way the tangent friction forces will have a better meaning.
only friction force along the direction on motion shouil be active. let us do that and see what happens.
Also in the code that displays the see if you can scale the tangent direction by the magnitud of the friction force along the direction.
If do not knwo how to do it let me know. I can post teh code.

Zeroing out the dynamics friction force is the correct way of doing that , because according to the Laws of Newtonian and Columb friction model.
when a contact point is in motion then the friction forces on that contact sould be only along the direction of motion.

Game physics engines do not do that automatically because Game physics engine uses a Box Friction model when the calculating the tangent normals.
howuever the Columnb model says there shouldbe only one tangent.
By having two tangents the physics solver will calculate a sideway forces and there is not guarante that thye will add to zero.

Hopefully the Newton engine allowes for the aligment of the tangent, you already did that, but now you need to zero out the sideway tangent forces by setting zero or a very small dynamic friction value.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Sliding Object Behavior

Postby michDS » Thu Aug 18, 2011 4:08 pm

I'm only applying gravity in the force and torque callback.

I've added this call in the material collision callback (for the puck/surface) collision, but it didn't change the results:
NewtonMaterialSetContactFrictionCoef(pMaterial, 0.05f, 0.0f, 1);

The outcome looks the same. Is this the correct way to zero out the second tangent dynamic friction?

Also, could you provide me the code to display the magnitude of the friction force for the tangents? I can't find the function that would give me that.

Thanks.
michDS
 
Posts: 33
Joined: Fri Aug 12, 2011 3:47 pm

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests