EPhysics - Slider

The purpose of this example is to demonstrate the EPhysics Slider constraint usage - The code applies slider on three cubes.

slider.png

For this example we'll have an EPhysics_World, and four basic EPhysics_Bodys.

The basic concepts like - defining 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

You can use also a P2P (point to point) constraint: EPhysics - Constraint

Adding a Slider

Slider is a constraint that will limit the linear and angular moving of a body.

We'll add three sliders on the cubes, starting with the highest purple.

First we need to create a specific variable type to get EPhysics_Body constraint and create a new slider constraint passing the body which we want as parameter.

EPhysics_Constraint *constraint;

Here we define the linear moving limits of the slider constraint, in this case we just set moving limit down on Y axis (under), but if we wanted we could set left, right and above also.

Here we set the angular moving limits of the slider constraint. The angular moving limits is defined in degrees and will limit the moving on Z axis, in this case we just set the clockwise direction, but if we wanted we could set the counter clockwise direction also.

When this cube falls by the gravity, the slider constraint will act limiting its linear and angular movings, giving the impression that its hanging.

For the next two cubes is the same process.

Now we set the slider constraint of the highest blue and lowest purple, limiting moving limits to the left on X axis and applying an impulse to the left where the two cubes will be limited by the slider constraint and pushed back.

Here we finish the example. The full source code can be found at test_slider.c.