MADEAPPS / newton-dynamics

Newton Dynamics is an integrated solution for real time simulation of physics environments.
http://www.newtondynamics.com
Other
928 stars 183 forks source link

How to change mass of body? #301

Closed olitheolix closed 1 year ago

olitheolix commented 1 year ago

I would like to change the mass of the demo body from 1kg to 2kg and verify that it now only moves 0.25m when pushed with a force of 1N for 1s. I thought I could do that with setMassMatrix but apparently not. How do I specify the mass of a body, please?

JulioJerez commented 1 year ago

ah, I see you are using body->SetMassMatrix(1.0f, sphere); body->SetMassMatrix(2.0f, sphere);

That's the correct way, and if you read the mass, you will see that is in 2.0 but that is not going to do it as long as the gravity acting on the body is the same constant. It is the famous Galileo experiments, remember. Gravity applies equally regardless of the mass. Two falling bodies from the same high, will reach the floor at the same time, regardless of their mass. In fact, if it generated different result, that would be an indication of something wrong in the engine.

if you want to change the force acting of the body. It could be a good exercise for you by making custom notify call and apply a different force on the body or change the gravity. but if you want to make the quickest test you can apply the different gravity like this.

ndVector gravity = ndVector(0.5f, 0.f, 0.f, 0.f); ndBodyDynamic *sphere = BuildSphere(spherePos, gravity); world.AddBody(sphere);

I merged the PR.

JulioJerez commented 1 year ago

If I undertand what you try to test. The way to do it is by making a notify callback. Them in the ApplyFirceAnd torque You any a fix forze of 1.0 instead of a force equal M * gravity

That way, since the force is constant, them the more massive the body, the lower the acceleration.

And I guess that's what you try to do.

olitheolix commented 1 year ago

If you want to change the force acting of the body

Yes, that is what I was trying to do. The self contained problem statement in the PR description makes that very clear, as does the doc string on the test...

For some reason, I always thought that Newton treats the gravity value as a force, and that is why I tried to hijack it for the test.

I merged the PR.

Why would anyone knowingly merge a PR that breaks master?

JulioJerez commented 1 year ago

Yes gravity is treated as a force. If you look at the default notify callback. It read the body mass and scale the gravity by that value. So each body with default notify will get a force equal to gravity scaled by the body mass.

JulioJerez commented 1 year ago

alright I added a test that show how to go about setting a callback that set a const force to bodies with different masses.