Most of the time beginners and medium level programmers are intimidated when they are faced with the challenge of controlling a vehicle or character using a real time physics engine.

There are not fundamental differences between a real time physics engine and most in house implementations of real time physics, when the later abide by the laws of physics.

The first thing we need to understand is that torque is not a real quantity, that's why people have such hard time imaging a torque. I certainly do too, if you read in the Newton forum you will notice I almost never talk about torque nor I use torque in any of the demos to control anything.

So if torque does not exist then what is it? Torque is the mathematical consequence of applying Newton's second and third law to a group of particles tight together called rigid body. Leonard Euler deducted the expression by applying Newton's second law to a set of particles an integrating then over the body. He found out that the solution can be decoupled from the equations of linear motion for each particle, and that the motion of each particle can be interpolated from the motion of the center of mass, the mass, and the position of the particle relative to the center of distribution. In conclusion the reason it is so hard to imaging torque, is because there is not such thing as principle of conservation of torque, or Euler's second law of torque. Torque plain and simple is a mathematical consequence not a principle.

For example, everybody knows that is you push an object at the center the object moves straight, but if you push the object at an offset from the center, the object tends to rotate to the side opposite to the point where the forces was applied. In reality what happens is that the particles directly on the point where the force was applied starts to move in straight line, and every other particle away from that one will get a reaction force generated by the link connecting them to the neighbor particle. The ones in near proximity get more reaction and they move in the same direction. The one at the origin does not move at all, and the ones past the origin move backwards. The net effect is a rotation of the body.

Looking at the problem this way is a futile and useless effort, however it helps to understand what is going on. Euler was bother by this and he tried to solve the problem mathematically. He found out that the solution to the problem is equivalent to solving a problem where the force is applied to the center of gravity of the body, and a quantity equivalent to R * F (point of focus cross product) to spin the object.

That simplifies the problem a lot. Because now we know (thanks to Euler) we most never use torque to control an object; we should only apply forces at a point.

Two examples to clarity further. Say you have an helicopter in real life, every one knows that to push the helicopter forward we need thrusters on each side, when both thruster push with equal force what you get is:

- Code: Select all
`F = f1 + f2`

T = R1 * f1 + (- R2 * f2)

Since R1 = R2, and f1 = f2

F = 2f

T = 0

Now say you want to turn right, say also R1 is the right thruster.

Every one knows that to do that one must increase the trust in the right thruster, so we get

- Code: Select all
`F = (f1 + df) + f2`

T = R1 * (f1 + df) - R2 * f2

F = 2 * f1 + df

T = R * dF > 0

a net torque, plus straight motion

However you will find that this will accelerate during the turn, and in real life the pilots probably slow down during turn, so instead of increasing the right trust, they decrease the left thrust, or they increase the right thruster and decrease the left at the same time. Say they decrease the left.

- Code: Select all
`F = f1 + (f2 - df)`

T = R1 * f1 - R2 * (f2 - df)

F = 2f1 - dF

T = R1 * df > 0

Also you need to decrease the forces as you move forward. So instead of the thrusters applying a constant force they apply a force that is smaller the faster the helicopter goes, something like this

- Code: Select all
`F1 = N1 - K * V;`

If you get this concept you will find that you will be able to control no just helicopters but anything you want. The good thing about this is that the result will always be realistic. Meaning the model can be set in reality, the only thing separating your model from a real one is how good you are a thinking of how to apply those forces, and also the inevitable errors we get from numerical integration.

To put this into practice, the application must implement a set of utility functions that are not provided by the physics engine as they can be easily written using the generic functionality.

- Code: Select all
`AddGlobalForce (Force, Point)`

{

R = Point - BodyMatrix.Position;

Torque = CrossProduct (R, Force);

NewtonAddForce (Force)

NewtonAddTorque (Torque)

}

AddLocalForce (LocalForce, localPoint)

{

GlobaForce = BodyMatrixRotate (LocalForce)

GlobalPoint = BodyMatrixTranform (localPoint)

AddGlobalForce (GlobaForce, GlobalPoint);

}