The purpose of this example is to demonstrate the E\+Physics\+\_\+\+Camera 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}}
\end{DoxyImageNoCaption}


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

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 \hyperlink{tutorial_ephysics_bouncing_ball}{E\+Physics -\/ Bouncing Ball}\hypertarget{tutorial_ephysics_camera_add-camstruct}{}\section{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}
\textcolor{keyword}{struct }\_Camera\_Data \{
     Test\_Data base;
     Ecore\_Animator *animator;
     \textcolor{keywordtype}{int} old\_x;
\};

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


\begin{DoxyCodeInclude}
   camera\_data->animator = \hyperlink{group__Ecore__Animator__Group_gaa1e33b8be9117a26918823c535e429ea}{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\+: \hyperlink{group__EPhysics__Camera}{E\+Physics Camera} And also get the worlds rendered area width to define a limit to the camera.




\begin{DoxyCodeInclude}
\_camera\_move\_cb(\textcolor{keywordtype}{void} *data)
\{
   Camera\_Data *camera\_data = data;
   \hyperlink{group__EPhysics__Camera_ga945948dcbf4d98beb457c77b6537116f}{EPhysics\_Camera} *camera;
   \textcolor{keywordtype}{int} x, y, w;

   \hyperlink{group__EPhysics__World_ga6bc905b2f56aa2a6c567d9a1575f9075}{ephysics\_world\_render\_geometry\_get}(camera\_data->base.world,
                                      NULL, NULL, NULL, &w, NULL, NULL);

\end{DoxyCodeInclude}


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


\begin{DoxyCodeInclude}
   camera = \hyperlink{group__EPhysics__World_ga97fe0c2a98a7998f29f7390cea868ff0}{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}
   \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}
   \textcolor{keywordflow}{if} (x + w > WIDTH * 2)
     \{
        camera\_data->animator = NULL;
        \textcolor{keywordflow}{return} \hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE};
     \}

   x += 2;
   \hyperlink{group__EPhysics__Camera_gaed0ba3e4daecc66fca5dc399031da530}{ephysics\_camera\_position\_set}(camera, x, y);
\}

\end{DoxyCodeInclude}
\hypertarget{tutorial_ephysics_camera_track_add-uptfloor}{}\section{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 \hyperlink{group__EPhysics__World_ga2b621ffb39920e4619fe2ec2e5508073}{ephysics\+\_\+world\+\_\+event\+\_\+callback\+\_\+add()} will register a callback to a type of physics world event.

\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}
   \hyperlink{group__EPhysics__World_ga2b621ffb39920e4619fe2ec2e5508073}{ephysics\_world\_event\_callback\_add}(world,
                                     \hyperlink{group__EPhysics__World_gga0b0aff31f415be24679d4ab703674619aa5f6adbd98bc6599221d12ecfeb1cbc6}{EPHYSICS\_CALLBACK\_WORLD\_CAMERA\_MOVED}
      ,
                                     \_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}
\_camera\_moved\_cb(\textcolor{keywordtype}{void} *data, \hyperlink{group__EPhysics__World_ga83c0d22744748525aa2dac11726c58e6}{EPhysics\_World} *world \_\_UNUSED\_\_, \textcolor{keywordtype}{void} *event\_info)
\{
   \hyperlink{group__EPhysics__Camera_ga945948dcbf4d98beb457c77b6537116f}{EPhysics\_Camera} *camera = event\_info;
   Camera\_Data *camera\_data = data;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *floor\_obj;
   \textcolor{keywordtype}{int} x;

   \hyperlink{group__Eina__File__Group_gae8924623ca601364965e3d88fb7f40fa}{DBG}(\textcolor{stringliteral}{"Camera moved"});

   \hyperlink{group__EPhysics__Camera_ga5e549e85d0d98a878dc636b6463645d6}{ephysics\_camera\_position\_get}(camera, &x, NULL);

   floor\_obj = \hyperlink{group__Evas__Object__Group__Extras_gafbad43015793eda4ae50202c0ce0e652}{evas\_object\_data\_get}(camera\_data->base.layout, \textcolor{stringliteral}{"floor"});
   \_update\_floor(floor\_obj, camera\_data->old\_x - x);

   floor\_obj = \hyperlink{group__Evas__Object__Group__Extras_gafbad43015793eda4ae50202c0ce0e652}{evas\_object\_data\_get}(camera\_data->base.layout, \textcolor{stringliteral}{"floor2"});
   \_update\_floor(floor\_obj, camera\_data->old\_x - x);

   camera\_data->old\_x = x;
\}

\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}
\_update\_floor(\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *floor\_obj, \hyperlink{group__Evas_ga2453e92182bad3b0e0d84e5aff433b07}{Evas\_Coord} delta)
\{
   \textcolor{keywordtype}{int} fx, x, y;

   \hyperlink{group__Evas__Object__Group__Basic_ga6f52fab1a96dc58c85ee481d84bac871}{evas\_object\_geometry\_get}(floor\_obj, &x, &y, NULL, NULL);
   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}
   \textcolor{keywordflow}{if} (fx < -FLOOR\_WIDTH)
     fx += 2 * FLOOR\_WIDTH;
   \hyperlink{group__Evas__Font__Group_ga02da8091bbac768b8e86c7b74b2a94f9}{evas\_object\_move}(floor\_obj, fx, y);
\}

\end{DoxyCodeInclude}


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