The purpose of this example is to demonstrate the EPhysics Collision Filter usage -\/ The code adds four balls in 2 rows and 2 columns, two on each collision group, the collision only happens when the balls are in the same group (row),to make it easier, balls in the same group has the same color and size.

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


For this example we\textquotesingle{}ll have an EPhysics\+\_\+\+World and four basic EPhysics\+\_\+\+Bodys, we\textquotesingle{}ll apply an impulse on then and see what happens when they\textquotesingle{}re in other collision group.

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_collision_filter_autotoc_md13}{}\doxysection{Adding the balls}\label{tutorial_ephysics_collision_filter_autotoc_md13}


We\textquotesingle{}ll use two arrays (color and size) to distinguish the groups.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\_world\_populate(Test\_Data\ *test\_data)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *colors[]\ =\ \{\textcolor{stringliteral}{"{}blue-\/ball"{}},\ \textcolor{stringliteral}{"{}big-\/red-\/ball"{}}\};}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ sizes[]\ =\ \{54,\ 70\};}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body}}\ *fall\_body;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}}\ *sphere;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ i,\ column,\ row;}

\end{DoxyCodeInclude}
 The balls declaration was placed into a For loop, just to simplify the coding and divide them in two groups.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ 4;\ i++)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ column\ =\ i\ \%\ 2;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ row\ =\ i\ /\ 2;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ sphere\ =\ \mbox{\hyperlink{group__Elm__Image_ga1e320bab8a343c91522d0f09b938ab4f}{elm\_image\_add}}(test\_data-\/>win);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Elm__Image_gad1a96ede5f513042cef3c1dac4572f73}{elm\_image\_file\_set}}(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ sphere,\ PACKAGE\_DATA\_DIR\ \textcolor{stringliteral}{"{}/"{}}\ EPHYSICS\_TEST\_THEME\ \textcolor{stringliteral}{"{}.edj"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ colors[row]);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga335c8ee6eaeaac9710656af4f8b0db91}{evas\_object\_move}}(sphere,\ (1\ +\ column)\ *\ WIDTH\ /\ 4\ +}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (70\ -\/\ sizes[row])\ /\ 2,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 100\ +\ row\ *\ 60\ +\ row\ /\ 2\ *\ 20);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gacad94595f83580c18908cb3b69b08d1a}{evas\_object\_resize}}(sphere,\ sizes[row],\ sizes[row]);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(sphere);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ test\_data-\/>evas\_objs\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga625698a383dda8fc0db245a1c7608c49}{eina\_list\_append}}(test\_data-\/>evas\_objs,\ sphere);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fall\_body\ =\ \mbox{\hyperlink{group__EPhysics__Body_ga9fe94b35f5b58527b1199a23468b1f86}{ephysics\_body\_sphere\_add}}(test\_data-\/>world);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__EPhysics__Body_ga39cb9e95bbe1d097926a09365c501db3}{ephysics\_body\_evas\_object\_set}}(fall\_body,\ sphere,\ \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__EPhysics__Body_ga731c9a6443f7c4294fce23fc1287b778}{ephysics\_body\_restitution\_set}}(fall\_body,\ 0.95);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__EPhysics__Body_ga986d45060bf6ba1689a56889a2bcabce}{ephysics\_body\_friction\_set}}(fall\_body,\ 0.1);}

\end{DoxyCodeInclude}
 Note in this part we divide the balls in two groups by color (row).


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__EPhysics__Body_ga163b202be4c445bf79c28adb0db2bdbd}{ephysics\_body\_collision\_group\_add}}(fall\_body,\ colors[row]);}

\end{DoxyCodeInclude}
 The impulse will be applied in only 1 ball per group, in this case\+:

The 1st row 2nd column ball will be applied an impulse to the left (-\/300kg $\ast$ p/s).

The 2nd row 1st column ball will be applied an impulse to the right (300kg $\ast$ p/s).

And then saving the body into a list.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (column\ +\ row\ ==\ 1)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__EPhysics__Body_ga9109b39047a724640f6a18c683c9eb07}{ephysics\_body\_central\_impulse\_apply}}(fall\_body,\ 600\ *\ row\ -\/\ 300,\ 0,\ 0);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ test\_data-\/>bodies\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga625698a383dda8fc0db245a1c7608c49}{eina\_list\_append}}(test\_data-\/>bodies,\ fall\_body);}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 Here we finish the example. The full source code can be found at \mbox{\hyperlink{test_collision_filter_c}{test\+\_\+collision\+\_\+filter.\+c}}. 