The purpose of this example is to demonstrate the EPhysics\+\_\+\+Camera usage.

The EPhysics\+\_\+\+Camera facilitates the usage of scenarios bigger than the viewport, that\textquotesingle{}s because the EPhysics handles the position of objects which has control.

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


For this example we\textquotesingle{}ll have an EPhysics\+\_\+\+World, two distant EPhysics\+\_\+\+Bodys, one with an impulse to collide each other and an EPhysics\+\_\+\+Camera that follows the moving body using an animator.

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_camera_add-camstruct}{}\doxysection{Camera Data Struct}\label{tutorial_ephysics_camera_add-camstruct}


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\ }\_Camera\_Data\ \{}
\DoxyCodeLine{\ \ \ \ \ Test\_Data\ base;}
\DoxyCodeLine{\ \ \ \ \ \mbox{\hyperlink{structEcore__Animator}{Ecore\_Animator}}\ *animator;}
\DoxyCodeLine{\ \ \ \ \ \textcolor{keywordtype}{int}\ old\_x;}
\DoxyCodeLine{\};}

\end{DoxyCodeInclude}
 \hypertarget{tutorial_ephysics_camera_autotoc_md5}{}\doxysection{Adding a Camera}\label{tutorial_ephysics_camera_autotoc_md5}
To move the camera in this example, we\textquotesingle{}ll use an animator.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ camera\_data-\/>animator\ =\ \mbox{\hyperlink{group__Ecore__Animator__Group_ga0eca52138288075de4487d31dd3942ff}{ecore\_animator\_add}}(\_camera\_move\_cb,\ camera\_data);}

\end{DoxyCodeInclude}
 In the animators function, we\textquotesingle{}ll have to create a specific type of variable\+: \mbox{\hyperlink{group__EPhysics__Camera}{EPhysics Camera}} And also get the worlds rendered area width to define a limit to the camera.




\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\_camera\_move\_cb(\textcolor{keywordtype}{void}\ *data)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ Camera\_Data\ *camera\_data\ =\ data;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Camera_ga945948dcbf4d98beb457c77b6537116f}{EPhysics\_Camera}}\ *camera;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ x,\ y,\ w;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__World_ga6bc905b2f56aa2a6c567d9a1575f9075}{ephysics\_world\_render\_geometry\_get}}(camera\_data-\/>base.world,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ NULL,\ NULL,\ NULL,\ \&w,\ NULL,\ NULL);}

\end{DoxyCodeInclude}
 Every world has a camera, so here we get this camera used by our EPhysics\+\_\+\+World.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ camera\ =\ \mbox{\hyperlink{group__EPhysics__World_gac676a37c869af5ec41fab3268e53ed21}{ephysics\_world\_camera\_get}}(camera\_data-\/>base.world);}

\end{DoxyCodeInclude}
 Here we get the cameras position to after set the position based on previous.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Camera_ga5e549e85d0d98a878dc636b6463645d6}{ephysics\_camera\_position\_get}}(camera,\ \&x,\ \&y);}

\end{DoxyCodeInclude}
 Here we check if the camera reached the end of scenario (define the limit to the camera) then we stop the animator, else we move the camera + 2 pixel positions to the right.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (x\ +\ w\ >\ WIDTH\ *\ 2)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ camera\_data-\/>animator\ =\ NULL;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}};}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ x\ +=\ 2;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Camera_gaed0ba3e4daecc66fca5dc399031da530}{ephysics\_camera\_position\_set}}(camera,\ x,\ y);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 \hypertarget{tutorial_ephysics_camera_autotoc_md6}{}\doxysection{Updating the floor}\label{tutorial_ephysics_camera_autotoc_md6}
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}{EPHYSICS\+\_\+\+CALLBACK\+\_\+\+WORLD\+\_\+\+CAMERA\+\_\+\+MOVED}} \+: 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,\ camera\_data);}

\end{DoxyCodeInclude}
 In the function, we just 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. 


\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{\ \ \ Camera\_Data\ *camera\_data\ =\ data;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}}\ *floor\_obj;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ x;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ DBG(\textcolor{stringliteral}{"{}Camera\ moved"{}});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__EPhysics__Camera_ga5e549e85d0d98a878dc636b6463645d6}{ephysics\_camera\_position\_get}}(camera,\ \&x,\ NULL);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ floor\_obj\ =\ evas\_object\_data\_get(camera\_data-\/>base.layout,\ \textcolor{stringliteral}{"{}floor"{}});}
\DoxyCodeLine{\ \ \ \_update\_floor(floor\_obj,\ camera\_data-\/>old\_x\ -\/\ x);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ floor\_obj\ =\ evas\_object\_data\_get(camera\_data-\/>base.layout,\ \textcolor{stringliteral}{"{}floor2"{}});}
\DoxyCodeLine{\ \ \ \_update\_floor(floor\_obj,\ camera\_data-\/>old\_x\ -\/\ x);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ camera\_data-\/>old\_x\ =\ x;}
\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}}\ *floor\_obj,\ \mbox{\hyperlink{Evas__Common_8h_a2453e92182bad3b0e0d84e5aff433b07}{Evas\_Coord}}\ delta)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ fx,\ x,\ y;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga6e8e78e110392480dd612df86a16b630}{evas\_object\_geometry\_get}}(floor\_obj,\ \&x,\ \&y,\ NULL,\ NULL);}
\DoxyCodeLine{\ \ \ fx\ =\ x\ +\ delta;}

\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.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (fx\ <\ -\/FLOOR\_WIDTH)}
\DoxyCodeLine{\ \ \ \ \ fx\ +=\ 2\ *\ FLOOR\_WIDTH;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga335c8ee6eaeaac9710656af4f8b0db91}{evas\_object\_move}}(floor\_obj,\ fx,\ y);}
\DoxyCodeLine{\}}

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