EPhysics Shape

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files
- Examples

Typedefs | Functions
EPhysics Shape
EPhysics

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...

## 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 perfomance 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

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.

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

  shape | The shape to be deleted.

See also
  ephysics_shape_new().

Examples:
  test_shapes.c.

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:

1 EPhysics_Shape *shape = ephysics_shape_new();
2
3 ephysics_shape_point_add(shape, 0, 24, -10);
4 ephysics_shape_point_add(shape, 0, 24, 10);
5 ephysics_shape_point_add(shape, 35, 0, -10);
6 ephysics_shape_point_add(shape, 35, 0, 10);
7 ephysics_shape_point_add(shape, 70, 24, -10);
8 ephysics_shape_point_add(shape, 70, 24, 10);
9 ephysics_shape_point_add(shape, 56, 66, -10);
10 ephysics_shape_point_add(shape, 56, 66, 10);
11 ephysics_shape_point_add(shape, 14, 66, -10);
12 ephysics_shape_point_add(shape, 14, 66, 10);
13
14 ephysics_body_shape_add(world, shape);
15
16 ephysics_shape_del(shape);

Parameters

  shape | The shape to be modified.
  x | Point position at x axis.
  y | Point position at y axis.
  z | Point position at z axis.

Returns
  `EINA_TRUE` on success or EINA_FALSE on error.

See also
  ephysics_shape_new().

Examples:
  test_shapes.c.

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

  filename | The 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().

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

  shape | The shape to be saved.
  filename | The 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().