The purpose of this example is to demonstrate the EPhysics Callbacks usage -\/ The code adds two balls, one with impulse and the second with a collision detection callback, to delete the body.

For this example we\textquotesingle{}ll have an EPhysics\+\_\+\+World and two basic EPhysics\+\_\+\+Bodys, we\textquotesingle{}ll apply an impulse in one of then and the other will be stopped \char`\"{}waiting\char`\"{} for a collision.

The basic concepts like -\/ initializing 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_delete_body_autotoc_md15}{}\doxysection{Adding Callbacks}\label{tutorial_ephysics_delete_body_autotoc_md15}


Calling \mbox{\hyperlink{group__EPhysics__Body_gada176f4748a4c2fc4ba2042021ea7067}{ephysics\+\_\+body\+\_\+event\+\_\+callback\+\_\+add()}} registers a callback to a given EPhysics\+\_\+\+Body event type.

We\textquotesingle{}ll use two types\+:

\mbox{\hyperlink{group__EPhysics__Body_gga904d0d1462e71c1f32cb27f540b5277cab8f46f167ee3872ea35fe645bf14a5d2}{EPHYSICS\+\_\+\+CALLBACK\+\_\+\+BODY\+\_\+\+DEL}} \+: called when a body deletion has been issued and just before the deletion actually happens. In other words, to know that body has been marked for deletion. Typically to free some data associated with the body.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Body_gada176f4748a4c2fc4ba2042021ea7067}{ephysics\_body\_event\_callback\_add}}(sphere\_body1,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__EPhysics__Body_gga904d0d1462e71c1f32cb27f540b5277cab8f46f167ee3872ea35fe645bf14a5d2}{EPHYSICS\_CALLBACK\_BODY\_DEL}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_del\_cb,\ collision\_data);}

\end{DoxyCodeInclude}
 The callback function will receive the collision\+\_\+data and free some data associated with the body.




\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\_del\_cb(\textcolor{keywordtype}{void}\ *data,\ \mbox{\hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body}}\ *body,\ \textcolor{keywordtype}{void}\ *event\_info\ \_\_UNUSED\_\_)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ Collision\_Data\ *collision\_data\ =\ data;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}}\ *obj,\ *shadow;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ obj\ =\ \mbox{\hyperlink{group__EPhysics__Body_gade11f9cb1bdd26f393adbbe0b4a594be}{ephysics\_body\_evas\_object\_get}}(body);}
\DoxyCodeLine{\ \ \ shadow\ =\ evas\_object\_data\_get(obj,\ \textcolor{stringliteral}{"{}shadow"{}});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ collision\_data-\/>base.evas\_objs\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga6e81c26272c54177d087b29c965af4d8}{eina\_list\_remove}}(}
\DoxyCodeLine{\ \ \ \ \ \ collision\_data-\/>base.evas\_objs,\ shadow);}
\DoxyCodeLine{\ \ \ collision\_data-\/>base.evas\_objs\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga6e81c26272c54177d087b29c965af4d8}{eina\_list\_remove}}(}
\DoxyCodeLine{\ \ \ \ \ \ collision\_data-\/>base.evas\_objs,\ obj);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9217cf1d90690dbd1960db155d1c7476}{evas\_object\_del}}(shadow);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9217cf1d90690dbd1960db155d1c7476}{evas\_object\_del}}(obj);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ collision\_data-\/>sphere\ =\ NULL;}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 \mbox{\hyperlink{group__EPhysics__Body_gga904d0d1462e71c1f32cb27f540b5277caa002e2d26e86261221dc643f19071754}{EPHYSICS\+\_\+\+CALLBACK\+\_\+\+BODY\+\_\+\+COLLISION}} \+: called just after the collision has been actually processed by the physics engine. In other words, to be notified about a collision between two physical bodies.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Body_gada176f4748a4c2fc4ba2042021ea7067}{ephysics\_body\_event\_callback\_add}}(collision\_data-\/>sphere,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__EPhysics__Body_gga904d0d1462e71c1f32cb27f540b5277caa002e2d26e86261221dc643f19071754}{EPHYSICS\_CALLBACK\_BODY\_COLLISION}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_collision\_cb,\ collision\_data);}

\end{DoxyCodeInclude}
 The callback function will get the collision body and check if its body is equal to which we want to delete.




\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\_collision\_cb(\textcolor{keywordtype}{void}\ *data,\ \mbox{\hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body}}\ *body,\ \textcolor{keywordtype}{void}\ *event\_info)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Body_ga454052288e957641ff40f79ca3c72792}{EPhysics\_Body\_Collision}}\ *collision\ =\ event\_info;}
\DoxyCodeLine{\ \ \ Collision\_Data\ *collision\_data\ =\ data;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body}}\ *contact\_body;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ contact\_body\ =\ \mbox{\hyperlink{group__EPhysics__Body_gacb7ca0a444bf31b04b84f97d7198d392}{ephysics\_body\_collision\_contact\_body\_get}}(collision);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (contact\_body\ !=\ collision\_data-\/>sphere2)\ \textcolor{keywordflow}{return};}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ collision\_data-\/>base.bodies\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga6e81c26272c54177d087b29c965af4d8}{eina\_list\_remove}}(collision\_data-\/>base.bodies,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ body);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ INF(\textcolor{stringliteral}{"{}Collision\ Detected"{}});}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Body_ga9f47ada6fe8ee0abb234bc4aaab7dd1c}{ephysics\_body\_del}}(body);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 See \mbox{\hyperlink{group__EPhysics__Body_ga904d0d1462e71c1f32cb27f540b5277c}{\+\_\+\+EPhysics\+\_\+\+Callback\+\_\+\+Body\+\_\+\+Type}} for more event types.

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