efl

Форк
0
/
test_forces.c 
114 строк · 4.0 Кб
1
#ifdef HAVE_CONFIG_H
2
# include <config.h>
3
#endif
4

5
#include "ephysics_test.h"
6

7
static void
8
_update_object_cb(void *data __UNUSED__, EPhysics_Body *body, void *event_info __UNUSED__)
9
{
10
   double x, y, z, torque, vx, vy, vz, va;
11

12
   ephysics_body_evas_object_update(body);
13
   ephysics_body_forces_get(body, &x, &y, &z);
14
   ephysics_body_torques_get(body, NULL, NULL, &torque);
15
   DBG("Body %p, fx: %lf, fy: %lf, fz: %lf, torque: %lf", body, x, y, z,
16
       torque);
17

18
   ephysics_body_linear_velocity_get(body, &vx, &vy, &vz);
19
   ephysics_body_angular_velocity_get(body, NULL, NULL, &va);
20
   DBG("Body %p, vx: %lf, vy: %lf, vz: %lf, va: %lf", body, vx, vy, vz, va);
21
}
22

23
static void
24
_world_populate(Test_Data *test_data)
25
{
26
   EPhysics_Body *box_body1, *box_body2;
27
   Evas_Object *box1, *box2;
28

29
   box1 = elm_image_add(test_data->win);
30
   elm_image_file_set(
31
      box1, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "blue-cube");
32
   evas_object_move(box1, 80, FLOOR_Y - 200);
33
   evas_object_resize(box1, 70, 70);
34
   evas_object_show(box1);
35
   test_data->evas_objs = eina_list_append(test_data->evas_objs, box1);
36

37
   box_body1 = ephysics_body_box_add(test_data->world);
38
   ephysics_body_evas_object_set(box_body1, box1, EINA_TRUE);
39
   ephysics_body_event_callback_add(box_body1, EPHYSICS_CALLBACK_BODY_UPDATE,
40
                                    _update_object_cb, NULL);
41
   ephysics_body_restitution_set(box_body1, 0.7);
42
   ephysics_body_friction_set(box_body1, 0);
43
   ephysics_body_force_apply(box_body1, 60, 0, 0, 0, 10, 0);
44
   test_data->bodies = eina_list_append(test_data->bodies, box_body1);
45

46
   box2 = elm_image_add(test_data->win);
47
   elm_image_file_set(
48
      box2, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "purple-cube");
49
   evas_object_move(box2, 80, FLOOR_Y - 100);
50
   evas_object_resize(box2, 70, 70);
51
   evas_object_show(box2);
52
   test_data->evas_objs = eina_list_append(test_data->evas_objs, box2);
53

54
   box_body2 = ephysics_body_box_add(test_data->world);
55
   ephysics_body_evas_object_set(box_body2, box2, EINA_TRUE);
56
   ephysics_body_event_callback_add(box_body2, EPHYSICS_CALLBACK_BODY_UPDATE,
57
                                    _update_object_cb, NULL);
58
   ephysics_body_restitution_set(box_body2, 0.7);
59
   ephysics_body_friction_set(box_body2, 0);
60
   ephysics_body_central_force_apply(box_body2, 60, 0, 0);
61
   test_data->bodies = eina_list_append(test_data->bodies, box_body2);
62
   test_data->data = box_body2;
63
}
64

65
static void
66
_restart(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
67
{
68
   Test_Data *test_data = data;
69

70
   DBG("Restart pressed");
71
   test_clean(test_data);
72
   _world_populate(test_data);
73
}
74

75
void
76
test_forces(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
77
{
78
   EPhysics_Body *boundary;
79
   EPhysics_World *world;
80
   Test_Data *test_data;
81

82
   if (!ephysics_init())
83
     return;
84

85
   test_data = test_data_new();
86
   test_win_add(test_data, "Forces", EINA_TRUE);
87
   elm_object_signal_emit(test_data->layout, "borders,show", "ephysics_test");
88
   elm_layout_signal_callback_add(test_data->layout, "restart", "test-theme",
89
                                  _restart, test_data);
90

91
   world = ephysics_world_new();
92
   ephysics_world_render_geometry_set(world, 50, 40, -50,
93
                                      WIDTH - 100, FLOOR_Y - 40, DEPTH);
94
   test_data->world = world;
95

96
   boundary = ephysics_body_bottom_boundary_add(test_data->world);
97
   ephysics_body_restitution_set(boundary, 1);
98
   ephysics_body_friction_set(boundary, 0);
99

100
   boundary = ephysics_body_top_boundary_add(test_data->world);
101
   ephysics_body_restitution_set(boundary, 1);
102
   ephysics_body_friction_set(boundary, 0);
103

104
   boundary = ephysics_body_left_boundary_add(test_data->world);
105
   ephysics_body_restitution_set(boundary, 1);
106
   ephysics_body_friction_set(boundary, 0);
107

108
   boundary = ephysics_body_right_boundary_add(test_data->world);
109
   ephysics_body_restitution_set(boundary, 1);
110
   ephysics_body_friction_set(boundary, 0);
111

112
   _world_populate(test_data);
113
   ephysics_world_gravity_set(world, 0, 0, 0);
114
}
115

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.