ephysics: add cube 3d test
authorBruno Dilly <bdilly@profusion.mobi>
Tue, 13 Nov 2012 22:18:09 +0000 (22:18 +0000)
committerBruno Dilly <bdilly@profusion.mobi>
Tue, 13 Nov 2012 22:18:09 +0000 (22:18 +0000)
spot issues on rotation based on euler angles

SVN revision: 79251

legacy/ephysics/data/themes/Makefile.am
legacy/ephysics/data/themes/cubes.edc
legacy/ephysics/data/themes/images/cube_back.png [new file with mode: 0644]
legacy/ephysics/data/themes/images/cube_bottom.png [new file with mode: 0644]
legacy/ephysics/data/themes/images/cube_front.png [new file with mode: 0644]
legacy/ephysics/data/themes/images/cube_left.png [new file with mode: 0644]
legacy/ephysics/data/themes/images/cube_right.png [new file with mode: 0644]
legacy/ephysics/data/themes/images/cube_top.png [new file with mode: 0644]
legacy/ephysics/src/bin/Makefile.am
legacy/ephysics/src/bin/test.c
legacy/ephysics/src/bin/test_cube_3d.c [new file with mode: 0644]

index 11d2fd2..6e0e7e1 100644 (file)
@@ -48,6 +48,12 @@ TEST_FILES = \
        images/collisionL.png \
        images/cube-blue.png \
        images/cube-purple.png \
+       images/cube_back.png \
+       images/cube_bottom.png \
+       images/cube_front.png \
+       images/cube_left.png \
+       images/cube_right.png \
+       images/cube_top.png \
        images/dice1.png \
        images/dice2.png \
        images/dice3.png \
index b2be72a..f6d99b6 100644 (file)
 
 ADD_CUBE(blue-cube, cube-blue);
 ADD_CUBE(purple-cube, cube-purple);
+ADD_CUBE(cube_top, cube_top);
+ADD_CUBE(cube_bottom, cube_bottom);
+ADD_CUBE(cube_front, cube_front);
+ADD_CUBE(cube_back, cube_back);
+ADD_CUBE(cube_right, cube_right);
+ADD_CUBE(cube_left, cube_left);
 
 ADD_CUBE(dice1, dice1);
 ADD_CUBE(dice2, dice2);
diff --git a/legacy/ephysics/data/themes/images/cube_back.png b/legacy/ephysics/data/themes/images/cube_back.png
new file mode 100644 (file)
index 0000000..c8da7d8
Binary files /dev/null and b/legacy/ephysics/data/themes/images/cube_back.png differ
diff --git a/legacy/ephysics/data/themes/images/cube_bottom.png b/legacy/ephysics/data/themes/images/cube_bottom.png
new file mode 100644 (file)
index 0000000..62ff8d2
Binary files /dev/null and b/legacy/ephysics/data/themes/images/cube_bottom.png differ
diff --git a/legacy/ephysics/data/themes/images/cube_front.png b/legacy/ephysics/data/themes/images/cube_front.png
new file mode 100644 (file)
index 0000000..2c5f827
Binary files /dev/null and b/legacy/ephysics/data/themes/images/cube_front.png differ
diff --git a/legacy/ephysics/data/themes/images/cube_left.png b/legacy/ephysics/data/themes/images/cube_left.png
new file mode 100644 (file)
index 0000000..adbdcc3
Binary files /dev/null and b/legacy/ephysics/data/themes/images/cube_left.png differ
diff --git a/legacy/ephysics/data/themes/images/cube_right.png b/legacy/ephysics/data/themes/images/cube_right.png
new file mode 100644 (file)
index 0000000..4d4e423
Binary files /dev/null and b/legacy/ephysics/data/themes/images/cube_right.png differ
diff --git a/legacy/ephysics/data/themes/images/cube_top.png b/legacy/ephysics/data/themes/images/cube_top.png
new file mode 100644 (file)
index 0000000..dd981d7
Binary files /dev/null and b/legacy/ephysics/data/themes/images/cube_top.png differ
index 54e7390..b25c909 100644 (file)
@@ -27,6 +27,7 @@ test_collision_detection.c \
 test_collision_filter.c \
 test_collision_speed.c \
 test_constraint.c \
+test_cube_3d.c \
 test_delete.c \
 test_dices.c \
 test_falling_letters.c \
index 38b577b..6b409f5 100644 (file)
@@ -26,6 +26,7 @@ void test_collision(void *data, Evas_Object *obj, void *event_info);
 void test_collision_filter(void *data, Evas_Object *obj, void *event_info);
 void test_collision_speed(void *data, Evas_Object *obj, void *event_info);
 void test_constraint(void *data, Evas_Object *obj, void *event_info);
+void test_cube_3d(void *data, Evas_Object *obj, void *event_info);
 void test_delete(void *data, Evas_Object *obj, void *event_info);
 void test_dices(void *data, Evas_Object *obj, void *event_info);
 void test_falling_letters(void *data, Evas_Object *obj, void *event_info);
@@ -58,6 +59,7 @@ static const EPhysics_Test tests[] = {
        {"Collision Filter", test_collision_filter},
        {"Collision High Speed", test_collision_speed},
        {"Constraint", test_constraint},
+       {"Cube 3D", test_cube_3d},
        {"Dices", test_dices},
        {"Delete Body", test_delete},
        {"Falling Letters", test_falling_letters},
diff --git a/legacy/ephysics/src/bin/test_cube_3d.c b/legacy/ephysics/src/bin/test_cube_3d.c
new file mode 100644 (file)
index 0000000..01bcf7f
--- /dev/null
@@ -0,0 +1,116 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "ephysics_test.h"
+
+#define BOX_SIZE (70)
+
+static void
+_mouse_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
+{
+   Evas_Event_Mouse_Move *mmove = event_info;
+   EPhysics_Body *body = data;
+   double rx, ry, rz;
+
+   if (mmove->buttons != 1) return;
+
+   ephysics_body_rotation_get(body, &rx, &ry, &rz);
+   rx += mmove->cur.output.y - mmove->prev.output.y;
+   ry += mmove->cur.output.x - mmove->prev.output.x;
+   ephysics_body_rotation_set(body, rx, ry, rz);
+}
+
+static void
+_obj_face_add(Test_Data *test_data, EPhysics_Body *body, EPhysics_Body_Face face, const char *group, Evas_Coord x, Evas_Coord y)
+{
+   Evas_Object *obj;
+
+   obj = elm_image_add(test_data->win);
+   elm_image_file_set(obj, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj",
+                      group);
+   evas_object_move(obj, x, y);
+   evas_object_resize(obj, BOX_SIZE, BOX_SIZE);
+   evas_object_show(obj);
+
+   ephysics_body_face_evas_object_set(body, face, obj, EINA_TRUE);
+
+   test_data->evas_objs = eina_list_append(test_data->evas_objs, obj);
+}
+
+static void
+_world_populate(Test_Data *test_data)
+{
+   EPhysics_Body *box;
+   Evas_Object *rect;
+   Evas_Coord x, y;
+   Evas *evas;
+
+   x = (WIDTH - BOX_SIZE) / 2;
+   y = (HEIGHT - BOX_SIZE) / 2;
+
+   box = ephysics_body_box_add(test_data->world);
+
+   _obj_face_add(test_data, box, EPHYSICS_BODY_BOX_FACE_FRONT, "cube_front",
+                 x, y);
+   _obj_face_add(test_data, box, EPHYSICS_BODY_BOX_FACE_BACK, "cube_back",
+                 x, y);
+   _obj_face_add(test_data, box, EPHYSICS_BODY_BOX_FACE_TOP, "cube_top",
+                 x, y);
+   _obj_face_add(test_data, box, EPHYSICS_BODY_BOX_FACE_BOTTOM, "cube_bottom",
+                 x, y);
+   _obj_face_add(test_data, box, EPHYSICS_BODY_BOX_FACE_RIGHT, "cube_right",
+                 x, y);
+   _obj_face_add(test_data, box, EPHYSICS_BODY_BOX_FACE_LEFT, "cube_left",
+                 x, y);
+
+   ephysics_body_damping_set(box, 0, 0.2);
+   ephysics_body_linear_movement_enable_set(box, EINA_FALSE, EINA_FALSE,
+                                            EINA_FALSE);
+   ephysics_body_angular_movement_enable_set(box, EINA_TRUE, EINA_TRUE,
+                                             EINA_TRUE);
+   test_data->bodies = eina_list_append(test_data->bodies, box);
+
+   evas = evas_object_evas_get(test_data->win);
+   rect = evas_object_rectangle_add(evas);
+   evas_object_resize(rect, 120, 120);
+   evas_object_move(rect, (WIDTH - 120) / 2, (HEIGHT - 120) / 2);
+   evas_object_color_set(rect, 0, 0, 0, 0);
+   evas_object_show(rect);
+   evas_object_event_callback_add(rect, EVAS_CALLBACK_MOUSE_MOVE,
+                                  _mouse_move_cb, box);
+}
+
+static void
+_restart(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
+{
+   test_clean(data);
+   _world_populate(data);
+}
+
+void
+test_cube_3d(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+   EPhysics_World *world;
+   Test_Data *test_data;
+
+   if (!ephysics_init())
+     return;
+
+   test_data = test_data_new();
+   test_win_add(test_data, "Cube 3D", EINA_TRUE);
+
+   elm_layout_signal_callback_add(test_data->layout, "restart", "test-theme",
+                                  _restart, test_data);
+   elm_object_signal_emit(test_data->layout, "borders,show", "ephysics_test");
+
+   world = ephysics_world_new();
+   ephysics_world_render_geometry_set(world, 50, 40, -50,
+                                      WIDTH - 100, FLOOR_Y - 40, DEPTH * 2);
+   ephysics_world_gravity_set(world, 0, 0, 0);
+   ephysics_camera_perspective_enabled_set(ephysics_world_camera_get(world),
+                                           EINA_TRUE);
+   test_data->world = world;
+
+   _world_populate(test_data);
+}