Multiple Floating Point Traps

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Re: Multiple Floating Point Traps

Postby Julio Jerez » Tue Dec 17, 2019 5:20 pm

they will move off the z axis by some small value when they collide because that's how the physics of impulsive collision works, but the value should be very small no more than when the bodies can translate in a time step. Any small thickness should prevent them from crossing each other.
setting the velocity to zero is a huge mistake.

are the players and the objects paper thin?
are you running at 60fps, if so you can try NewtonSetNumberOfSubsteps (m_world, 2);
and should be much, much better
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Multiple Floating Point Traps

Postby Lax » Wed Dec 18, 2019 2:46 am

My objects are moving like on a paper yes and I have to assure of the time, that a GameObject does not drift away on z axis. I also thought of a regulation watchdog. That is, when a game object drifts away to much, It will be regulated by setting adding velocity z a bit in the corresponding direction.

The sub step option is a good idea. I will try that out.
I also tried with joint stickness, but results were the same.
Please support SecondEarthTechnicBase built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd17-5ff5-40a0-ac6f-44b97b79be62
Image
Lax
 
Posts: 165
Joined: Sat Jan 08, 2011 8:24 am

Re: Multiple Floating Point Traps

Postby Sweenie » Wed Dec 18, 2019 6:10 am

I think Julio meant that the colliders shouldn't be too thin on the z-axis or else they could pass each other. During each simulation step the joint can drift slightly during a collision or strong force and the solver will try to correct this error, but it sounds from your description that they keep drifting on the z-axis. How much does the body drift?
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Multiple Floating Point Traps

Postby Julio Jerez » Wed Dec 18, 2019 8:40 am

For what you are saying Lax, the objects are drifting away from the z plane and the error is not being corrected.
This is telling me that your set up is still incorrect.
The error should always be within on some max bound, and on average zero.

There are two demos in the SDK that use that joint,
Flat land and the Excavator.

Has you try any of them?

Flat land is similar, and should represent what you seek 100%
The excavator is more complex, because the threads are a chain of many very small objects and very light weight compare to the rest of the vehicle about 500 lighter, only one is constrained to the plane of motion, they are in perpetual collision with other bodies and the ground and to make even harder the plane rotates with the vehicle, and they move fine, with drift error that are acceptable.
In fact if I do not mention this, people would not even noticed.

Did you put together your game like the flat land demo?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Multiple Floating Point Traps

Postby Lax » Fri Dec 27, 2019 9:30 am

Sorry guys, my mistake :(
I set the plane joint for the player to early, hence the plane joint has never been created for the player, but all enemies had their plane set correctly... I fixed it now.

Best Regards
Lax
Please support SecondEarthTechnicBase built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd17-5ff5-40a0-ac6f-44b97b79be62
Image
Lax
 
Posts: 165
Joined: Sat Jan 08, 2011 8:24 am

Re: Multiple Floating Point Traps

Postby Lax » Sat Dec 28, 2019 12:23 pm

Hi,

just one question with this plane constraint. Is it normal, that when the plane is active, that a body cannot be rotated anymore? Because that is the case, my player does no more rotate. When I release the plane constraint, the player will can rotate again.

Best Regards
Lax
Please support SecondEarthTechnicBase built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd17-5ff5-40a0-ac6f-44b97b79be62
Image
Lax
 
Posts: 165
Joined: Sat Jan 08, 2011 8:24 am

Re: Multiple Floating Point Traps

Postby Julio Jerez » Sat Dec 28, 2019 3:36 pm

again one more time.
in the SDK dCustomJoint library there is a joint named dCustomPlane
say you want to make a body moves in the x-y plane.
you make the joint with the plane equation of that plane.
a plane equation is define by a point on the plane and the normal of the plane. this is the equation.
Code: Select all
dotProduct ((p - p0), n0) = 0;


p is any point in space
p0 is the reference point in the plane
n0 is the normal of the plane

p0 and n0 are the parameters for the joint and the joint implement the equation of the plane to force the chosen point on the body to be on that plane equation.

the body will only be allowed to move on the plane x-y and rotate around the normal n0 (the z axis) pivoted around the point p on the body. That's all there is to it.
and it is what you should be getting each time you apply that joint to a body.
if you delete the joint them the body is free to rotate and move anyway is allowed to move and rotate.

here are the software restrictions.

1-there evaluation of the plane equation is done via a numerical linear matrix solver using a numerical method and numerical integration, therefore the instant error will not be an absolute zero, however the average error should be zero at all time.

2-you only use this joint or a subclass of this joint with root a body of any hierarchy, not doing so will lead to explosions or malfunction of the joint solver. This is, if you have a rag doll of any other arrangement of connected body, you only apply the joint to one body, in the case of graphics this will be the root body.

3- to make a player body similar to the upVector in 3d of the joint library, you use a sub class of the dCustomPlane joint, this joint does not exist in the joint library, but there is a user defined joint in the Flatland demo that does the job. I will copy the code here again.
Code: Select all
class dPlane2dUpVector: public dCustomPlane
{
   public:
   dPlane2dUpVector (const dVector& pivot, const dVector& normal, NewtonBody* const child)
      :dCustomPlane (pivot, normal, child)
   {
   }

   void SubmitConstraints (dFloat timestep, int threadIndex)
   {
      dMatrix matrix0;
      dMatrix matrix1;

      // add one row to prevent body from rotating on the plane of motion
      CalculateGlobalMatrix(matrix0, matrix1);

      dFloat pitchAngle = CalculateAngle(matrix0.m_up, matrix1.m_up, matrix1.m_front);
      NewtonUserJointAddAngularRow(m_joint, pitchAngle, &matrix1.m_front[0]);

      // add rows to fix matrix body the the plane
      dCustomPlane::SubmitConstraints(timestep, threadIndex);
   }
};

Other that this, I do not really know how else I can explain this anymore.

It has been my greatest disappointment than in 16 years going 17, most people has simply ignored the engine based on other peoples narrative, and the very few people who are still using it,
still get this trivial problems that still baffled me, but to that, there is nothing I can really do.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Multiple Floating Point Traps

Postby Lax » Sun Dec 29, 2019 6:18 am

Hi Julio,

ok thanks for the explanation. I already understood your descriptions and did as you proposed. The only thing, that I missed is the custom joint implementation of upvector and plane, sorry for that.

It has been my greatest disappointment than in 16 years going 17, most people has simply ignored the engine based on other peoples narrative, and the very few people who are still using it,
still get this trivial problems that still baffled me, but to that, there is nothing I can really do.


I'm sorry for disappointing you. But you also must understand, that I'm creating a whole game engine in my spare time and physics are just one topic besides ai, 3d sound, graphics, lua scripting, game mechanics, tieding everything together, performance, Level editor etc.

So sometimes I do understand something wrong with physics etc. or have not enough physics knowledge... or it does not work correctly because like in my previous post, I set the plane constraint to early for the ragdoll's root body.

Nevertheless newton dynamics is a great engine, that eases physics implementation a lot. I'm really happy, that I can use it for my project! And I'm also happy, that you are taking time and trying to answer all questions so promptly.
Please support SecondEarthTechnicBase built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd17-5ff5-40a0-ac6f-44b97b79be62
Image
Lax
 
Posts: 165
Joined: Sat Jan 08, 2011 8:24 am

Re: Multiple Floating Point Traps

Postby Lax » Sun Dec 29, 2019 4:07 pm

Hi Julio,

I had to modify the Plane2dUpVector, because it did not work for me. The player could be no more rotated via NewtonBodySetOmega because, by setting the plane axis to (0, 0, 1), only pitch rotation was possible. So I also set besides the normal also a pin vector, which will be used for rotation. Because my player needs to be rotated around y-axis. In your Flatlandgame demo bodies are rotating around x-axis.

Here my code:
Code: Select all
class Plane2dUpVector : public dCustomPlane
   {
   public:
      Plane2dUpVector(const dVector& pivot, const dVector& normal, const dVector& pin, NewtonBody* const child)
         : dCustomPlane(pivot, normal, child),
         m_normal(normal)
      {
         
         dMatrix pinAndPivotFrame(dGrammSchmidt(pin));
         pinAndPivotFrame.m_posit = pivot;
         pinAndPivotFrame.m_posit.m_w = 1.0f;
         // calculate the two local matrix of the pivot point
         CalculateLocalMatrix(pinAndPivotFrame, m_localMatrix0, m_localMatrix1);
      }

      void SubmitConstraints(dFloat timestep, int threadIndex)
      {
         dMatrix matrix0;
         dMatrix matrix1;

         // add one row to prevent body from rotating on the plane of motion
         CalculateGlobalMatrix(matrix0, matrix1);

         dFloat pitchAngle = CalculateAngle(matrix0.m_up, matrix1.m_up, matrix1.m_front);
         NewtonUserJointAddAngularRow(m_joint, pitchAngle, &matrix1.m_front[0]);

         // Restrict the movement on the pivot point along all two orthonormal axis direction perpendicular to the motion
                       
                        // Set the specified normal
         const dVector& dir = m_normal;
         const dVector& p0 = matrix0.m_posit;
         const dVector& p1 = matrix1.m_posit;
         NewtonUserJointAddLinearRow(m_joint, &p0[0], &p1[0], &dir[0]);

         const dFloat invTimeStep = 1.0f / timestep;
         const dFloat dist = 0.25f * dir.DotProduct3(p1 - p0);
         const dFloat accel = NewtonUserJointCalculateRowZeroAcceleration(m_joint) + dist * invTimeStep * invTimeStep;
         NewtonUserJointSetRowAcceleration(m_joint, accel);
         NewtonUserJointSetRowStiffness(m_joint, m_stiffness);

         // construct an orthogonal coordinate system with these two vectors
         NewtonUserJointAddAngularRow(m_joint, CalculateAngle(matrix0.m_front, matrix1.m_front, matrix1.m_up), &matrix1.m_up[0]);
         NewtonUserJointSetRowStiffness(m_joint, m_stiffness);
         NewtonUserJointAddAngularRow(m_joint, CalculateAngle(matrix0.m_front, matrix1.m_front, matrix1.m_right), &matrix1.m_right[0]);
         NewtonUserJointSetRowStiffness(m_joint, m_stiffness);
      }
   private:
      dVector m_normal;
   };

One strange thing I'm facing is, that the player is rotating more slowely.

Maybe you have a better idea how to get it working correctly?
Please support SecondEarthTechnicBase built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd17-5ff5-40a0-ac6f-44b97b79be62
Image
Lax
 
Posts: 165
Joined: Sat Jan 08, 2011 8:24 am

Re: Multiple Floating Point Traps

Postby Julio Jerez » Sun Dec 29, 2019 4:39 pm

Are you saying that you want a 2d joint that, only forces the pivot point to the plane but that the body can rotate arbitraritlly around all three axis?
Are the rotation free or motors?
You keep say rotation around x or rotation around other axis.
I am very confused as to find out what is it that you seek.

The joint that can let you place a body anywhere you want with any arbitrary rotation, is called dCustomkinematic joint.

This you pass an arbitrary matrix and the joint moves the body to align to that matrix.
Maybe that will work better for your player.
The you just tell the player were to be and how to orient at will.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Multiple Floating Point Traps

Postby Lax » Mon Dec 30, 2019 8:03 am

Are you saying that you want a 2d joint that, only forces the pivot point to the plane but that the body can rotate arbitraritlly around all three axis?


The player should be movable just on x-y axis:
x: for left and right movement
y: for jump and fall
For that I use the plane joint.

The player should rotate just around y-axis on that plane. For that I use the custom 2d Up vector.

Like in this video:



At the beginning of the video the player is rotated manually via NewtonBodySetOmega(0, yaw, 0).

In your demo your bodies also can just be moved on x-y axis, just as I want, but the bodies in your demo can only be rotated around x-axis (pitch). That is not suitable for me.
Please support SecondEarthTechnicBase built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd17-5ff5-40a0-ac6f-44b97b79be62
Image
Lax
 
Posts: 165
Joined: Sat Jan 08, 2011 8:24 am

Re: Multiple Floating Point Traps

Postby Julio Jerez » Mon Dec 30, 2019 11:23 am

oh I see your player can turn around a vertical axis. did I interpreted right? is so I modify the joint to do just that. here is the joint, but you need to sync since I have to add an option to the plane joint so that only restrict the translation of the plane but not rotation.
here is the new joint now
Code: Select all
class dPlane2dUpVector: public dCustomPlane
{
   public:
   dPlane2dUpVector (const dVector& pivot, const dVector& normal, NewtonBody* const child)
      :dCustomPlane (pivot, normal, child)
   {
      EnableControlRotation(false);
   }

   void SubmitConstraints (dFloat timestep, int threadIndex)
   {
      dMatrix matrix0;
      dMatrix matrix1;

      // add rows to fix matrix body the the plane
      dCustomPlane::SubmitConstraints(timestep, threadIndex);

      // add one row to prevent body from rotating on the plane of motion
      CalculateGlobalMatrix(matrix0, matrix1);

      //dFloat pitchAngle = CalculateAngle(matrix0.m_up, matrix1.m_up, matrix1.m_front);
      NewtonUserJointAddAngularRow(m_joint, CalculateAngle(matrix0.m_up, matrix1.m_up, matrix1.m_front), &matrix1.m_front[0]);
      NewtonUserJointAddAngularRow(m_joint, CalculateAngle(matrix0.m_up, matrix1.m_up, matrix1.m_front), &matrix1.m_right[0]);
   }
};


is that video using the new system or it is still the old version where you set the velocity and rotation directly?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Multiple Floating Point Traps

Postby Lax » Mon Dec 30, 2019 1:27 pm

Hi Julio,

thanks for the modifications. I will try that out.

is that video using the new system or it is still the old version whe you set the velocity and rotation directly?

The video is old and using the ill formed system. I just wanted to show, what I want to accomplish.

Best Regards
Lax
Please support SecondEarthTechnicBase built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd17-5ff5-40a0-ac6f-44b97b79be62
Image
Lax
 
Posts: 165
Joined: Sat Jan 08, 2011 8:24 am

Re: Multiple Floating Point Traps

Postby Julio Jerez » Mon Dec 30, 2019 1:49 pm

Lax wrote:At the beginning of the video the player is rotated manually via NewtonBodySetOmega(0, yaw, 0).
.

Once you get the joint hooked, you can rotate the player around the y axis by using the applyimpulse function I stead of setting the angular velocity.

I will post the code sniped later, setting Omega will work most the cases but when the player is colliding or liked to other bodies will cause side effects that you do not want, and them you think is the physics that is wrong.
Set velocity , mass and those function are basically for setting initialization.
But first let us see if the joint is what you seek.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Multiple Floating Point Traps

Postby Julio Jerez » Mon Dec 30, 2019 3:05 pm

alright Lax, I added a little code that single out one of the upright capsules and apply an angular velocity to manipulate the body at will. Here is the function
Code: Select all
// demonstration how to set velocity directly
static void SetBodyAngularVelocity (const NewtonBody* const body, const dVector& desiredOmega, dFloat timestep)
{
   dMatrix bodyInertia;
   dVector bodyOmega(0.0f);

   // get body internal data
   NewtonBodyGetOmega(body, &bodyOmega[0]);
   NewtonBodyGetInertiaMatrix(body, &bodyInertia[0][0]);
   
   // calculate angular velocity error
   dVector omegaError (desiredOmega - bodyOmega);

   // calculate impulse
   dVector angularImpulse (bodyInertia.RotateVector(omegaError));

   // apply impulse to achieve desired omega
   dVector linearImpulse (0.0f);
   NewtonBodyApplyImpulsePair (body, &linearImpulse[0], &angularImpulse[0], timestep);
}


you can use at will from anywhere, and should not have any conflicts.
If you sync and play the Flatland demo, you will see that it even makes other player spins correctly when they collide.
if you do not want the other players to rotate that's fine too because they will
not be allow to rotate, or they are also players with their own target velocity in wich case
the friction will break not letting the other body spins,
or they are bodies that are allow to spins in which case it is the correct behavior like in
teh SDK demo. It should be like a magic Wang that always does what you expect it to do.
I hope this is what you seek.

please do not use NewtonBodySetOmega(0, yaw, 0). to control the bodies, even of you see it working, because it will work until I brakes.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Previous

Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 11 guests

cron