Applyforce & Applyimpulse behavior

Post Reply
Xenos
Posts: 3
Joined: Tue Nov 27, 2012 5:54 am

Applyforce & Applyimpulse behavior

Post by Xenos »

Hello,

I'm trying to build some 'ballistic missile simulator' program that relies heavily on applying force to a rigid body (the missile).
Currently I'm using the applycentralimpulse method to launch the missile (initial push).
Can someone confirm me of how this method behaves? If I apply a force, how long does that force actually works?

My current assumption is that applycentralforce works based on the time given to the following stepsimulation.
When I see the DiscreteDynamicsWorld code, any force applied to a rigidbody will be cleared after a call to stepsimulation method. Meaning that a force is active constantly during a simulation step.
given : impulse = force * working_time
If i use applycentralforce(0, 500, 0) and then call stepsimulation for 60 milliseconds step, then that will be the same as using applycentralimpulse(0, 30, 0) and calling stepsimulation for 60 miliseconds.
( 30 impulse = 500 force * 0.06 second )
Is that correct?

And about units... I used SI units (Kgs , newtons , meters, seconds). Does that means when I apply force in newtons and define mass in kilograms, I would get the positions in meters? and velocity in meter/second (from rigidbody->getLinearVelocity())?

Also, from the forum I found something about a rigidbody going into sleep mode. Causing apply force/impulse to be ignored. Does that means I always have to call rigidbody->activate() before applying force/impulse? (just to be safe)
In my experiment I didn't encounter this 'sleeping' issue though (my code is modified directly from the helloworld example). Maybe because I applied the impulse right after the the line where I added the rigidbody to a dynamicworld? When does a rigidbody sleep anyway?

Sorry if my questions are too basic. I haven't got much experience in this.
And thanks in advance!
zarlox
Posts: 31
Joined: Tue Apr 26, 2011 5:52 pm

Re: Applyforce & Applyimpulse behavior

Post by zarlox »

Xenos wrote:My current assumption is that applycentralforce works based on the time given to the following stepsimulation.
applyForce() value is for a full second. But it needs to be applied every step as the forces are cleared at the end of the step.

applyImpulse() is a instant push so it changes the velocity instantly.
Xenos wrote:And about units... I used SI units (Kgs , newtons , meters, seconds). Does that means when I apply force in newtons and define mass in kilograms, I would get the positions in meters? and velocity in meter/second (from rigidbody->getLinearVelocity())?
Yes Bullet AFAIK is using those same units by default, so you will have velocity in meters per second.
Xenos
Posts: 3
Joined: Tue Nov 27, 2012 5:54 am

Re: Applyforce & Applyimpulse behavior

Post by Xenos »

What happens when I don't re-apply the force at the end of a step?
Are my assumption correct? Will that force be active only for the step time (not a whole second)?
zarlox
Posts: 31
Joined: Tue Apr 26, 2011 5:52 pm

Re: Applyforce & Applyimpulse behavior

Post by zarlox »

In fact, both force and impulse are valid on the current physic step only. The difference is the value argument where :

Impulse value is the instant change in velocity applied on the next physic update.

Force value is the change in velocity over one second, BUT applied only for the current deltaTimeStep. This is why you need to call ApplyForce every step.

So 10 calls to applyImpulse(1) over a second should result as the same momentum as calling applyForce(10) on each update for 1 second.

And by the way, if you do your updates in the btActionInterface::UpdateAction() or inside the post tick callback, the StepSimulation() will already have done its physic calculation for the current step and will clear the forces applied via applyForce() and applyCentralForce(). So if you want to use those function, use them inside the pre-tick callback.

The best way to understand the simulation is to trace into the StepSimulation() call.
Post Reply