The purpose of this example is to demonstrate the E\+Physics Shapes usage -\/ The code creates two E\+Physics\+\_\+\+Bodys using a custom shape.

 
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics{shapes}}
\end{DoxyImageNoCaption}


For this example we'll have an E\+Physics\+\_\+\+World, and two basic E\+Physics\+\_\+\+Bodys.

The basic concepts like -\/ defining an E\+Physics\+\_\+\+World, render geometry, physics limiting boundaries, add an E\+Physics\+\_\+\+Body, associate it to evas objects, change restitution, friction and impulse properties, were already covered in \hyperlink{tutorial_ephysics_bouncing_ball}{E\+Physics -\/ Bouncing Ball}\hypertarget{tutorial_ephysics_shapes_add-shape}{}\section{Adding a Shape}\label{tutorial_ephysics_shapes_add-shape}


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

A shape consists in a group of points, the vertices of the body to be created later with \hyperlink{group__EPhysics__Body_gabe733ecf3e04d267005118ff7291daab}{ephysics\+\_\+body\+\_\+shape\+\_\+add()}. You can also save and load it from a file.

We'll have to create a specific type of variable\+: \hyperlink{group__EPhysics__Shape}{E\+Physics Shape}


\begin{DoxyCodeInclude}
\_world\_populate(Test\_Data *test\_data)
\{
   \hyperlink{group__EPhysics__Shape_gadfcc565af1b4e898f2959292a9089e7e}{EPhysics\_Shape} *pentagon\_shape, *hexagon\_shape;
   \hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body} *pentagon\_body, *hexagon\_body;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *pentagon, *hexagon;

\end{DoxyCodeInclude}


First we add an image we want to add an E\+Physics\+\_\+\+Body to have a reference to after set the points (vertices).


\begin{DoxyCodeInclude}
   pentagon = elm\_image\_add(test\_data->win);
   elm\_image\_file\_set(
      pentagon, PACKAGE\_DATA\_DIR \textcolor{stringliteral}{"/"} EPHYSICS\_TEST\_THEME \textcolor{stringliteral}{".edj"}, \textcolor{stringliteral}{"pentagon"});
   evas\_object\_move(pentagon, WIDTH / 3, HEIGHT / 2 - 80);
   evas\_object\_resize(pentagon, 70, 68);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(pentagon);

\end{DoxyCodeInclude}


Here we create a new shape, note that the returned shape initially doesn't has points set, so its requiered to set vertices.


\begin{DoxyCodeInclude}
   pentagon\_shape = \hyperlink{group__EPhysics__Shape_ga79ca252f9b15296416c3f73c75efa293}{ephysics\_shape\_new}();

\end{DoxyCodeInclude}


Now we're setting the shape points (vertices) basing on the image that we added, two vertices form a link between them, an edge, so with some vertices is possible to create polygons, in this case a pentagon.


\begin{DoxyCodeInclude}
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(pentagon\_shape, -1, -9/33., -1);
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(pentagon\_shape, -1, -9/33., 1);
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(pentagon\_shape, 0, -1, -1);
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(pentagon\_shape, 0, -1, 1);
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(pentagon\_shape, 1, -9/33., -1);
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(pentagon\_shape, 1, -9/33., 1);
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(pentagon\_shape, -21/35., 1, -1);
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(pentagon\_shape, -21/35., 1, 1);
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(pentagon\_shape, 21/35., 1, -1);
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(pentagon\_shape, 21/35., 1, 1);

\end{DoxyCodeInclude}


Here we create a new physics body using a custom shape. The center of mass will be the center of the shape. Its collision shape will be the convex shape that has all the points (and edges) we added to this shape before.


\begin{DoxyCodeInclude}
   pentagon\_body = \hyperlink{group__EPhysics__Body_gabe733ecf3e04d267005118ff7291daab}{ephysics\_body\_shape\_add}(test\_data->world, pentagon\_shape);
   \hyperlink{group__EPhysics__Body_ga39cb9e95bbe1d097926a09365c501db3}{ephysics\_body\_evas\_object\_set}(pentagon\_body, pentagon, 
      \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE});
   \hyperlink{group__EPhysics__Body_ga731c9a6443f7c4294fce23fc1287b778}{ephysics\_body\_restitution\_set}(pentagon\_body, 1);

\end{DoxyCodeInclude}


Here we just delete the custom shape (not the body) after 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.


\begin{DoxyCodeInclude}
   \hyperlink{group__EPhysics__Shape_ga9d91574e5cdac7772d6c75c22c32d8a7}{ephysics\_shape\_del}(pentagon\_shape);

\end{DoxyCodeInclude}


In the example we add another shape with the same process we just used, but with different image and points.




\begin{DoxyCodeInclude}
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(hexagon\_shape, 0, 30, -10);
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(hexagon\_shape, 0, 30, 10);
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(hexagon\_shape, 18, 0, -10);
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(hexagon\_shape, 18, 0, 10);
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(hexagon\_shape, 52, 0, -10);
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(hexagon\_shape, 52, 0, 10);
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(hexagon\_shape, 70, 30, -10);
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(hexagon\_shape, 70, 30, 10);
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(hexagon\_shape, 52, 60, -10);
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(hexagon\_shape, 52, 60, 10);
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(hexagon\_shape, 18, 60, -10);
   \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}(hexagon\_shape, 18, 60, 10);

\end{DoxyCodeInclude}


Here we finish the example. The full source code can be found at \hyperlink{test_shapes_c}{test\+\_\+shapes.\+c}. 