forked from enlightenment/efl
EPhysics: add test using different shapes
Position / size looks buggy. Need to be fixed. SVN revision: 75153
This commit is contained in:
parent
031d47d1a9
commit
5088b6bb93
|
@ -22,12 +22,13 @@ Unported License:
|
|||
collisionL.png
|
||||
cube-blue.png
|
||||
cube-purple.png
|
||||
hexagonal.png
|
||||
hexagon.png
|
||||
list-item-corner.png
|
||||
list-item-corner-pressed.png
|
||||
list-item.png
|
||||
list-item-pressed.png
|
||||
list.png
|
||||
pentagon.png
|
||||
shadow-ball.png
|
||||
shadow-cube.png
|
||||
spinner_base.png
|
||||
|
|
|
@ -20,6 +20,7 @@ EXTRA_DIST = \
|
|||
frame.edc \
|
||||
list.edc \
|
||||
shadows.edc \
|
||||
shapes.edc \
|
||||
spinner.edc \
|
||||
images/arrows.png \
|
||||
images/background.jpg \
|
||||
|
@ -41,11 +42,12 @@ EXTRA_DIST = \
|
|||
images/collisionL.png \
|
||||
images/cube-blue.png \
|
||||
images/cube-purple.png \
|
||||
images/hexagonal.png \
|
||||
images/hexagon.png \
|
||||
images/list-item.png \
|
||||
images/list-item-corner.png \
|
||||
images/list-item-corner-pressed.png \
|
||||
images/list-item-pressed.png \
|
||||
images/pentagon.png \
|
||||
images/shadow-ball.png \
|
||||
images/shadow-cube.png \
|
||||
images/spinner_base.png \
|
||||
|
|
|
@ -10,5 +10,6 @@ collections {
|
|||
#include "frame.edc"
|
||||
#include "list.edc"
|
||||
#include "shadows.edc"
|
||||
#include "shapes.edc"
|
||||
#include "spinner.edc"
|
||||
}
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 4.3 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
|
@ -0,0 +1,24 @@
|
|||
#define ADD_SHAPE(_name) \
|
||||
images { \
|
||||
image: #_name##".png" COMP; \
|
||||
} \
|
||||
group { \
|
||||
name: #_name; \
|
||||
parts { \
|
||||
part { \
|
||||
name: #_name; \
|
||||
mouse_events: 0; \
|
||||
type: IMAGE; \
|
||||
description { \
|
||||
state: "default" 0.0; \
|
||||
image.normal: #_name##".png"; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
ADD_SHAPE(hexagon)
|
||||
ADD_SHAPE(pentagon)
|
||||
ADD_SHAPE(star)
|
||||
|
||||
#undef ADD_SHAPE
|
|
@ -31,6 +31,7 @@ test_jumping_balls.c \
|
|||
test_no_gravity.c \
|
||||
test_rotate.c \
|
||||
test_velocity.c \
|
||||
test_shapes.c \
|
||||
test_sleeping_threshold.c \
|
||||
test_slider.c
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ void test_jumping_balls(void *data, Evas_Object *obj, void *event_info);
|
|||
void test_no_gravity(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_rotate(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_velocity(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_shapes(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_sleeping(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_slider(void *data, Evas_Object *obj, void *event_info);
|
||||
|
||||
|
@ -168,6 +169,7 @@ _main_win_add(char *autorun __UNUSED__, Eina_Bool test_win_only __UNUSED__)
|
|||
ADD_TEST("NO GRAVITY", test_no_gravity);
|
||||
ADD_TEST("ROTATE", test_rotate);
|
||||
ADD_TEST("VELOCITY", test_velocity);
|
||||
ADD_TEST("SHAPES", test_shapes);
|
||||
ADD_TEST("SLEEPING THRESHOLD", test_sleeping);
|
||||
ADD_TEST("SLIDER", test_slider);
|
||||
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "ephysics_test.h"
|
||||
|
||||
static void
|
||||
_world_populate(Test_Data *test_data)
|
||||
{
|
||||
EPhysics_Shape *pentagon_shape, *hexagon_shape;
|
||||
EPhysics_Body *pentagon_body, *hexagon_body;
|
||||
EPhysics_Constraint *constraint;
|
||||
Evas_Object *pentagon, *hexagon;
|
||||
|
||||
pentagon = elm_image_add(test_data->win);
|
||||
elm_image_file_set(
|
||||
pentagon, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "pentagon");
|
||||
evas_object_move(pentagon, WIDTH / 3, HEIGHT / 2 - 30);
|
||||
evas_object_resize(pentagon, 70, 66);
|
||||
evas_object_show(pentagon);
|
||||
test_data->evas_objs = eina_list_append(test_data->evas_objs, pentagon);
|
||||
|
||||
pentagon_shape = ephysics_shape_new();
|
||||
ephysics_shape_point_add(pentagon_shape, 0/70., 24/66.);
|
||||
ephysics_shape_point_add(pentagon_shape, 35/70., 0/66.);
|
||||
ephysics_shape_point_add(pentagon_shape, 70/70., 24/66.);
|
||||
ephysics_shape_point_add(pentagon_shape, 56/70., 66/66.);
|
||||
ephysics_shape_point_add(pentagon_shape, 14/70., 66/66.);
|
||||
|
||||
pentagon_body = ephysics_body_shape_add(test_data->world, pentagon_shape);
|
||||
ephysics_body_evas_object_set(pentagon_body, pentagon, EINA_TRUE);
|
||||
ephysics_body_restitution_set(pentagon_body, 1);
|
||||
ephysics_body_friction_set(pentagon_body, 0);
|
||||
test_data->bodies = eina_list_append(test_data->bodies, pentagon_body);
|
||||
|
||||
hexagon = elm_image_add(test_data->win);
|
||||
elm_image_file_set(
|
||||
hexagon, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "hexagon");
|
||||
evas_object_move(hexagon, WIDTH / 3 + 80, HEIGHT / 2 - 30 + 35);
|
||||
evas_object_resize(hexagon, 70, 60);
|
||||
evas_object_show(hexagon);
|
||||
test_data->evas_objs = eina_list_append(test_data->evas_objs, hexagon);
|
||||
|
||||
hexagon_shape = ephysics_shape_new();
|
||||
ephysics_shape_point_add(hexagon_shape, 0, 0.5);
|
||||
ephysics_shape_point_add(hexagon_shape, 18/70., 0);
|
||||
ephysics_shape_point_add(hexagon_shape, 52/70., 0);
|
||||
ephysics_shape_point_add(hexagon_shape, 1, 0.5);
|
||||
ephysics_shape_point_add(hexagon_shape, 52/70., 1);
|
||||
ephysics_shape_point_add(hexagon_shape, 18/70., 1);
|
||||
|
||||
hexagon_body = ephysics_body_shape_add(test_data->world, hexagon_shape);
|
||||
ephysics_body_mass_set(hexagon_body, 5);
|
||||
ephysics_body_evas_object_set(hexagon_body, hexagon, EINA_TRUE);
|
||||
ephysics_body_restitution_set(hexagon_body, 1);
|
||||
ephysics_body_friction_set(hexagon_body, 0);
|
||||
test_data->bodies = eina_list_append(test_data->bodies, hexagon_body);
|
||||
|
||||
constraint = ephysics_constraint_p2p_add(pentagon_body, NULL, 8, 0,
|
||||
0, 0);
|
||||
test_data->constraints = eina_list_append(test_data->constraints,
|
||||
constraint);
|
||||
|
||||
constraint = ephysics_constraint_p2p_add(hexagon_body, NULL, 0, 0, 0, 0);
|
||||
test_data->constraints = eina_list_append(test_data->constraints,
|
||||
constraint);
|
||||
|
||||
ephysics_body_torque_impulse_apply(pentagon_body, 2);
|
||||
|
||||
ephysics_shape_del(pentagon_shape);
|
||||
ephysics_shape_del(hexagon_shape);
|
||||
|
||||
ephysics_world_serialize(test_data->world, "/tmp/test.bullet");
|
||||
}
|
||||
|
||||
static void
|
||||
_restart(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
|
||||
{
|
||||
Test_Data *test_data = data;
|
||||
|
||||
DBG("Restart pressed");
|
||||
test_clean(test_data);
|
||||
_world_populate(test_data);
|
||||
}
|
||||
|
||||
void
|
||||
test_shapes(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, "Shapes", EINA_TRUE);
|
||||
elm_object_signal_emit(test_data->layout, "borders,show", "ephysics_test");
|
||||
elm_layout_signal_callback_add(test_data->layout, "restart", "test-theme",
|
||||
_restart, test_data);
|
||||
|
||||
world = ephysics_world_new();
|
||||
ephysics_world_render_geometry_set(world, 50, 40, WIDTH - 100, FLOOR_Y - 40);
|
||||
test_data->world = world;
|
||||
|
||||
_world_populate(test_data);
|
||||
}
|
Loading…
Reference in New Issue