\hypertarget{test_constraint_8c-example}{\section{test\+\_\+constraint.\+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} \textcolor{keywordtype}{void}
\_constraint\_set(Test\_Data *test\_data, \hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body} *body1, 
      \hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body} *body2)
\{
   \hyperlink{group__EPhysics__Constraint_ga6cdc4a630836a63a51489b885c09c7e3}{EPhysics\_Constraint} *constraint;
   \hyperlink{Evas__Common_8h_a2453e92182bad3b0e0d84e5aff433b07}{Evas\_Coord} b1x, b1y, b1z, b1w, b1h, b1d, b2x, b2y, b2z, b2w, b2h, b2d;

   \hyperlink{group__EPhysics__Body_gae84f1b9e25cb15f7ec63d1371093b263}{ephysics\_body\_geometry\_get}(body1, &b1x, &b1y, &b1z, &b1w, &b1h, &b1d);
   \hyperlink{group__EPhysics__Body_gae84f1b9e25cb15f7ec63d1371093b263}{ephysics\_body\_geometry\_get}(body2, &b2x, &b2y, &b2z, &b2w, &b2h, &b2d);

   constraint = \hyperlink{group__EPhysics__Constraint_ga49d1bce8073380c8e085caed3465d7e8}{ephysics\_constraint\_linked\_add}(body1, body2);

   \hyperlink{group__EPhysics__Constraint_gac70dbb237de696e0356fc9d7722ba835}{ephysics\_constraint\_anchor\_set}(constraint, b1x + b1w / 2, b1y + b1h / 2 + 
      100,
                                  b1z, b2x + b2w / 2, b2y + b2h / 2, b2z);
   test\_data->constraints = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(test\_data->constraints, constraint);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_world\_populate(Test\_Data *test\_data)
\{
   \hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body} *box\_body1, *box\_body2;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *box1, *box2, *sh1, *sh2;

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

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

   box\_body1 = \hyperlink{group__EPhysics__Body_gaf8f30587da7453114397d64dd9704d7f}{ephysics\_body\_box\_add}(test\_data->world);
   \hyperlink{group__EPhysics__Body_ga39cb9e95bbe1d097926a09365c501db3}{ephysics\_body\_evas\_object\_set}(box\_body1, box1, 
      \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE});
   \hyperlink{group__EPhysics__Body_gada176f4748a4c2fc4ba2042021ea7067}{ephysics\_body\_event\_callback\_add}(box\_body1, 
      \hyperlink{group__EPhysics__Body_gga904d0d1462e71c1f32cb27f540b5277cacb2363cd59bc8642e74ad916c6658e0a}{EPHYSICS\_CALLBACK\_BODY\_UPDATE},
                                    update\_object\_cb, sh1);
   \hyperlink{group__EPhysics__Body_ga731c9a6443f7c4294fce23fc1287b778}{ephysics\_body\_restitution\_set}(box\_body1, 0.3);
   \hyperlink{group__EPhysics__Body_ga986d45060bf6ba1689a56889a2bcabce}{ephysics\_body\_friction\_set}(box\_body1, 0.1);
   test\_data->bodies = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(test\_data->bodies, box\_body1);

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

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

   box\_body2 = \hyperlink{group__EPhysics__Body_gaf8f30587da7453114397d64dd9704d7f}{ephysics\_body\_box\_add}(test\_data->world);
   \hyperlink{group__EPhysics__Body_ga39cb9e95bbe1d097926a09365c501db3}{ephysics\_body\_evas\_object\_set}(box\_body2, box2, 
      \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE});
   \hyperlink{group__EPhysics__Body_gaa0915777f634079ca6c088fda5c20e8f}{ephysics\_body\_mass\_set}(box\_body2, 5);
   \hyperlink{group__EPhysics__Body_gada176f4748a4c2fc4ba2042021ea7067}{ephysics\_body\_event\_callback\_add}(box\_body2, 
      \hyperlink{group__EPhysics__Body_gga904d0d1462e71c1f32cb27f540b5277cacb2363cd59bc8642e74ad916c6658e0a}{EPHYSICS\_CALLBACK\_BODY\_UPDATE},
                                    update\_object\_cb, sh2);
   \hyperlink{group__EPhysics__Body_ga731c9a6443f7c4294fce23fc1287b778}{ephysics\_body\_restitution\_set}(box\_body2, 0.5);
   \hyperlink{group__EPhysics__Body_ga986d45060bf6ba1689a56889a2bcabce}{ephysics\_body\_friction\_set}(box\_body2, 0.1);
   test\_data->bodies = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(test\_data->bodies, box\_body2);

   \_constraint\_set(test\_data, box\_body1, box\_body2);
\}

\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\_constraint(\textcolor{keywordtype}{void} *data \_\_UNUSED\_\_, \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *obj \_\_UNUSED\_\_, \textcolor{keywordtype}{void} *event\_info \_\_UNUSED\_\_)
\{
   \hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body} *boundary;
   \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}{"Constraint"}, \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;

   boundary = \hyperlink{group__EPhysics__Body_gac5fc5a1817ac81e2f1fcdcd8908614f2}{ephysics\_body\_bottom\_boundary\_add}(test\_data->world);
   \hyperlink{group__EPhysics__Body_ga731c9a6443f7c4294fce23fc1287b778}{ephysics\_body\_restitution\_set}(boundary, 0.65);
   \hyperlink{group__EPhysics__Body_ga986d45060bf6ba1689a56889a2bcabce}{ephysics\_body\_friction\_set}(boundary, 3);

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