The purpose of this example is to demonstrate the EPhysics_Camera Track usage.
The EPhysics_Camera facilitates the usage of scenarios bigger than the viewport, that's because the EPhysics handles the position of objects which has control.
For this example we'll have an EPhysics_World, one main EPhysics_Body that will be tracked by an EPhysics_Camera on three ways, horizontal, vertical and full tracking. Also nine EPhysics_Bodys with mass 0, that will be used as scenario in order to our main body change its position on x and y axes when passes through this scenario.
The basic concepts like - initializing an EPhysics_World, render geometry, physics limiting boundaries, add an Ephysics_Body, associate it to evas objects, change restitution, friction and impulse properties, 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.
In this example we'll use 3 kinds of tracking, to change this values we'll have an Elementary spinner widget and handle it on this function.
Every world has a camera, so here we get this camera used by our EPhysics_World.
Here we'll get the elm_spinner value to the tracking base on this value
Here we'll set the camera to track the body, when a body is tracked, the camera will move automatically, following this body. It will keeps the body centralized on rendered area. If it will be centralized horizontally and / or vertically depends if parameters horizontal and vertical are set to EINA_TRUE, in this case we based these values on elm_spinner.
Here we'll use 2 floor images to give the impression of an infinite ground.
Calling ephysics_world_event_callback_add() will register a callback to a type of physics world event.
EPHYSICS_CALLBACK_WORLD_CAMERA_MOVED : called if the camera position changed on physics simulation tick.
In the function, we'll get the cameras position to know how much the camera moved and move the same value to the floor passing it as delta_x to the function, note that we use an old_x variable to do this calculation.
We'll get also if the body is being tracked on x and y axes. If the body isn't being tracked on x axis the floors x position won't change, delta_x will be zero.
Here we get the floors position and plus the delta_x value to move the floor in the same "velocity".
We use 2 floor images because whenever one exits the screen by the left side, another is being shown, when it happens the one which exit the screen is sent to the right side, entering into an infinite loop, giving the impression of an infinite ground image. Its important to note that we need to use the fx to don't gap the images.
Note that the fy is being defined considering its offsets, -20 is to the floor image be above the floor, thus having an border above the collision point, +40 is the render area height, to offset the cameras y, basically to draw in the correct position in the canvas.
Here we finish the example. The full source code can be found at test_camera_track.c.