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_Shape * | ephysics_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_Shape * | ephysics_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... | |
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.
Shape handle, represents a shape to be used to create a body.
Created with ephysics_shape_new() and deleted with ephysics_shape_del().
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().
NULL
on error.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.
shape | The shape to be deleted. |
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:
shape | The shape to be modified. |
x | Point position at x axis. |
y | Point position at y axis. |
z | Point position at z axis. |
EINA_TRUE
on success or EINA_FALSE on error.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.
filename | The path to the file describing the shape. |
NULL
on error.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.
shape | The shape to be saved. |
filename | The path to save the shape. |
EINA_TRUE
on success or EINA_FALSE on error.