Skip to content
Uri edited this page Feb 7, 2025 · 4 revisions

FAQ

General questions

Q: Is there a MAC / LINUX version of Newton?

Yes, both MAC and LINUX version are now available for download from the Newton homepage.

Q: What languages are supported, where do I get headers?

The SDK only includes a header for C/C++ and it should work with Visual Studio 6.0 and up.

Q: Can I manually dynamically move an otherwise static TriMesh without having objects sink through it?

Sometimes you may wish to move portions of static game world for creating elevators, trains and other special animations.

If you want to move an immobile object (mass = 0), then you need to:

  • set it's velocity using NewtonBodySetVelocity()
  • every frame, manually use NewtonBodySetMatrix() to move the body's position according to its velocity
  • every frame, wake up all objects within this body's AABB using NewtonWorldForEachBodyInAABBDo() or NewtonWorldGetFirst/NextBody() and NewtonBodySetSleepState()
(psuedo-code)
game loop
{
    if body has 0 mass and NewtonBodyGetVelocity(body) != vec3(0, 0, 0)
        mat4 position = NewtonBodyGetMatrix(body)
        position.translate(NewtonBodyGetVelocity(body) * deltaTime)
        NewtonBodySetMatrix(body, position)

        vec3 min, max = NewtonCollisionCalculateAABB(body.collision, position)
        for each body in AABB(min, max) do // can be done via NewtonWorldForEachBodyInAABBDo(), for example
            NewtonBodySetSleepState(body, 0)
}

Now dynamic objects will react properly to any immobile mesh that is 'manually' moving (even if it's a tree collision). You can also use this technique to set the position of a body (not via velocity, forces or joints) and make other bodies react properly - simply move it as such, and set the velocity to the vector (newPosition - oldPosition). Then perform the rest of the operations above.

If it's not an immobile object, simply use NewtonBodySetVelocity() or NewtonBodyAddImpulse() to give the body a velocity.

Newton SDK - specific questions

Q: How can I control an object using a physics engine?

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 in the 1700's deducted the expression by applying Newton's second law to a set of particle an integrating then over the body. He found out that the solution can be decouple 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:

F = f1 + f2
T = R1 * f1 + (- R2 * f2)
Since R1 = R2, and f1 = f2
F = 2f
T = 0

No spin and straight motion

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:

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:

F = f1 + (f2 / df)
T = R1 * f1 / R2 * (f2 - df)
F = 2f1 /dF
T = R1 * df > 0

Still turn to the right and also slow down at the same time.

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:

F1 = N1 / K * V;

Where N1 is the nominal engine Thrust controlled by the pilot, K is the combine attenuation generated by air drag, internal engine drag etc. and V is the linear velocity of the point where the force is applied on the rigid body. (It is important to notice that V is not the velocity of the object, but the velocity at the point in the body), and then you plug in this into to the previous formulas.

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:

AddGlobalForce (Force, Point)
{
   R = Point / BodyMatrix.Position;
   Torque = CrossProduct (R, Force);
   NewtonAddForce (Force)
   NewtonAddTorque (Torque)
}
AddLocalForce (LocalForce, localPoint)
{
   GlobaForce = BodyMatrixRotate (Force)
   GlobalPoint = BodyMatrixTranform (localPoint)
   AddGlobalForce (GlobaForce, GlobalPoint);
}

Q: The collision tree does not seem to work correctly?

...

Q: What's the difference between AddForce and SetForce?

...

Q: Why isn't raycast working sometimes?

...

Q: How do I remove drag from the system completely?

...

Q: Blowing up in extremes

...

Q: My newton bodies aren't updating and my callbacks are set up correctly!

...

Q: Linker errors

...

General Physics Programming questions

Q: What is "Time-slicing"?

...

Q: What value should I pass to "NewtonUpdate?

...