The purpose of this example is to demonstrate the EPhysics Velocity usage - The code adds a small bouncing ball on the ground and responding to users events by making it jump - applying a central impulse on it and showing its velocity and acceleration.
We'll see in this example how to get EPhysics_Body Linear and Angular velocity and acceleration.
For this example we'll have an EPhysics_World and one basic EPhysics_Body, we'll apply impulses that follows user events, it were already covered in EPhysics - Bouncing Ball
While in this example we'll be working with a struct to hold some objects in our code. For clarity sake we present you the struct declaration in the following block.
Calling ephysics_body_event_callback_add() will register a callback to a type of physics body event.
EPHYSICS_CALLBACK_BODY_UPDATE : called after every physics iteration. In other words, will be called after each world tick.
EPHYSICS_CALLBACK_BODY_STOPPED : called when a body is found to be stopped. In other words, when the body is not moving anymore.
See _EPhysics_Callback_Body_Type for more event types.
The callback function will be called on every physics iteration to show the linear and angular velocity and acceleration.
Here we're declaring the necessary variables to calculate acelerations and delta time. And checking if its the first time to return before shows informations about the velocity.
Get the delta time to use it soon to calculate the acceleration on every physics iteration.
Note in this part we get the angular and linear velocities.
We need to handle the velocity using delta time to have the acceleration on every tick. Check if its the first time to return before shows informations about the velocity because we don't have the old aceletations and then the calculation of this informations will be wrong.
Here we calculate the aceletarions using this formula:
(velocity - old_velocity) / delta_time;
Turning data into text, to pass it to edje shows on screen.
Here we finish the example. The full source code can be found at test_velocity.c.