The purpose of this example is to demonstrate the E\+Physics\+\_\+\+Camera Track usage.

The E\+Physics\+\_\+\+Camera facilitates the usage of scenarios bigger than the viewport, thats because the E\+Physics handles the position of objects which has control.

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


For this example we\textquotesingle{}ll have an E\+Physics\+\_\+\+World, one main E\+Physics\+\_\+\+Body that will be tracked by an E\+Physics\+\_\+\+Camera on three ways, horizontal, vertical and full tracking. Also nine E\+Physics\+\_\+\+Bodys with mass 0, that will be used as scenario in order to our main body change its position on x and y axes when passes through this scenario.

The basic concepts like -\/ initializing an E\+Physics\+\_\+\+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}{E\+Physics -\/ Bouncing Ball}}\hypertarget{tutorial_ephysics_camera_track_add-trkstruct}{}\doxysection{Track Data Struct}\label{tutorial_ephysics_camera_track_add-trkstruct}


While in this example we\textquotesingle{}ll be working with a struct to hold some objects in our code. For clarity sake we present you the struct declaration in the following block.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{struct }\_Track\_Data \{}
\DoxyCodeLine{     Test\_Data base;}
\DoxyCodeLine{     \mbox{\hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body}} *body;}
\DoxyCodeLine{     \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *sp;}
\DoxyCodeLine{     \textcolor{keywordtype}{int} old\_cx;}
\DoxyCodeLine{\};}

\end{DoxyCodeInclude}
\hypertarget{tutorial_ephysics_camera_track_add-camera}{}\doxysection{Adding a Camera}\label{tutorial_ephysics_camera_track_add-camera}
In this example we\textquotesingle{}ll use 3 kinds of tracking, to change this values we\textquotesingle{}ll have an Elementary spinner widget and handle it on this function.

Every world has a camera, so here we get this camera used by our E\+Physics\+\_\+\+World.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\_track\_apply(Track\_Data *track\_data)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}} hor = \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}};}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}} ver = \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}};}
\DoxyCodeLine{   \mbox{\hyperlink{group__EPhysics__Camera_ga945948dcbf4d98beb457c77b6537116f}{EPhysics\_Camera}} *camera;}
\DoxyCodeLine{   \mbox{\hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body}} *body;}
\DoxyCodeLine{   \textcolor{keywordtype}{int} mode;}
\DoxyCodeLine{}
\DoxyCodeLine{   body = track\_data-\/>body;}
\DoxyCodeLine{   camera = \mbox{\hyperlink{group__EPhysics__World_ga97fe0c2a98a7998f29f7390cea868ff0}{ephysics\_world\_camera\_get}}(track\_data-\/>base.world);}

\end{DoxyCodeInclude}


Here we\textquotesingle{}ll get the elm\+\_\+spinner value to the tracking base on this value


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{   mode = (int) \mbox{\hyperlink{group__Elm__Spinner_ga0f93a325d38ad9a249994a7dc4ea4f1b}{elm\_spinner\_value\_get}}(track\_data-\/>sp);}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{switch} (mode)}
\DoxyCodeLine{     \{}
\DoxyCodeLine{      \textcolor{keywordflow}{case} 1:}
\DoxyCodeLine{         hor = \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};}
\DoxyCodeLine{         \textcolor{keywordflow}{break};}
\DoxyCodeLine{      \textcolor{keywordflow}{case} 3:}
\DoxyCodeLine{         hor = \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};}
\DoxyCodeLine{      \textcolor{keywordflow}{case} 2:}
\DoxyCodeLine{         ver = \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};}
\DoxyCodeLine{     \}}

\end{DoxyCodeInclude}


Here we\textquotesingle{}ll set the camera to track the body, when a body is tracked, the camera will move automatically, following this body. It will keeps the body centralized on rendered area. If it will be centralized horizontally and / or vertically depends if parameters horizontal and vertical are set to E\+I\+N\+A\+\_\+\+T\+R\+UE, in this case we based these values on elm\+\_\+spinner.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{   \mbox{\hyperlink{group__EPhysics__Camera_gabb7602830e3a9daa67d7bbe1a71a776e}{ephysics\_camera\_body\_track}}(camera, body, hor, ver);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
\hypertarget{tutorial_ephysics_camera_track_add-uptfloor}{}\doxysection{Updating the floor}\label{tutorial_ephysics_camera_track_add-uptfloor}
Here we\textquotesingle{}ll use 2 floor images to give the impression of an infinite ground.

Calling \mbox{\hyperlink{group__EPhysics__World_ga2b621ffb39920e4619fe2ec2e5508073}{ephysics\+\_\+world\+\_\+event\+\_\+callback\+\_\+add()}} will register a callback to a type of physics world event.

\mbox{\hyperlink{group__EPhysics__World_gga0b0aff31f415be24679d4ab703674619aa5f6adbd98bc6599221d12ecfeb1cbc6}{E\+P\+H\+Y\+S\+I\+C\+S\+\_\+\+C\+A\+L\+L\+B\+A\+C\+K\+\_\+\+W\+O\+R\+L\+D\+\_\+\+C\+A\+M\+E\+R\+A\+\_\+\+M\+O\+V\+ED}} \+: called if the camera position changed on physics simulation tick.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{   \mbox{\hyperlink{group__EPhysics__World_ga2b621ffb39920e4619fe2ec2e5508073}{ephysics\_world\_event\_callback\_add}}(world,}
\DoxyCodeLine{                                     \mbox{\hyperlink{group__EPhysics__World_gga0b0aff31f415be24679d4ab703674619aa5f6adbd98bc6599221d12ecfeb1cbc6}{EPHYSICS\_CALLBACK\_WORLD\_CAMERA\_MOVED}},}
\DoxyCodeLine{                                     \_camera\_moved\_cb, track\_data);}

\end{DoxyCodeInclude}


In the function, we\textquotesingle{}ll get the cameras position to know how much the camera moved and move the same value to the floor passing it as delta\+\_\+x to the function, note that we use an old\+\_\+x variable to do this calculation.

We\textquotesingle{}ll get also if the body is being tracked on x and y axes. If the body isn\textquotesingle{}t being tracked on x axis the floors x position won\textquotesingle{}t change, delta\+\_\+x will be zero.




\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\_camera\_moved\_cb(\textcolor{keywordtype}{void} *data, \mbox{\hyperlink{group__EPhysics__World_ga83c0d22744748525aa2dac11726c58e6}{EPhysics\_World}} *world \_\_UNUSED\_\_, \textcolor{keywordtype}{void} *event\_info)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__EPhysics__Camera_ga945948dcbf4d98beb457c77b6537116f}{EPhysics\_Camera}} *camera = event\_info;}
\DoxyCodeLine{   Track\_Data *track\_data = data;}
\DoxyCodeLine{   \textcolor{keywordtype}{int} cx, cy, delta\_x = 0;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}} hor, ver;}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__File__Group_gae8924623ca601364965e3d88fb7f40fa}{DBG}}(\textcolor{stringliteral}{"Camera moved"});}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__EPhysics__Camera_ga3f8d5e51ae54ac3c2a5bdc0a6fb162c6}{ephysics\_camera\_tracked\_body\_get}}(camera, NULL, \&hor, \&ver);}
\DoxyCodeLine{   \mbox{\hyperlink{group__EPhysics__Camera_ga5e549e85d0d98a878dc636b6463645d6}{ephysics\_camera\_position\_get}}(camera, \&cx, \&cy);}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (hor)}
\DoxyCodeLine{     delta\_x = track\_data-\/>old\_cx -\/ cx;}
\DoxyCodeLine{}
\DoxyCodeLine{   \_update\_floor(track\_data-\/>base.layout, \textcolor{stringliteral}{"floor"}, delta\_x, cy, ver);}
\DoxyCodeLine{   \_update\_floor(track\_data-\/>base.layout, \textcolor{stringliteral}{"floor2"}, delta\_x, cy, ver);}
\DoxyCodeLine{}
\DoxyCodeLine{   track\_data-\/>old\_cx = cx;}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}


Here we get the floors position and plus the delta\+\_\+x value to move the floor in the same \char`\"{}velocity\char`\"{}.




\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\_update\_floor(\mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *layout, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name, \textcolor{keywordtype}{int} delta\_x, \textcolor{keywordtype}{int} cy, \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}} ver)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *floor\_obj;}
\DoxyCodeLine{   \textcolor{keywordtype}{int} x, y, fx, fy;}
\DoxyCodeLine{}
\DoxyCodeLine{   floor\_obj = \mbox{\hyperlink{group__Evas__Object__Group__Extras_gafbad43015793eda4ae50202c0ce0e652}{evas\_object\_data\_get}}(layout, name);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga6f52fab1a96dc58c85ee481d84bac871}{evas\_object\_geometry\_get}}(floor\_obj, \&x, \&y, NULL, NULL);}
\DoxyCodeLine{   fx = x + delta\_x;}

\end{DoxyCodeInclude}


We use 2 floor images because whenever one exits the screen by the left side, another is being shown, when it happens the one which exit the screen is sent to the right side, entering into an infinite loop, giving the impression of an infinite ground image. Its important to note that we need to use the fx to don\textquotesingle{}t gap the images.

Note that the fy is being defined considering its offsets, -\/20 is to the floor image be above the floor, thus having an border above the collision point, +40 is the render area height, to offset the cameras y, basically to draw in the correct position in the canvas.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (fx < -\/FLOOR\_WIDTH)}
\DoxyCodeLine{     fx += 2 * FLOOR\_WIDTH;}
\DoxyCodeLine{}
\DoxyCodeLine{   fy = (ver) ? FLOOR\_Y -\/ 20 -\/ cy + 40 : y;}
\DoxyCodeLine{   evas\_object\_move(floor\_obj, fx, fy);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}


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