Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change mass of body? #301

Merged
merged 1 commit into from
Oct 18, 2022

Conversation

olitheolix
Copy link
Contributor

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 JulioJerez merged commit 9ba9f9a into MADEAPPS:master Oct 18, 2022
@JulioJerez
Copy link
Contributor

JulioJerez commented Oct 18, 2022

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
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants