Typedefs | Functions
EPhysics Shape

Shapes are used to create bodies with shapes that differ from primitive ones, like box and cylinder. More...

Typedefs

typedef struct _EPhysics_Shape EPhysics_Shape
 Shape handle, represents a shape to be used to create a body. More...
 

Functions

EAPI EPhysics_Shapeephysics_shape_new (void)
 Create a new shape. More...
 
EAPI void ephysics_shape_del (EPhysics_Shape *shape)
 Delete a shape. More...
 
EAPI Eina_Bool ephysics_shape_point_add (EPhysics_Shape *shape, double x, double y, double z)
 Add a new point to the shape. More...
 
EAPI EPhysics_Shapeephysics_shape_load (const char *filename)
 Load the shape from a file. More...
 
EAPI Eina_Bool ephysics_shape_save (const EPhysics_Shape *shape, const char *filename)
 Save the shape to a file. More...
 

Detailed Description

Shapes are used to create bodies with shapes that differ from primitive ones, like box and cylinder.

A shape consists in a group of points, the vertices of the body to be created later with ephysics_body_shape_add().

A new shape is created with ephysics_shape_new() and points are set with ephysics_shape_point_add(). A shape can be used to create many bodies. When done, it's required to delete the shape with ephysics_shape_del().

A shape can be loaded from a file describing it with ephysics_shape_load(), and can be saved to a file with ephysics_shape_save(). With that shapes can be done or visualized on design applications.

Note
Using primitive shapes has better performance than generic shapes.
For now, only convex shapes are supported.

Typedef Documentation

◆ EPhysics_Shape

Shape handle, represents a shape to be used to create a body.

Created with ephysics_shape_new() and deleted with ephysics_shape_del().

Function Documentation

◆ ephysics_shape_new()

EAPI EPhysics_Shape * ephysics_shape_new ( void  )

Create a new shape.

The returned shape initially doesn't has points set, so it's required to set vertices with ephysics_shape_point_add().

After the shape is completely defined, all the points were added, it's possible to create one or more bodies with ephysics_body_shape_add().

Returns
The created shape or NULL on error.
See also
ephysics_shape_del().
ephysics_shape_load().
Examples
test_shapes.c.

◆ ephysics_shape_del()

EAPI void ephysics_shape_del ( EPhysics_Shape shape)

Delete a shape.

After a shape is used to create the wanted bodies, it's required to delete it. It won't be deleted automatically by ephysics at any point, even on shutdown. The creator is responsible to free it after usage is concluded.

Parameters
shapeThe shape to be deleted.
See also
ephysics_shape_new().
Examples
test_shapes.c.

◆ ephysics_shape_point_add()

EAPI Eina_Bool ephysics_shape_point_add ( EPhysics_Shape shape,
double  x,
double  y,
double  z 
)

Add a new point to the shape.

Any point can be added to a shape, but only vertices matter. A vertex is a special kind of point that describes a corner of geometric shapes. The final shape will be constructed in such a way it will have all the added points and will be convex.

The center of mass will be the centroid, or geometric center of the shape.

The order of points doesn't matter.

For example, to create a pentagon:

ephysics_shape_point_add(shape, 0, 24, -10);
ephysics_shape_point_add(shape, 0, 24, 10);
ephysics_shape_point_add(shape, 35, 0, -10);
ephysics_shape_point_add(shape, 35, 0, 10);
ephysics_shape_point_add(shape, 70, 24, -10);
ephysics_shape_point_add(shape, 70, 24, 10);
ephysics_shape_point_add(shape, 56, 66, -10);
ephysics_shape_point_add(shape, 56, 66, 10);
ephysics_shape_point_add(shape, 14, 66, -10);
ephysics_shape_point_add(shape, 14, 66, 10);
EAPI EPhysics_Body * ephysics_body_shape_add(EPhysics_World *world, EPhysics_Shape *shape)
Create a new physics body using a custom shape.
EAPI Eina_Bool ephysics_shape_point_add(EPhysics_Shape *shape, double x, double y, double z)
Add a new point to the shape.
EAPI void ephysics_shape_del(EPhysics_Shape *shape)
Delete a shape.
struct _EPhysics_Shape EPhysics_Shape
Shape handle, represents a shape to be used to create a body.
Definition: EPhysics.h:507
EAPI EPhysics_Shape * ephysics_shape_new(void)
Create a new shape.
Parameters
shapeThe shape to be modified.
xPoint position at x axis.
yPoint position at y axis.
zPoint position at z axis.
Returns
EINA_TRUE on success or EINA_FALSE on error.
See also
ephysics_shape_new().
Examples
test_shapes.c.

◆ ephysics_shape_load()

EAPI EPhysics_Shape * ephysics_shape_load ( const char *  filename)

Load the shape from a file.

Useful to edit shapes on design tools and load it from an exported file.

Also it helps to avoid lots of ephysics_shape_point_add() in the code, and keep a better separation between code logic and design stuff.

Parameters
filenameThe path to the file describing the shape.
Returns
The loaded shape or NULL on error.
Note
Not implemented yet.
See also
ephysics_shape_new() for more details.
ephysics_shape_save().

◆ ephysics_shape_save()

EAPI Eina_Bool ephysics_shape_save ( const EPhysics_Shape shape,
const char *  filename 
)

Save the shape to a file.

It can be useful to visualize it on design tools.

Parameters
shapeThe shape to be saved.
filenameThe path to save the shape.
Returns
EINA_TRUE on success or EINA_FALSE on error.
Note
Not implemented yet.
See also
ephysics_shape_new().
ephysics_shape_load().