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

 
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth,height=\textheight/2,keepaspectratio=true]{shapes}}
\end{DoxyImageNoCaption}


For this example we\textquotesingle{}ll have an EPhysics\+\_\+\+World, and two 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 \mbox{\hyperlink{tutorial_ephysics_bouncing_ball}{EPhysics -\/ Bouncing Ball}}\hypertarget{tutorial_ephysics_shapes_add-shape}{}\doxysection{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 \mbox{\hyperlink{group__EPhysics__Body_gaee1301dfd2548f4774d5e4cb81b14385}{ephysics\+\_\+body\+\_\+shape\+\_\+add()}}. You can also save and load it from a file.

We\textquotesingle{}ll have to create a specific type of variable\+: \mbox{\hyperlink{group__EPhysics__Shape}{EPhysics Shape}}


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

\end{DoxyCodeInclude}
 First we add an image we want to add an EPhysics\+\_\+\+Body to have a reference to after set the points (vertices).


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

\end{DoxyCodeInclude}
 Here we create a new shape, note that the returned shape initially doesn\textquotesingle{}t has points set, so its requiered to set vertices.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ pentagon\_shape\ =\ \mbox{\hyperlink{group__EPhysics__Shape_gae9e86be43d7e1c4407f6de877950217b}{ephysics\_shape\_new}}();}

\end{DoxyCodeInclude}
 Now we\textquotesingle{}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}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}}(pentagon\_shape,\ -\/1,\ -\/9/33.,\ -\/1);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}}(pentagon\_shape,\ -\/1,\ -\/9/33.,\ 1);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}}(pentagon\_shape,\ 0,\ -\/1,\ -\/1);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}}(pentagon\_shape,\ 0,\ -\/1,\ 1);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}}(pentagon\_shape,\ 1,\ -\/9/33.,\ -\/1);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}}(pentagon\_shape,\ 1,\ -\/9/33.,\ 1);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}}(pentagon\_shape,\ -\/21/35.,\ 1,\ -\/1);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}}(pentagon\_shape,\ -\/21/35.,\ 1,\ 1);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}}(pentagon\_shape,\ 21/35.,\ 1,\ -\/1);}
\DoxyCodeLine{\ \ \ \mbox{\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}{0}
\DoxyCodeLine{\ \ \ pentagon\_body\ =\ \mbox{\hyperlink{group__EPhysics__Body_gaee1301dfd2548f4774d5e4cb81b14385}{ephysics\_body\_shape\_add}}(test\_data-\/>world,\ pentagon\_shape);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Body_ga39cb9e95bbe1d097926a09365c501db3}{ephysics\_body\_evas\_object\_set}}(pentagon\_body,\ pentagon,\ \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}});}
\DoxyCodeLine{\ \ \ \mbox{\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\textquotesingle{}s required to delete it. It won\textquotesingle{}t be deleted automatically by ephysics at any point, even on shutdown.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \mbox{\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}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}}(hexagon\_shape,\ 0,\ 30,\ -\/10);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}}(hexagon\_shape,\ 0,\ 30,\ 10);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}}(hexagon\_shape,\ 18,\ 0,\ -\/10);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}}(hexagon\_shape,\ 18,\ 0,\ 10);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}}(hexagon\_shape,\ 52,\ 0,\ -\/10);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}}(hexagon\_shape,\ 52,\ 0,\ 10);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}}(hexagon\_shape,\ 70,\ 30,\ -\/10);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}}(hexagon\_shape,\ 70,\ 30,\ 10);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}}(hexagon\_shape,\ 52,\ 60,\ -\/10);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}}(hexagon\_shape,\ 52,\ 60,\ 10);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\_shape\_point\_add}}(hexagon\_shape,\ 18,\ 60,\ -\/10);}
\DoxyCodeLine{\ \ \ \mbox{\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 \mbox{\hyperlink{test_shapes_c}{test\+\_\+shapes.\+c}}. 