summaryrefslogtreecommitdiff
path: root/legacy/ephysics
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-10-04 22:39:47 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-10-04 22:39:47 +0000
commit7fe038a1c8d480e91664df68809b122791ab7fe7 (patch)
treea4a9f1622e4d9fb7cce72957fe6558d3a23bf4eb /legacy/ephysics
parent0bdec6725538665680ba77a84b21a745c7462380 (diff)
ephysics: add test for materials
SVN revision: 77463
Diffstat (limited to 'legacy/ephysics')
-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_material.c122
-rw-r--r--legacy/ephysics/src/lib/ephysics_body_materials.h2
4 files changed, 126 insertions, 1 deletions
diff --git a/legacy/ephysics/src/bin/Makefile.am b/legacy/ephysics/src/bin/Makefile.am
index a31965d067..1dc99669c4 100644
--- a/legacy/ephysics/src/bin/Makefile.am
+++ b/legacy/ephysics/src/bin/Makefile.am
@@ -30,6 +30,7 @@ test_falling_letters.c \
30test_forces.c \ 30test_forces.c \
31test_growing_balls.c \ 31test_growing_balls.c \
32test_jumping_balls.c \ 32test_jumping_balls.c \
33test_material.c \
33test_no_gravity.c \ 34test_no_gravity.c \
34test_rotate.c \ 35test_rotate.c \
35test_rotating_forever.c \ 36test_rotating_forever.c \
diff --git a/legacy/ephysics/src/bin/test.c b/legacy/ephysics/src/bin/test.c
index 03b680baf0..635b838cc4 100644
--- a/legacy/ephysics/src/bin/test.c
+++ b/legacy/ephysics/src/bin/test.c
@@ -29,6 +29,7 @@ void test_falling_letters(void *data, Evas_Object *obj, void *event_info);
29void test_forces(void *data, Evas_Object *obj, void *event_info); 29void test_forces(void *data, Evas_Object *obj, void *event_info);
30void test_growing_balls(void *data, Evas_Object *obj, void *event_info); 30void test_growing_balls(void *data, Evas_Object *obj, void *event_info);
31void test_jumping_balls(void *data, Evas_Object *obj, void *event_info); 31void test_jumping_balls(void *data, Evas_Object *obj, void *event_info);
32void test_material(void *data, Evas_Object *obj, void *event_info);
32void test_no_gravity(void *data, Evas_Object *obj, void *event_info); 33void test_no_gravity(void *data, Evas_Object *obj, void *event_info);
33void test_rotate(void *data, Evas_Object *obj, void *event_info); 34void test_rotate(void *data, Evas_Object *obj, void *event_info);
34void test_rotating_forever(void *data, Evas_Object *obj, void *event_info); 35void test_rotating_forever(void *data, Evas_Object *obj, void *event_info);
@@ -54,6 +55,7 @@ static const EPhysics_Test tests[] = {
54 {"Forces", test_forces}, 55 {"Forces", test_forces},
55 {"Growing Balls", test_growing_balls}, 56 {"Growing Balls", test_growing_balls},
56 {"Jumping Balls", test_jumping_balls}, 57 {"Jumping Balls", test_jumping_balls},
58 {"Material", test_material},
57 {"No Gravity", test_no_gravity}, 59 {"No Gravity", test_no_gravity},
58 {"Rotate", test_rotate}, 60 {"Rotate", test_rotate},
59 {"Rotating Forever", test_rotating_forever}, 61 {"Rotating Forever", test_rotating_forever},
diff --git a/legacy/ephysics/src/bin/test_material.c b/legacy/ephysics/src/bin/test_material.c
new file mode 100644
index 0000000000..7b2c3fc295
--- /dev/null
+++ b/legacy/ephysics/src/bin/test_material.c
@@ -0,0 +1,122 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "ephysics_test.h"
6
7static void
8_material_change(Test_Data *test_data)
9{
10 double density, mass, restitution, friction;
11 EPhysics_Body *body;
12 Evas_Object *sp;
13 int material;
14
15 sp = test_data->data;
16 material = (int) elm_spinner_value_get(sp);
17 body = evas_object_data_get(sp, "body");
18
19 ephysics_body_material_set(body, material);
20
21 material = ephysics_body_material_get(body);
22 density = ephysics_body_density_get(body);
23 mass = ephysics_body_mass_get(body);
24 restitution = ephysics_body_restitution_get(body);
25 friction = ephysics_body_friction_get(body);
26
27 INF("Material: %i, Density: %lf, Mass: %lf, Restitution: %lf, Friction: %lf",
28 material, density, mass, restitution, friction);
29}
30
31static void
32_material_changed_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
33{
34 _material_change(data);
35}
36
37static void
38_world_populate(Test_Data *test_data)
39{
40 Evas_Object *sphere, *shadow;
41 EPhysics_Body *fall_body;
42
43 shadow = elm_layout_add(test_data->win);
44 elm_layout_file_set(
45 shadow, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "shadow-ball");
46 evas_object_move(shadow, WIDTH / 3, FLOOR_Y);
47 evas_object_resize(shadow, 70, 3);
48 evas_object_show(shadow);
49 test_data->evas_objs = eina_list_append(test_data->evas_objs, shadow);
50
51 sphere = elm_image_add(test_data->win);
52 elm_image_file_set(
53 sphere, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "big-blue-ball");
54 evas_object_move(sphere, WIDTH / 3, HEIGHT / 8);
55 evas_object_resize(sphere, 70, 70);
56 evas_object_show(sphere);
57 test_data->evas_objs = eina_list_append(test_data->evas_objs, sphere);
58
59 fall_body = ephysics_body_circle_add(test_data->world);
60 ephysics_body_evas_object_set(fall_body, sphere, EINA_TRUE);
61 ephysics_body_event_callback_add(fall_body, EPHYSICS_CALLBACK_BODY_UPDATE,
62 update_object_cb, shadow);
63 test_data->bodies = eina_list_append(test_data->bodies, fall_body);
64
65 evas_object_data_set(test_data->data, "body", fall_body);
66}
67
68static void
69_restart(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
70{
71 DBG("Restart pressed");
72 test_clean(data);
73 _world_populate(data);
74 _material_change(data);
75}
76
77void
78test_material(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
79{
80 EPhysics_Body *boundary;
81 EPhysics_World *world;
82 Test_Data *test_data;
83 Evas_Object *sp;
84
85 if (!ephysics_init())
86 return;
87
88 test_data = test_data_new();
89 test_win_add(test_data, "Material", EINA_TRUE);
90
91 elm_layout_signal_callback_add(test_data->layout, "restart", "test-theme",
92 _restart, test_data);
93 elm_object_signal_emit(test_data->layout, "borders,show", "ephysics_test");
94
95 sp = elm_spinner_add(test_data->win);
96 elm_spinner_min_max_set(sp, 0, 6);
97 elm_spinner_step_set(sp, 1);
98 elm_spinner_wrap_set(sp, EINA_TRUE);
99 elm_spinner_special_value_add(sp, 0, "Custom");
100 elm_spinner_special_value_add(sp, 1, "Concrete");
101 elm_spinner_special_value_add(sp, 2, "Iron");
102 elm_spinner_special_value_add(sp, 3, "Plastic");
103 elm_spinner_special_value_add(sp, 4, "Polystyrene");
104 elm_spinner_special_value_add(sp, 5, "Rubber");
105 elm_spinner_special_value_add(sp, 6, "Wood");
106 elm_spinner_editable_set(sp, EINA_FALSE);
107 elm_object_style_set(sp, "ephysics-test");
108 evas_object_smart_callback_add(sp, "delay,changed", _material_changed_cb,
109 test_data);
110 elm_layout_content_set(test_data->layout, "extra_input", sp);
111 test_data->data = sp;
112
113 world = ephysics_world_new();
114 ephysics_world_render_geometry_set(world, 50, 40, WIDTH - 100, FLOOR_Y - 40);
115 test_data->world = world;
116
117 boundary = ephysics_body_bottom_boundary_add(test_data->world);
118 ephysics_body_restitution_set(boundary, 1);
119
120 _world_populate(test_data);
121 _material_change(test_data);
122}
diff --git a/legacy/ephysics/src/lib/ephysics_body_materials.h b/legacy/ephysics/src/lib/ephysics_body_materials.h
index 993a0b116b..e9ed0da3ad 100644
--- a/legacy/ephysics/src/lib/ephysics_body_materials.h
+++ b/legacy/ephysics/src/lib/ephysics_body_materials.h
@@ -14,7 +14,7 @@ struct _EPhysics_Body_Material_Props {
14}; 14};
15 15
16const EPhysics_Body_Material_Props ephysics_material_props [] = { 16const EPhysics_Body_Material_Props ephysics_material_props [] = {
17 {EPHYSICS_BODY_MATERIAL_CUSTOM, 1.0, 0.0, 0.0}, 17 {EPHYSICS_BODY_MATERIAL_CUSTOM, 1.0, 0.5, 0.0},
18 {EPHYSICS_BODY_MATERIAL_CONCRETE, EPHYSICS_BODY_DENSITY_CONCRETE, 18 {EPHYSICS_BODY_MATERIAL_CONCRETE, EPHYSICS_BODY_DENSITY_CONCRETE,
19 EPHYSICS_BODY_FRICTION_CONCRETE, EPHYSICS_BODY_RESTITUTION_CONCRETE}, 19 EPHYSICS_BODY_FRICTION_CONCRETE, EPHYSICS_BODY_RESTITUTION_CONCRETE},
20 {EPHYSICS_BODY_MATERIAL_IRON, EPHYSICS_BODY_DENSITY_IRON, 20 {EPHYSICS_BODY_MATERIAL_IRON, EPHYSICS_BODY_DENSITY_IRON,