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\textquotesingle{}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 \mbox{\hyperlink{tutorial_ephysics_bouncing_ball}{E\+Physics -\/ Bouncing Ball}}\hypertarget{tutorial_ephysics_rotating_forever_add-rotate}{}\doxysection{Rotating}\label{tutorial_ephysics_rotating_forever_add-rotate}


For the first body we\textquotesingle{}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}{0}
\DoxyCodeLine{   \mbox{\hyperlink{group__EPhysics__Body_ga6c6d3c8bfc6bb5600947b66b519d2d98}{ephysics\_body\_torque\_impulse\_apply}}(body, 0, 0, 1);}

\end{DoxyCodeInclude}


For the second body we\textquotesingle{}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}{0}
\DoxyCodeLine{   \mbox{\hyperlink{group__EPhysics__Body_gadc5405c4d07742e9aff7a0a564aa63e2}{ephysics\_body\_impulse\_apply}}(body, 30, 0, 0, 0, -\/10, 0);}

\end{DoxyCodeInclude}


For the third body we\textquotesingle{}ll use a timer to rotate the body and a callback to delete it.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{   timer = \mbox{\hyperlink{group__Ecore__Timer__Group_ga7b9cb9d24ecebfdbb957436e2e669402}{ecore\_timer\_add}}(1, \_rotate\_cb, body);}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__EPhysics__Body_gada176f4748a4c2fc4ba2042021ea7067}{ephysics\_body\_event\_callback\_add}}(body,}
\DoxyCodeLine{                                    \mbox{\hyperlink{group__EPhysics__Body_gga904d0d1462e71c1f32cb27f540b5277cab8f46f167ee3872ea35fe645bf14a5d2}{EPHYSICS\_CALLBACK\_BODY\_DEL}},}
\DoxyCodeLine{                                    \_del\_cb, timer);}

\end{DoxyCodeInclude}


 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\_del\_cb(\textcolor{keywordtype}{void} *data, \mbox{\hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body}} *body \_\_UNUSED\_\_, \textcolor{keywordtype}{void} *event\_info \_\_UNUSED\_\_)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Timer__Group_gaba2b599c7aabe3ab664dc3d47f62a33a}{ecore\_timer\_del}}(data);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}


In the function we\textquotesingle{}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}{0}
\DoxyCodeLine{\_rotate\_cb(\textcolor{keywordtype}{void} *data)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{struct__EPhysics__Quaternion}{EPhysics\_Quaternion}} *quat\_prev, quat\_delta, quat;}
\DoxyCodeLine{   \mbox{\hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body}} *body = data;}
\DoxyCodeLine{}
\DoxyCodeLine{   quat\_prev = \mbox{\hyperlink{group__EPhysics__Body_gaf1e13b27301a7f4c9cb3bcba3fa9f26a}{ephysics\_body\_rotation\_get}}(body, NULL);}
\DoxyCodeLine{   \mbox{\hyperlink{group__EPhysics__Quaternion_gae05800bc35b8f0d161673f167e632524}{ephysics\_quaternion\_set}}(\&quat\_delta, 0, 0, -\/0.15, 0.98);}
\DoxyCodeLine{   \mbox{\hyperlink{group__EPhysics__Quaternion_gae72bd8e462318feae3636dd5f405065f}{ephysics\_quaternion\_normalize}}(\&quat\_delta);}
\DoxyCodeLine{   \mbox{\hyperlink{group__EPhysics__Body_ga11a611cba12f9066a272e5cb6d1b371e}{ephysics\_body\_rotation\_set}}(}
\DoxyCodeLine{      body, \mbox{\hyperlink{group__EPhysics__Quaternion_gace88a4e4700fa1a1456c852655969a19}{ephysics\_quaternion\_multiply}}(\&quat\_delta, quat\_prev, \&quat));}
\DoxyCodeLine{   free(quat\_prev);}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}


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


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

\end{DoxyCodeInclude}


Just the callback function to delete the timers.

 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\_del\_torque\_cb(\textcolor{keywordtype}{void} *data \_\_UNUSED\_\_, \mbox{\hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas}} *e \_\_UNUSED\_\_, \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *obj, \textcolor{keywordtype}{void} *event\_info \_\_UNUSED\_\_)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Timer__Group_gaf96ffb609956658ec038e54bd39f46f0}{Ecore\_Timer}} *timer;}
\DoxyCodeLine{}
\DoxyCodeLine{   timer = \mbox{\hyperlink{group__Evas__Object__Group__Extras_gafbad43015793eda4ae50202c0ce0e652}{evas\_object\_data\_get}}(obj, \textcolor{stringliteral}{"increase\_timer"});}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (timer)}
\DoxyCodeLine{     \mbox{\hyperlink{group__Ecore__Timer__Group_gaba2b599c7aabe3ab664dc3d47f62a33a}{ecore\_timer\_del}}(timer);}
\DoxyCodeLine{}
\DoxyCodeLine{   timer = \mbox{\hyperlink{group__Evas__Object__Group__Extras_gafbad43015793eda4ae50202c0ce0e652}{evas\_object\_data\_get}}(obj, \textcolor{stringliteral}{"stop\_timer"});}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (timer)}
\DoxyCodeLine{     \mbox{\hyperlink{group__Ecore__Timer__Group_gaba2b599c7aabe3ab664dc3d47f62a33a}{ecore\_timer\_del}}(timer);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}


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


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

\end{DoxyCodeInclude}


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

 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\_increase\_torque\_cb(\textcolor{keywordtype}{void} *data)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body}} *body = data;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *obj;}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__EPhysics__Body_ga336a585598ed882a9575ed72a9f748e2}{ephysics\_body\_torque\_apply}}(body, 0, 0, 2);}
\DoxyCodeLine{   obj = \mbox{\hyperlink{group__EPhysics__Body_ga47ea07534cc809cd5d132495ebf2793a}{ephysics\_body\_evas\_object\_get}}(body);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Extras_ga70134a7068c9bff4107a761abe0a2ad4}{evas\_object\_data\_set}}(obj, \textcolor{stringliteral}{"increase\_timer"}, NULL);}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}};}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}


In the stop function we\textquotesingle{}ll clear all the forces applied to the body, setting its linear and angular acceleration to zero. We\textquotesingle{}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}{0}
\DoxyCodeLine{\_stop\_torque\_cb(\textcolor{keywordtype}{void} *data)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body}} *body = data;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *obj;}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__EPhysics__Body_ga8a84144392d9f3c7dbecdec6a1199a49}{ephysics\_body\_forces\_clear}}(body);}
\DoxyCodeLine{   obj = \mbox{\hyperlink{group__EPhysics__Body_ga47ea07534cc809cd5d132495ebf2793a}{ephysics\_body\_evas\_object\_get}}(body);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Extras_ga70134a7068c9bff4107a761abe0a2ad4}{evas\_object\_data\_set}}(obj, \textcolor{stringliteral}{"stop\_timer"}, NULL);}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}};}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}


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