summaryrefslogtreecommitdiff
path: root/legacy/ephysics/src
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-11-09 18:53:26 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-11-09 18:53:26 +0000
commit06bf7b0761e73d0410fb99100b600bb5cde4f92f (patch)
treebefeb10dee7f987e0fdde4092cc035b5465cd45c /legacy/ephysics/src
parent8a70256010ef7f9a100e022a92cbe92d73cf839a (diff)
ephysics: add dices test
SVN revision: 79047
Diffstat (limited to 'legacy/ephysics/src')
-rw-r--r--legacy/ephysics/src/bin/Makefile.am1
-rw-r--r--legacy/ephysics/src/bin/test.c2
-rw-r--r--legacy/ephysics/src/bin/test_bouncing_3d.c2
-rw-r--r--legacy/ephysics/src/bin/test_dices.c128
4 files changed, 132 insertions, 1 deletions
diff --git a/legacy/ephysics/src/bin/Makefile.am b/legacy/ephysics/src/bin/Makefile.am
index 46fa4db14e..4448576c1e 100644
--- a/legacy/ephysics/src/bin/Makefile.am
+++ b/legacy/ephysics/src/bin/Makefile.am
@@ -27,6 +27,7 @@ test_collision_filter.c \
27test_collision_speed.c \ 27test_collision_speed.c \
28test_constraint.c \ 28test_constraint.c \
29test_delete.c \ 29test_delete.c \
30test_dices.c \
30test_falling_letters.c \ 31test_falling_letters.c \
31test_forces.c \ 32test_forces.c \
32test_grab.c \ 33test_grab.c \
diff --git a/legacy/ephysics/src/bin/test.c b/legacy/ephysics/src/bin/test.c
index 96660e85da..646f230d12 100644
--- a/legacy/ephysics/src/bin/test.c
+++ b/legacy/ephysics/src/bin/test.c
@@ -26,6 +26,7 @@ void test_collision_filter(void *data, Evas_Object *obj, void *event_info);
26void test_collision_speed(void *data, Evas_Object *obj, void *event_info); 26void test_collision_speed(void *data, Evas_Object *obj, void *event_info);
27void test_constraint(void *data, Evas_Object *obj, void *event_info); 27void test_constraint(void *data, Evas_Object *obj, void *event_info);
28void test_delete(void *data, Evas_Object *obj, void *event_info); 28void test_delete(void *data, Evas_Object *obj, void *event_info);
29void test_dices(void *data, Evas_Object *obj, void *event_info);
29void test_falling_letters(void *data, Evas_Object *obj, void *event_info); 30void test_falling_letters(void *data, Evas_Object *obj, void *event_info);
30void test_flag(void *data, Evas_Object *obj, void *event_info); 31void test_flag(void *data, Evas_Object *obj, void *event_info);
31void test_forces(void *data, Evas_Object *obj, void *event_info); 32void test_forces(void *data, Evas_Object *obj, void *event_info);
@@ -56,6 +57,7 @@ static const EPhysics_Test tests[] = {
56 {"Collision Filter", test_collision_filter}, 57 {"Collision Filter", test_collision_filter},
57 {"Collision High Speed", test_collision_speed}, 58 {"Collision High Speed", test_collision_speed},
58 {"Constraint", test_constraint}, 59 {"Constraint", test_constraint},
60 {"Dices", test_dices},
59 {"Delete Body", test_delete}, 61 {"Delete Body", test_delete},
60 {"Falling Letters", test_falling_letters}, 62 {"Falling Letters", test_falling_letters},
61 {"Flag - Cloth", test_flag}, 63 {"Flag - Cloth", test_flag},
diff --git a/legacy/ephysics/src/bin/test_bouncing_3d.c b/legacy/ephysics/src/bin/test_bouncing_3d.c
index e0d6758e5c..2012b70cb8 100644
--- a/legacy/ephysics/src/bin/test_bouncing_3d.c
+++ b/legacy/ephysics/src/bin/test_bouncing_3d.c
@@ -4,7 +4,7 @@
4 4
5#include "ephysics_test.h" 5#include "ephysics_test.h"
6 6
7void 7static void
8_pos_print_cb(void *data __UNUSED__, EPhysics_Body *body, void *event_info __UNUSED__) 8_pos_print_cb(void *data __UNUSED__, EPhysics_Body *body, void *event_info __UNUSED__)
9{ 9{
10 Evas_Coord x, y, z; 10 Evas_Coord x, y, z;
diff --git a/legacy/ephysics/src/bin/test_dices.c b/legacy/ephysics/src/bin/test_dices.c
new file mode 100644
index 0000000000..725096fe38
--- /dev/null
+++ b/legacy/ephysics/src/bin/test_dices.c
@@ -0,0 +1,128 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "ephysics_test.h"
6
7static Evas_Object *
8_obj_face_add(Test_Data *test_data, const char *group, Evas_Coord x, Evas_Coord y)
9{
10 Evas_Object *obj;
11
12 obj = elm_image_add(test_data->win);
13 elm_image_file_set(obj, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj",
14 group);
15 evas_object_move(obj, x, y);
16 evas_object_resize(obj, 70, 70);
17 evas_object_show(obj);
18 test_data->evas_objs = eina_list_append(test_data->evas_objs, obj);
19
20 return obj;
21}
22
23static EPhysics_Body *
24_box_add(Test_Data *test_data, Evas_Coord x, Evas_Coord y)
25{
26 Evas_Object *front, *back, *top, *bottom, *right, *left, *shadow;
27 EPhysics_Body *box;
28
29 shadow = elm_layout_add(test_data->win);
30 elm_layout_file_set(
31 shadow, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "shadow-ball");
32 evas_object_move(shadow, x, FLOOR_Y);
33 evas_object_resize(shadow, 70, 3);
34 evas_object_show(shadow);
35 test_data->evas_objs = eina_list_append(test_data->evas_objs, shadow);
36
37 front = _obj_face_add(test_data, "dice1", x, y);
38 back = _obj_face_add(test_data, "dice6", x, y);
39 top = _obj_face_add(test_data, "dice2", x, y);
40 bottom = _obj_face_add(test_data, "dice5", x, y);
41 right = _obj_face_add(test_data, "dice3", x, y);
42 left = _obj_face_add(test_data, "dice4", x, y);
43
44 box = ephysics_body_box_add(test_data->world);
45 ephysics_body_face_evas_object_set(box, EPHYSICS_BODY_BOX_FACE_FRONT,
46 front, EINA_TRUE);
47 ephysics_body_face_evas_object_set(box, EPHYSICS_BODY_BOX_FACE_BACK,
48 back, EINA_TRUE);
49 ephysics_body_face_evas_object_set(box, EPHYSICS_BODY_BOX_FACE_TOP,
50 top, EINA_TRUE);
51 ephysics_body_face_evas_object_set(box, EPHYSICS_BODY_BOX_FACE_BOTTOM,
52 bottom, EINA_TRUE);
53 ephysics_body_face_evas_object_set(box, EPHYSICS_BODY_BOX_FACE_RIGHT,
54 right, EINA_TRUE);
55 ephysics_body_face_evas_object_set(box, EPHYSICS_BODY_BOX_FACE_LEFT,
56 left, EINA_TRUE);
57 ephysics_body_restitution_set(box, 0.7);
58 ephysics_body_sleeping_threshold_set(box, 0, 0);
59 ephysics_body_damping_set(box, 0, 0);
60 ephysics_body_linear_movement_enable_set(box, EINA_TRUE, EINA_TRUE,
61 EINA_TRUE);
62 ephysics_body_angular_movement_enable_set(box, EINA_TRUE, EINA_TRUE,
63 EINA_TRUE);
64 ephysics_body_event_callback_add(box, EPHYSICS_CALLBACK_BODY_UPDATE,
65 update_object_cb, shadow);
66 test_data->bodies = eina_list_append(test_data->bodies, box);
67
68 return box;
69}
70
71static void
72_world_populate(Test_Data *test_data)
73{
74 EPhysics_Body *box;
75
76 box = _box_add(test_data, WIDTH / 2, HEIGHT / 4);
77 ephysics_body_torque_impulse_apply(box, 6, -2, 0);
78 box = _box_add(test_data, 80, 80);
79 ephysics_body_torque_impulse_apply(box, 0, 0, 3);
80 ephysics_body_central_impulse_apply(box, 80, 0, 0);
81}
82
83static void
84_restart(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
85{
86 test_clean(data);
87 _world_populate(data);
88}
89
90void
91test_dices(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
92{
93 EPhysics_Body *boundary;
94 EPhysics_World *world;
95 Test_Data *test_data;
96
97 if (!ephysics_init())
98 return;
99
100 test_data = test_data_new();
101 test_win_add(test_data, "Dices", EINA_TRUE);
102
103 elm_layout_signal_callback_add(test_data->layout, "restart", "test-theme",
104 _restart, test_data);
105 elm_object_signal_emit(test_data->layout, "borders,show", "ephysics_test");
106
107 world = ephysics_world_new();
108 ephysics_world_render_geometry_set(world, 50, 40, -50,
109 WIDTH - 100, FLOOR_Y - 40, DEPTH * 2);
110 ephysics_camera_perspective_enabled_set(ephysics_world_camera_get(world),
111 EINA_TRUE);
112
113 ephysics_world_point_light_position_set(world, 0, 100, -400);
114 ephysics_world_ambient_light_color_set(world, 60, 60, 60);
115 ephysics_world_light_all_bodies_set(world, EINA_TRUE);
116
117 test_data->world = world;
118
119 boundary = ephysics_body_bottom_boundary_add(test_data->world);
120 ephysics_body_restitution_set(boundary, 0.7);
121
122 ephysics_body_right_boundary_add(test_data->world);
123 ephysics_body_left_boundary_add(test_data->world);
124 ephysics_body_back_boundary_add(test_data->world);
125 ephysics_body_top_boundary_add(test_data->world);
126
127 _world_populate(test_data);
128}