Tutorial 102 - The ForceAndTorqueCallback

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Tutorial 102 - The ForceAndTorqueCallback

Postby Mumbles » Thu Aug 05, 2010 9:22 am

Hello everyone.

I'm reading through the beginners tutorials to try and understand how the engine works. However I'm failing to understand the ForceAndTorqueCallback function in tutorial 102.

I can see that it works, but I cannot see why.

Code: Select all
void ApplyForceAndTorqueCallback (const NewtonBody* body, dFloat timestep, int threadIndex)
{
   dFloat Ixx;
   dFloat Iyy;
   dFloat Izz;
   dFloat mass;

   // for this tutorial the only external force in the Gravity
   NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);

   dVector gravityForce  (0.0f, mass * GRAVITY, 0.0f, 1.0f);
   NewtonBodySetForce(body, &gravityForce[0]);
}


So, the gravitational force is calculated, but then it's applied ... using SetForce.

As I understand it, this would cause the body to fall at a constant speed of 10 m/sec. Rather than 10 m/sec/sec. I would have thought that AddForce would be correct here.

While I can't understand why this works, I can't really learn from it. I presume I have either not understood something, or that I have not read something that I should have done. Hopefully in either case, someone can explain why I'm not understanding this.

Thanks in advance for any help on this.
Mumbles
 
Posts: 9
Joined: Thu Aug 05, 2010 9:06 am

Re: Tutorial 102 - The ForceAndTorqueCallback

Postby Julio Jerez » Thu Aug 05, 2010 9:37 am

Mumbles wrote:As I understand it, this would cause the body to fall at a constant speed of 10 m/sec. Rather than 10 m/sec/sec. I would have thought that AddForce would be correct here.


this would cause the body to fall at a constant 10 m/sec/sec.
Julio Jerez
Moderator
Moderator
 
Posts: 12452
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Tutorial 102 - The ForceAndTorqueCallback

Postby Mumbles » Thu Aug 05, 2010 10:30 am

OK, but in this particular example what would happen if I changed the SetForce to AddForce?
I ask because I have just tried this, and did not see a difference.

Is the gravity influence from the previous timestep added after the callback?

Because I cannot see a difference I am thinking, that at the start of the callback the forces are 0. Is this the case? I had expected them to be the same as they were in the previous timestep.
Mumbles
 
Posts: 9
Joined: Thu Aug 05, 2010 9:06 am

Re: Tutorial 102 - The ForceAndTorqueCallback

Postby Julio Jerez » Thu Aug 05, 2010 1:24 pm

Force acculmulators are cleared in each call to newton update.

say you have a system of bodies, one is gravity, oteh is a airplane, oteh use Boyancy, and so on.
you can write many funce and torque callback and each one will add a force to eth accumulator.

basicalli add force and to teh force tha was already in the accumulator.
an example of that are joints, they can add force to the accumulation after Gravity is applied in teh force and torque callback.

the reason you do not see any difference is beacuse ther is onle one force applied, but if you apply more then you will see the difference.
Julio Jerez
Moderator
Moderator
 
Posts: 12452
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Tutorial 102 - The ForceAndTorqueCallback

Postby Mumbles » Fri Aug 06, 2010 11:18 am

Julio Jerez wrote:Force acculmulators are cleared in each call to newton update.


This is what I do not understand. If the forces are cleared, then why does the box not fall at a constant speed when using SetForce in the callback? Does this not set the force the same value every time? Unless GetMassMatrix() is returning a different value each time.
Mumbles
 
Posts: 9
Joined: Thu Aug 05, 2010 9:06 am

Re: Tutorial 102 - The ForceAndTorqueCallback

Postby Julio Jerez » Fri Aug 06, 2010 1:48 pm

because the Newton second law of motion states that the net force on a particle is equal its mass time the acceleration.
When the body is in free fall, the acceleration is the gravity which is constant.
so you can write

F = M * A = M * G

but A = g = change in velocity / change in time

g = (v2 - v1) / deltatime

if initial velocity is zero, at the inde of a time step you can write

f = m * g = m * (v2 - v1) / dt = m * v2 / dt

from there you can see that at the end of some time the velocity has changed by

v2 = g * dt;

the velocity changes linear with time, when the acceleration is constact.

if you do not apply gravity in the call back, then the first law of motion apply, which say the body will keep its state of motion unless there are extenal forces acting on it.
Setting Force to zero causes the body to keep moving with its current velocity until it hit another body.

you can get that for the above formule

f = 0 = m * g = m * (v2 - v1) / dt

since mass and tiem is not zero then (v2 - v1) most be zero
(v2 - v1) = 0
v1 = v2

meaning the body retain its current velocity when the net force is zero.
Julio Jerez
Moderator
Moderator
 
Posts: 12452
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Tutorial 102 - The ForceAndTorqueCallback

Postby Mumbles » Sat Aug 07, 2010 9:35 am

Julio Jerez wrote:if you do not apply gravity in the call back, then the first law of motion apply, which say the body will keep its state of motion unless there are extenal forces acting on it.
setting Force to zero causes the body to keep moving with its current velocity until it hit another body.


That is what didn't realise. I thought SetForce with a value of zero would make the body stop instantly. Rather than retaining it's current velocity. Back in school I was in the thickos class for science, so they did not teach us any of those laws. Now I know this, I can carry on with the tutorials. So thanks for your time, and help! It's greatly appreciated!
Mumbles
 
Posts: 9
Joined: Thu Aug 05, 2010 9:06 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 228 guests