\hypertarget{test_rotating_forever_8c-example}{\section{test\+\_\+rotating\+\_\+forever.\+c}
}

\begin{DoxyCodeInclude}
\textcolor{preprocessor}{#ifdef HAVE\_CONFIG\_H}
\textcolor{preprocessor}{# include <config.h>}
\textcolor{preprocessor}{#endif}

\textcolor{preprocessor}{#include "ephysics\_test.h"}

\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
\_rotate\_cb(\textcolor{keywordtype}{void} *data)
\{
   \hyperlink{struct__EPhysics__Quaternion}{EPhysics\_Quaternion} *quat\_prev, quat\_delta, quat;
   \hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body} *body = data;

   quat\_prev = \hyperlink{group__EPhysics__Body_gaf1e13b27301a7f4c9cb3bcba3fa9f26a}{ephysics\_body\_rotation\_get}(body, NULL);
   \hyperlink{group__EPhysics__Quaternion_gae05800bc35b8f0d161673f167e632524}{ephysics\_quaternion\_set}(&quat\_delta, 0, 0, -0.15, 0.98);
   \hyperlink{group__EPhysics__Quaternion_gae72bd8e462318feae3636dd5f405065f}{ephysics\_quaternion\_normalize}(&quat\_delta);
   \hyperlink{group__EPhysics__Body_ga11a611cba12f9066a272e5cb6d1b371e}{ephysics\_body\_rotation\_set}(
      body, \hyperlink{group__EPhysics__Quaternion_gace88a4e4700fa1a1456c852655969a19}{ephysics\_quaternion\_multiply}(&quat\_delta, quat\_prev, &quat));
   free(quat\_prev);

   \textcolor{keywordflow}{return} \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE};
\}

\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
\_increase\_torque\_cb(\textcolor{keywordtype}{void} *data)
\{
   \hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body} *body = data;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *obj;

   \hyperlink{group__EPhysics__Body_ga336a585598ed882a9575ed72a9f748e2}{ephysics\_body\_torque\_apply}(body, 0, 0, 2);
   obj = \hyperlink{group__EPhysics__Body_ga47ea07534cc809cd5d132495ebf2793a}{ephysics\_body\_evas\_object\_get}(body);
   \hyperlink{group__Evas__Object__Group__Extras_ga70134a7068c9bff4107a761abe0a2ad4}{evas\_object\_data\_set}(obj, \textcolor{stringliteral}{"increase\_timer"}, NULL);

   \textcolor{keywordflow}{return} \hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE};
\}

\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
\_stop\_torque\_cb(\textcolor{keywordtype}{void} *data)
\{
   \hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body} *body = data;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *obj;

   \hyperlink{group__EPhysics__Body_ga8a84144392d9f3c7dbecdec6a1199a49}{ephysics\_body\_forces\_clear}(body);
   obj = \hyperlink{group__EPhysics__Body_ga47ea07534cc809cd5d132495ebf2793a}{ephysics\_body\_evas\_object\_get}(body);
   \hyperlink{group__Evas__Object__Group__Extras_ga70134a7068c9bff4107a761abe0a2ad4}{evas\_object\_data\_set}(obj, \textcolor{stringliteral}{"stop\_timer"}, NULL);

   \textcolor{keywordflow}{return} \hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE};
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_del\_cb(\textcolor{keywordtype}{void} *data, \hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body} *body \_\_UNUSED\_\_, \textcolor{keywordtype}{void} *event\_info \_\_UNUSED\_\_)
\{
   \hyperlink{group__Ecore__Timer__Group_gaba2b599c7aabe3ab664dc3d47f62a33a}{ecore\_timer\_del}(data);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_del\_torque\_cb(\textcolor{keywordtype}{void} *data \_\_UNUSED\_\_, \hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas} *e \_\_UNUSED\_\_, \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *obj, \textcolor{keywordtype}{void} *event\_info
       \_\_UNUSED\_\_)
\{
   \hyperlink{group__Ecore__Timer__Group_gaf96ffb609956658ec038e54bd39f46f0}{Ecore\_Timer} *timer;

   timer = \hyperlink{group__Evas__Object__Group__Extras_gafbad43015793eda4ae50202c0ce0e652}{evas\_object\_data\_get}(obj, \textcolor{stringliteral}{"increase\_timer"});
   \textcolor{keywordflow}{if} (timer)
     \hyperlink{group__Ecore__Timer__Group_gaba2b599c7aabe3ab664dc3d47f62a33a}{ecore\_timer\_del}(timer);

   timer = \hyperlink{group__Evas__Object__Group__Extras_gafbad43015793eda4ae50202c0ce0e652}{evas\_object\_data\_get}(obj, \textcolor{stringliteral}{"stop\_timer"});
   \textcolor{keywordflow}{if} (timer)
     \hyperlink{group__Ecore__Timer__Group_gaba2b599c7aabe3ab664dc3d47f62a33a}{ecore\_timer\_del}(timer);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_update\_object\_cb(\textcolor{keywordtype}{void} *data \_\_UNUSED\_\_, \hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body} *body, \textcolor{keywordtype}{void} *event\_info \_\_UNUSED\_\_)
\{
   \textcolor{keywordtype}{double} rx, ry, rz, rw, vrot, torque;
   \hyperlink{struct__EPhysics__Quaternion}{EPhysics\_Quaternion} quat;

   \hyperlink{group__EPhysics__Body_ga4aa2211390aefa191a13639a672f21e8}{ephysics\_body\_angular\_velocity\_get}(body, NULL, NULL, &vrot);
   \hyperlink{group__EPhysics__Body_ga7d494e105a7f3a16e658b36ff00e8f17}{ephysics\_body\_torques\_get}(body, NULL, NULL, &torque);

   \hyperlink{group__EPhysics__Body_gaf1e13b27301a7f4c9cb3bcba3fa9f26a}{ephysics\_body\_rotation\_get}(body, &quat);
   \hyperlink{group__EPhysics__Quaternion_gaab4373700e3bdad8e761e63c398ebda6}{ephysics\_quaternion\_get}(&quat, &rx, &ry, &rz, &rw);

   \hyperlink{group__EPhysics__Body_ga7209e650176e0612efb2a2cc2af0ec27}{ephysics\_body\_evas\_object\_update}(body);

   \hyperlink{group__Eina__File__Group_gae8924623ca601364965e3d88fb7f40fa}{DBG}(\textcolor{stringliteral}{"body: %p, rot: (%lf, %lf, %lf, %lf), vrot: %lf, torque: %lf"}, body,
       rx, ry, rz, rw, vrot, torque);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_world\_populate(Test\_Data *test\_data)
\{
   \hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body} *body;
   \hyperlink{group__Ecore__Timer__Group_gaf96ffb609956658ec038e54bd39f46f0}{Ecore\_Timer} *timer;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *cube;

   cube = elm\_image\_add(test\_data->win);
   elm\_image\_file\_set(
      cube, PACKAGE\_DATA\_DIR \textcolor{stringliteral}{"/"} EPHYSICS\_TEST\_THEME \textcolor{stringliteral}{".edj"}, \textcolor{stringliteral}{"blue-cube"});
   evas\_object\_move(cube, WIDTH / 3, HEIGHT / 2 - 30);
   evas\_object\_resize(cube, 70, 70);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(cube);
   test\_data->evas\_objs = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(test\_data->evas\_objs, cube);

   body = \hyperlink{group__EPhysics__Body_gaf8f30587da7453114397d64dd9704d7f}{ephysics\_body\_box\_add}(test\_data->world);
   \hyperlink{group__EPhysics__Body_ga39cb9e95bbe1d097926a09365c501db3}{ephysics\_body\_evas\_object\_set}(body, cube, 
      \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE});
   test\_data->bodies = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(test\_data->bodies, body);
   \hyperlink{group__EPhysics__Body_gada176f4748a4c2fc4ba2042021ea7067}{ephysics\_body\_event\_callback\_add}(body,
                                    \hyperlink{group__EPhysics__Body_gga904d0d1462e71c1f32cb27f540b5277cacb2363cd59bc8642e74ad916c6658e0a}{EPHYSICS\_CALLBACK\_BODY\_UPDATE},
                                    \_update\_object\_cb, NULL);

   \hyperlink{group__EPhysics__Body_ga6c6d3c8bfc6bb5600947b66b519d2d98}{ephysics\_body\_torque\_impulse\_apply}(body, 0, 0, 1);

   cube = elm\_image\_add(test\_data->win);
   elm\_image\_file\_set(
      cube, PACKAGE\_DATA\_DIR \textcolor{stringliteral}{"/"} EPHYSICS\_TEST\_THEME \textcolor{stringliteral}{".edj"}, \textcolor{stringliteral}{"purple-cube"});
   evas\_object\_move(cube, WIDTH / 3, FLOOR\_Y - 70);
   evas\_object\_resize(cube, 70, 70);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(cube);
   test\_data->evas\_objs = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(test\_data->evas\_objs, cube);

   body = \hyperlink{group__EPhysics__Body_gaf8f30587da7453114397d64dd9704d7f}{ephysics\_body\_box\_add}(test\_data->world);
   \hyperlink{group__EPhysics__Body_ga39cb9e95bbe1d097926a09365c501db3}{ephysics\_body\_evas\_object\_set}(body, cube, 
      \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE});
   test\_data->bodies = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(test\_data->bodies, body);
   \hyperlink{group__EPhysics__Body_gada176f4748a4c2fc4ba2042021ea7067}{ephysics\_body\_event\_callback\_add}(body,
                                    \hyperlink{group__EPhysics__Body_gga904d0d1462e71c1f32cb27f540b5277cacb2363cd59bc8642e74ad916c6658e0a}{EPHYSICS\_CALLBACK\_BODY\_UPDATE},
                                    \_update\_object\_cb, NULL);

   \hyperlink{group__EPhysics__Body_gadc5405c4d07742e9aff7a0a564aa63e2}{ephysics\_body\_impulse\_apply}(body, 30, 0, 0, 0, -10, 0);

   cube = elm\_image\_add(test\_data->win);
   elm\_image\_file\_set(
      cube, PACKAGE\_DATA\_DIR \textcolor{stringliteral}{"/"} EPHYSICS\_TEST\_THEME \textcolor{stringliteral}{".edj"}, \textcolor{stringliteral}{"purple-cube"});
   evas\_object\_move(cube, WIDTH / 3, 60);
   evas\_object\_resize(cube, 70, 70);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(cube);
   test\_data->evas\_objs = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(test\_data->evas\_objs, cube);

   body = \hyperlink{group__EPhysics__Body_gaf8f30587da7453114397d64dd9704d7f}{ephysics\_body\_box\_add}(test\_data->world);
   \hyperlink{group__EPhysics__Body_ga39cb9e95bbe1d097926a09365c501db3}{ephysics\_body\_evas\_object\_set}(body, cube, 
      \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE});
   test\_data->bodies = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(test\_data->bodies, body);
   \hyperlink{group__EPhysics__Body_gada176f4748a4c2fc4ba2042021ea7067}{ephysics\_body\_event\_callback\_add}(body,
                                    \hyperlink{group__EPhysics__Body_gga904d0d1462e71c1f32cb27f540b5277cacb2363cd59bc8642e74ad916c6658e0a}{EPHYSICS\_CALLBACK\_BODY\_UPDATE},
                                    \_update\_object\_cb, NULL);

   timer = ecore\_timer\_add(1, \_rotate\_cb, body);

   \hyperlink{group__EPhysics__Body_gada176f4748a4c2fc4ba2042021ea7067}{ephysics\_body\_event\_callback\_add}(body,
                                    \hyperlink{group__EPhysics__Body_gga904d0d1462e71c1f32cb27f540b5277cab8f46f167ee3872ea35fe645bf14a5d2}{EPHYSICS\_CALLBACK\_BODY\_DEL},
                                    \_del\_cb, timer);

   cube = elm\_image\_add(test\_data->win);
   elm\_image\_file\_set(
      cube, PACKAGE\_DATA\_DIR \textcolor{stringliteral}{"/"} EPHYSICS\_TEST\_THEME \textcolor{stringliteral}{".edj"}, \textcolor{stringliteral}{"blue-cube"});
   evas\_object\_move(cube, WIDTH * 2 / 3, 60);
   evas\_object\_resize(cube, 70, 70);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(cube);
   test\_data->evas\_objs = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(test\_data->evas\_objs, cube);

   body = \hyperlink{group__EPhysics__Body_gaf8f30587da7453114397d64dd9704d7f}{ephysics\_body\_box\_add}(test\_data->world);
   \hyperlink{group__EPhysics__Body_ga39cb9e95bbe1d097926a09365c501db3}{ephysics\_body\_evas\_object\_set}(body, cube, 
      \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE});
   test\_data->bodies = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(test\_data->bodies, body);
   \hyperlink{group__EPhysics__Body_gada176f4748a4c2fc4ba2042021ea7067}{ephysics\_body\_event\_callback\_add}(body,
                                    \hyperlink{group__EPhysics__Body_gga904d0d1462e71c1f32cb27f540b5277cacb2363cd59bc8642e74ad916c6658e0a}{EPHYSICS\_CALLBACK\_BODY\_UPDATE},
                                    \_update\_object\_cb, NULL);

   \hyperlink{group__EPhysics__Body_ga336a585598ed882a9575ed72a9f748e2}{ephysics\_body\_torque\_apply}(body, 0, 0, 2);
   \hyperlink{group__Evas__Object__Group__Events_ga23be30ac5cdfb780f1ff82e9108ec26b}{evas\_object\_event\_callback\_add}(cube, 
      \hyperlink{Evas__Common_8h_a99e208e463a20499aabe6faac8a8cb8aa4471afbcbb4a754b7b0bbde00fb9a277}{EVAS\_CALLBACK\_DEL},
                                  \_del\_torque\_cb, NULL);

   timer = ecore\_timer\_add(3, \_increase\_torque\_cb, body);
   \hyperlink{group__Evas__Object__Group__Extras_ga70134a7068c9bff4107a761abe0a2ad4}{evas\_object\_data\_set}(cube, \textcolor{stringliteral}{"increase\_timer"}, timer);
   timer = ecore\_timer\_add(5, \_stop\_torque\_cb, body);
   \hyperlink{group__Evas__Object__Group__Extras_ga70134a7068c9bff4107a761abe0a2ad4}{evas\_object\_data\_set}(cube, \textcolor{stringliteral}{"stop\_timer"}, timer);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_restart(\textcolor{keywordtype}{void} *data, \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *obj \_\_UNUSED\_\_, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *emission \_\_UNUSED\_\_, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *
      source \_\_UNUSED\_\_)
\{
   Test\_Data *test\_data = data;

   \hyperlink{group__Eina__File__Group_gae8924623ca601364965e3d88fb7f40fa}{DBG}(\textcolor{stringliteral}{"Restart pressed"});
   test\_clean(test\_data);
   \_world\_populate(test\_data);
\}

\textcolor{keywordtype}{void}
test\_rotating\_forever(\textcolor{keywordtype}{void} *data \_\_UNUSED\_\_, \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *obj \_\_UNUSED\_\_, \textcolor{keywordtype}{void} *event\_info 
      \_\_UNUSED\_\_)
\{
   \hyperlink{group__EPhysics__World_ga83c0d22744748525aa2dac11726c58e6}{EPhysics\_World} *world;
   Test\_Data *test\_data;

   \textcolor{keywordflow}{if} (!\hyperlink{group__EPhysics_gaca8fc170d73b3f688349cc4dbaf219fd}{ephysics\_init}())
     \textcolor{keywordflow}{return};

   test\_data = test\_data\_new();
   test\_win\_add(test\_data, \textcolor{stringliteral}{"Rotating Forever"}, \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE});
   elm\_object\_signal\_emit(test\_data->layout, \textcolor{stringliteral}{"borders,show"}, \textcolor{stringliteral}{"ephysics\_test"});
   elm\_layout\_signal\_callback\_add(test\_data->layout, \textcolor{stringliteral}{"restart"}, \textcolor{stringliteral}{"test-theme"},
                                  \_restart, test\_data);

   world = \hyperlink{group__EPhysics__World_ga108e2d7df8c81321b8d5bde8497f0d45}{ephysics\_world\_new}();
   \hyperlink{group__EPhysics__World_gaabf8abaf9c41b0c1e5daa4acf3df0356}{ephysics\_world\_render\_geometry\_set}(world, 50, 40, -50,
                                      WIDTH - 100, FLOOR\_Y - 40, DEPTH);
   test\_data->world = world;
   \hyperlink{group__EPhysics__World_ga849f9d794ce5da7bf07f0bfc71aa5b6c}{ephysics\_world\_gravity\_set}(world, 0, 0, 0);

   \_world\_populate(test\_data);
\}
\end{DoxyCodeInclude}
 