The purpose of this example is to demonstrate the E\+Physics Rotate usage -\/ The code applies different ways to rotate an E\+Physics\+\_\+\+Body, such as torque, torque impulse and rotation set.

For this example we'll have an E\+Physics\+\_\+\+World with gravity setted to zero, and four basic E\+Physics\+\_\+\+Bodys.

The basic concepts like -\/ defining an E\+Physics\+\_\+\+World, render geometry, physics limiting boundaries, add an E\+Physics\+\_\+\+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_rotating_forever_add-rotate}{}\section{Rotating}\label{tutorial_ephysics_rotating_forever_add-rotate}


For the first body we'll apply a torque impulse to make it rotate around Z axis (rotate on x-\/y plane). Will make the body rolls on clockwise rotation, if the value is negative, the impulse will be on counter clockwise.


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

\end{DoxyCodeInclude}


For the second body we'll use an offset to apply the force, the three last parameters are responsible to set a relative position to apply the force.\+In other words, the force applied with an offset will make the body rotates and move around the other cubes.


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

\end{DoxyCodeInclude}


For the third body we'll use a timer to rotate the body and a callback to delete it.


\begin{DoxyCodeInclude}
   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);

\end{DoxyCodeInclude}


 
\begin{DoxyCodeInclude}
\_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);
\}

\end{DoxyCodeInclude}


In the function we'll get the body rotation on z axis in degrees and handle it increasing 5 degrees on its position on z axis on each tick of the timer.

 
\begin{DoxyCodeInclude}
\_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};
\}

\end{DoxyCodeInclude}


For the forth body we'll use 2 timers, but before that, we'll apply an initial torque, changing the body angular acceleration and a callback to delete the timers we'll add.


\begin{DoxyCodeInclude}
   \hyperlink{group__EPhysics__Body_ga336a585598ed882a9575ed72a9f748e2}{ephysics\_body\_torque\_apply}(body, 0, 0, 2);
   \hyperlink{group__EPhysics__Body_gada176f4748a4c2fc4ba2042021ea7067}{ephysics\_body\_event\_callback\_add}(body,
                                    \hyperlink{group__EPhysics__Body_gga904d0d1462e71c1f32cb27f540b5277cab8f46f167ee3872ea35fe645bf14a5d2}{EPHYSICS\_CALLBACK\_BODY\_DEL},

\end{DoxyCodeInclude}


Just the callback function to delete the timers.

 
\begin{DoxyCodeInclude}
\_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);
\}

\end{DoxyCodeInclude}


As we commented we'll use 2 timers, one to increase the torque and another to stop the torque, cleaning the forces related to the body.


\begin{DoxyCodeInclude}
   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);

\end{DoxyCodeInclude}


In the increase function we'll apply a torque over the body, changing its angular acceleration, it will leads to a change on angular velocity over time. We're using a timer to increase the angular acceleration on each tick of the timer.

 
\begin{DoxyCodeInclude}
\_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};
\}

\end{DoxyCodeInclude}


In the stop function we'll clear all the forces applied to the body, setting its linear and angular acceleration to zero. We're using this timer to \char`\"{}control\char`\"{} the body velocity, since we are increasing it by another timer. Note that we set the acceleration to zero not the velocity.


\begin{DoxyCodeInclude}
\_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};
\}

\end{DoxyCodeInclude}


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