summaryrefslogtreecommitdiff
path: root/legacy/ephysics/src/bin/test_hinge.c
diff options
context:
space:
mode:
authorLeandro Dorileo <dorileo@profusion.mobi>2012-11-29 18:53:56 +0000
committerLeandro Dorileo <dorileo@profusion.mobi>2012-11-29 18:53:56 +0000
commit9e76f59766a386613dec6512cc7a2469f1a5dc41 (patch)
treee207de0579fa5f379b1ca308cf73808ffc7a703d /legacy/ephysics/src/bin/test_hinge.c
parent0b558bc80ce7c6ed4bae0c64fd0c37cd0c8a1fab (diff)
EPhysics: add hinge test
Add a test to simulate a hinge constraint using the generic constraint API's. --This line, and those below, will be ignored-- SVN revision: 79849
Diffstat (limited to '')
-rw-r--r--legacy/ephysics/src/bin/test_hinge.c142
1 files changed, 142 insertions, 0 deletions
diff --git a/legacy/ephysics/src/bin/test_hinge.c b/legacy/ephysics/src/bin/test_hinge.c
new file mode 100644
index 0000000000..0136f7872a
--- /dev/null
+++ b/legacy/ephysics/src/bin/test_hinge.c
@@ -0,0 +1,142 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "ephysics_test.h"
6
7static void
8_door_create(Test_Data *test_data, Evas_Object *front, Evas_Object *back, Evas_Object *right, Evas_Object *left, Evas_Object *top)
9{
10 EPhysics_Body *body;
11 EPhysics_Constraint *constraint;
12 Evas_Coord x, y, z, w, h, d;
13
14 body = ephysics_body_box_add(test_data->world);
15 test_data->bodies = eina_list_append(test_data->bodies, body);
16
17 ephysics_body_face_evas_object_set(body, EPHYSICS_BODY_BOX_FACE_TOP, top,
18 EINA_TRUE);
19
20 ephysics_body_face_evas_object_set(body, EPHYSICS_BODY_BOX_FACE_RIGHT, right,
21 EINA_TRUE);
22
23 ephysics_body_face_evas_object_set(body, EPHYSICS_BODY_BOX_FACE_LEFT, left,
24 EINA_TRUE);
25
26 ephysics_body_face_evas_object_set(body, EPHYSICS_BODY_BOX_FACE_FRONT, front,
27 EINA_TRUE);
28
29 ephysics_body_face_evas_object_set(body, EPHYSICS_BODY_BOX_FACE_BACK, back,
30 EINA_TRUE);
31
32 ephysics_body_angular_movement_enable_set(body, EINA_FALSE, EINA_TRUE,
33 EINA_FALSE);
34
35 ephysics_body_linear_movement_enable_set(body, EINA_TRUE, EINA_TRUE,
36 EINA_TRUE);
37
38 ephysics_body_geometry_get(body, &x, &y, &z, &w, &h, &d);
39 ephysics_body_resize(body, w, h, 6);
40 ephysics_body_move(body, x, y, 150);
41 ephysics_body_geometry_get(body, &x, &y, &z, &w, &h, &d);
42
43 constraint = ephysics_constraint_add(body);
44 ephysics_constraint_angular_limit_set(constraint, 0, 0, 90, 0, 0, 0);
45 ephysics_constraint_anchor_set(constraint, x - 2, y + h / 2, z + d / 2, 0, 0,
46 0);
47 test_data->constraints = eina_list_append(test_data->constraints, constraint);
48 ephysics_body_impulse_apply(body, 0, 0, -10, x + w, y + h / 2, z);
49}
50
51static void
52_world_populate(Test_Data *test_data)
53{
54 Evas_Object *front, *back, *right, *left, *top;
55
56 front = elm_image_add(test_data->win);
57 elm_image_file_set(
58 front, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "door-front");
59 evas_object_resize(front, 139, 270);
60 evas_object_move(front, WIDTH / 3, FLOOR_Y - 290);
61 test_data->evas_objs = eina_list_append(test_data->evas_objs, front);
62
63 back = elm_image_add(test_data->win);
64 elm_image_file_set(
65 back, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "door-back");
66 evas_object_resize(back, 139, 270);
67 evas_object_move(back, WIDTH / 3, FLOOR_Y - 290);
68 test_data->evas_objs = eina_list_append(test_data->evas_objs, back);
69
70 right = evas_object_rectangle_add(evas_object_evas_get(test_data->win));
71 evas_object_color_set(right, 117, 75, 35, 255);
72 evas_object_resize(right, 6, 270);
73 test_data->evas_objs = eina_list_append(test_data->evas_objs, right);
74
75 left = evas_object_rectangle_add(evas_object_evas_get(test_data->win));
76 evas_object_color_set(left, 117, 75, 35, 255);
77 evas_object_resize(left, 6, 270);
78 test_data->evas_objs = eina_list_append(test_data->evas_objs, left);
79
80 top = evas_object_rectangle_add(evas_object_evas_get(test_data->win));
81 evas_object_color_set(top, 117, 75, 35, 255);
82 evas_object_resize(top, 139, 6);
83 test_data->evas_objs = eina_list_append(test_data->evas_objs, top);
84
85 _door_create(test_data, front, back, right, left, top);
86
87 evas_object_show(front);
88 evas_object_show(back);
89 evas_object_show(right);
90 evas_object_show(left);
91 evas_object_show(top);
92}
93
94static void
95_restart(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
96{
97 Test_Data *test_data = data;
98
99 DBG("Restart pressed");
100 test_clean(test_data);
101 _world_populate(test_data);
102}
103
104void
105test_hinge(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
106{
107 EPhysics_Camera *cam;
108 EPhysics_World *world;
109 Test_Data *test_data;
110 Evas_Object *floor_obj, *door_post;
111
112 if (!ephysics_init())
113 return;
114
115 test_data = test_data_new();
116 test_win_add(test_data, "Hinge", EINA_TRUE);
117 elm_layout_signal_callback_add(test_data->layout, "restart", "test-theme",
118 _restart, test_data);
119
120 floor_obj = elm_image_add(test_data->win);
121 elm_image_file_set(
122 floor_obj, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "floor");
123 evas_object_move(floor_obj, 0, FLOOR_Y - 20);
124 evas_object_resize(floor_obj, FLOOR_WIDTH, 224);
125 evas_object_show(floor_obj);
126
127 door_post = elm_image_add(test_data->win);
128 elm_image_file_set(
129 door_post, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "door-post");
130 evas_object_resize(door_post, 147, 278);
131 evas_object_move(door_post, WIDTH / 3 - 5, FLOOR_Y - 295);
132 evas_object_show(door_post);
133
134 world = ephysics_world_new();
135 cam = ephysics_world_camera_get(world);
136 ephysics_world_render_geometry_set(world, 0, 0, 0, WIDTH - 100, FLOOR_Y - 300,
137 300);
138 ephysics_camera_perspective_enabled_set(cam, EINA_TRUE);
139
140 test_data->world = world;
141 _world_populate(test_data);
142}