# NewtonApplyForceAndTorque

## NewtonApplyForceAndTorque

```typedef void (*NewtonApplyForceAndTorque) (const NewtonBody* body, dFloat timestep, int threadIndex);
```

## Usage

This is probably the most often used Newton callback. This callback is called once per frame, during NewtonUpdate call. It allow you to apply force and torque to a simulated body, to make physical shape move and interact dynamically, common use for this can be like simple gravity, to complex character controller or raycast car physics, this callback lets you tell newton what a object does physically in a simulated newton world.

You can assign it to body using NewtonBodySetForceAndTorqueCallback function.

## Remarks

• This is not a library function, but a callback event.
• The callback is not called for bodies that are static (Zero mass or Collision trees and heightmap collision shapes).
• Changing from Newton 1.53, this callback is now also always called for sleeping / frozen bodies in newton 2.0, applying sufficient force in the callback will wake up the newton body back to normal state (see NewtonBodyGetSleepState NewtonBodyGetAutoSleep and NewtonBodySetAutoSleep).

## Example

```   float force[3], torque[3];

void _cdecl callbackForce(const NewtonBody* body)
{
}
```

Simple Earth Gravity example:

```void _cdecl callbackSimpleGravity(const NewtonBody* body)
{
float force[3];
float mass;
float inertia[3];

NewtonBodyGetMassMatrix( body, &mass, &inertia[0] );

float force[0] = 0.0f;
float force[1] = -9.8f * mass;
float force[2] = 0.0f;

}
```

A more 'object-oriented' example:

```   void _cdecl callbackForce(const NewtonBody* body)
{
CSceneMoveableObject *obj = ((CSceneMoveableObject*)NewtonBodyGetUserData(body));

obj->ClearForceTorque();
}
```