parent
a2a51a28fa
commit
3532a4620f
|
@ -30,6 +30,15 @@
|
|||
image: "background.jpg" COMP;
|
||||
}
|
||||
|
||||
styles {
|
||||
style {
|
||||
name: "test_style";
|
||||
base: "font=Sans font_size=20 align=justify color=#c6b19a";
|
||||
tag: "br" "\n";
|
||||
tag: "tab" "\t";
|
||||
}
|
||||
}
|
||||
|
||||
parts {
|
||||
|
||||
part {
|
||||
|
@ -85,7 +94,7 @@
|
|||
mouse_events: 0;
|
||||
description {
|
||||
state: "default" 0.0;
|
||||
color: 232 224 215 0;
|
||||
color: 0 0 0 0;
|
||||
rel1.relative: 0.08 0.96;
|
||||
rel2.relative: 0.92 1.0;
|
||||
text {
|
||||
|
@ -102,13 +111,47 @@
|
|||
}
|
||||
}
|
||||
|
||||
part {
|
||||
name: "controls_msg";
|
||||
type: TEXTBLOCK;
|
||||
mouse_events: 0;
|
||||
description {
|
||||
state: "default" 0.0;
|
||||
rel1.relative: 0.5 0.5;
|
||||
rel2.relative: 0.5 0.5;
|
||||
color: 0 0 0 0;
|
||||
text {
|
||||
style: "test_style";
|
||||
min: 1 1;
|
||||
max: 1 1;
|
||||
text: "Impulse Controls:<br>"
|
||||
" X Axis <tab> H - L<br>"
|
||||
" Y Axis <tab> J - K<br>"
|
||||
" Z Axis <tab> F - G";
|
||||
}
|
||||
}
|
||||
description {
|
||||
state: "msg1" 0.0;
|
||||
inherit: "default" 0.0;
|
||||
color: 95 56 19 255;
|
||||
}
|
||||
description {
|
||||
state: "msg2" 0.0;
|
||||
inherit: "msg1" 0.0;
|
||||
text.text: "Impulse Controls:<br>"
|
||||
" Pitch <tab> Y - O<br>"
|
||||
" Yaw <tab> U - I<br>"
|
||||
" Roll <tab> R - T";
|
||||
}
|
||||
}
|
||||
|
||||
part {
|
||||
name: "grab_msg";
|
||||
type: TEXT;
|
||||
mouse_events: 0;
|
||||
description {
|
||||
state: "default" 0.0;
|
||||
color: 232 224 215 0;
|
||||
color: 0 0 0 0;
|
||||
rel1.relative: 0.08 0.96;
|
||||
rel2.relative: 0.92 1.0;
|
||||
text {
|
||||
|
@ -289,6 +332,31 @@
|
|||
target: "arrows_msg";
|
||||
}
|
||||
|
||||
program {
|
||||
name: "controls,show";
|
||||
source: "ephysics_test";
|
||||
signal: "controls,show";
|
||||
action: STATE_SET "msg1" 0.0;
|
||||
target: "controls_msg";
|
||||
after: "controls,show,2";
|
||||
}
|
||||
|
||||
program {
|
||||
name: "controls,show,2";
|
||||
in: 4 0;
|
||||
action: STATE_SET "msg2" 0.0;
|
||||
target: "controls_msg";
|
||||
after: "controls,show,3";
|
||||
}
|
||||
|
||||
program {
|
||||
name: "controls,show,3";
|
||||
in: 4 0;
|
||||
action: STATE_SET "msg1" 0.0;
|
||||
target: "controls_msg";
|
||||
after: "controls,show,2";
|
||||
}
|
||||
|
||||
program {
|
||||
name: "grab,show";
|
||||
source: "ephysics_test";
|
||||
|
|
|
@ -16,6 +16,7 @@ EXTRA_PROGRAMS = ephysics_test ephysics_logo ephysics_sandbox
|
|||
|
||||
ephysics_test_SOURCES = \
|
||||
test.c \
|
||||
test_bouncing_3d.c \
|
||||
test_bouncing_ball.c \
|
||||
test_bouncing_text.c \
|
||||
test_camera.c \
|
||||
|
|
|
@ -15,6 +15,7 @@ struct _EPhysics_Test {
|
|||
};
|
||||
|
||||
/* examples prototypes */
|
||||
void test_bouncing_3d(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_bouncing_ball(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_bouncing_text(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_camera(void *data, Evas_Object *obj, void *event_info);
|
||||
|
@ -45,6 +46,7 @@ void test_soft_body(void *data, Evas_Object *obj, void *event_info);
|
|||
void test_win_resize(void *data, Evas_Object *obj, void *event_info);
|
||||
|
||||
static const EPhysics_Test tests[] = {
|
||||
{"Bouncing 3D", test_bouncing_3d},
|
||||
{"Bouncing Ball", test_bouncing_ball},
|
||||
{"Bouncing Text", test_bouncing_text},
|
||||
{"Camera", test_camera},
|
||||
|
|
|
@ -0,0 +1,144 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "ephysics_test.h"
|
||||
|
||||
void
|
||||
_pos_print_cb(void *data __UNUSED__, EPhysics_Body *body, void *event_info __UNUSED__)
|
||||
{
|
||||
Evas_Coord x, y, z;
|
||||
double rx, ry, rz;
|
||||
|
||||
ephysics_body_geometry_get(body, &x, &y, &z, NULL, NULL, NULL);
|
||||
ephysics_body_rotation_get(body, &rx, &ry, &rz);
|
||||
|
||||
printf("Position X:%i Y:%i Z:%i\n", x, y, z);
|
||||
printf("Rotation X:%lf Y:%lf Z:%lf\n", rx, ry, rz);
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_on_keydown(void *data, Evas_Object *obj __UNUSED__, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
|
||||
{
|
||||
Evas_Event_Key_Down *ev = event_info;
|
||||
EPhysics_Body *body = data;
|
||||
|
||||
if (type != EVAS_CALLBACK_KEY_UP)
|
||||
return EINA_FALSE;
|
||||
|
||||
if (!strcmp(ev->keyname, "j"))
|
||||
ephysics_body_central_impulse_apply(body, 0, -150, 0);
|
||||
else if (!strcmp(ev->keyname, "k"))
|
||||
ephysics_body_central_impulse_apply(body, 0, 150, 0);
|
||||
else if (!strcmp(ev->keyname, "l"))
|
||||
ephysics_body_central_impulse_apply(body, 150, 0, 0);
|
||||
else if (!strcmp(ev->keyname, "h"))
|
||||
ephysics_body_central_impulse_apply(body, -150, 0, 0);
|
||||
else if (!strcmp(ev->keyname, "f"))
|
||||
ephysics_body_central_impulse_apply(body, 0, 0, -150);
|
||||
else if (!strcmp(ev->keyname, "g"))
|
||||
ephysics_body_central_impulse_apply(body, 0, 0, 150);
|
||||
else if (!strcmp(ev->keyname, "u"))
|
||||
ephysics_body_torque_impulse_apply(body, 0, -5, 0);
|
||||
else if (!strcmp(ev->keyname, "i"))
|
||||
ephysics_body_torque_impulse_apply(body, 0, 5, 0);
|
||||
else if (!strcmp(ev->keyname, "o"))
|
||||
ephysics_body_torque_impulse_apply(body, 5, 0, 0);
|
||||
else if (!strcmp(ev->keyname, "y"))
|
||||
ephysics_body_torque_impulse_apply(body, -5, 0, 0);
|
||||
else if (!strcmp(ev->keyname, "r"))
|
||||
ephysics_body_torque_impulse_apply(body, 0, 0, -5);
|
||||
else if (!strcmp(ev->keyname, "t"))
|
||||
ephysics_body_torque_impulse_apply(body, 0, 0, 5);
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_world_populate(Test_Data *test_data)
|
||||
{
|
||||
Evas_Object *cube, *shadow;
|
||||
EPhysics_Body *box;
|
||||
|
||||
shadow = elm_layout_add(test_data->win);
|
||||
elm_layout_file_set(
|
||||
shadow, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "shadow-ball");
|
||||
evas_object_move(shadow, WIDTH / 3, FLOOR_Y);
|
||||
evas_object_resize(shadow, 70, 3);
|
||||
evas_object_show(shadow);
|
||||
test_data->evas_objs = eina_list_append(test_data->evas_objs, shadow);
|
||||
|
||||
cube = elm_image_add(test_data->win);
|
||||
elm_image_file_set(
|
||||
cube, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "purple-cube");
|
||||
evas_object_move(cube, WIDTH / 3, HEIGHT / 8);
|
||||
evas_object_resize(cube, 70, 70);
|
||||
evas_object_show(cube);
|
||||
test_data->evas_objs = eina_list_append(test_data->evas_objs, cube);
|
||||
|
||||
box = ephysics_body_box_add(test_data->world);
|
||||
ephysics_body_evas_object_set(box, cube, EINA_TRUE);
|
||||
ephysics_body_restitution_set(box, 0.95);
|
||||
ephysics_body_friction_set(box, 0.1);
|
||||
ephysics_body_linear_movement_enable_set(box, EINA_TRUE, EINA_TRUE,
|
||||
EINA_TRUE);
|
||||
ephysics_body_angular_movement_enable_set(box, EINA_TRUE, EINA_TRUE,
|
||||
EINA_TRUE);
|
||||
ephysics_body_event_callback_add(box, EPHYSICS_CALLBACK_BODY_UPDATE,
|
||||
update_object_cb, shadow);
|
||||
ephysics_body_event_callback_add(box, EPHYSICS_CALLBACK_BODY_UPDATE,
|
||||
_pos_print_cb, NULL);
|
||||
test_data->bodies = eina_list_append(test_data->bodies, box);
|
||||
test_data->data = box;
|
||||
}
|
||||
|
||||
static void
|
||||
_restart(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
|
||||
{
|
||||
Test_Data *test_data = data;
|
||||
|
||||
elm_object_event_callback_del(test_data->win, _on_keydown, test_data->data);
|
||||
test_clean(test_data);
|
||||
_world_populate(test_data);
|
||||
elm_object_event_callback_add(test_data->win, _on_keydown, test_data->data);
|
||||
}
|
||||
|
||||
void
|
||||
test_bouncing_3d(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
||||
{
|
||||
EPhysics_Body *boundary;
|
||||
EPhysics_World *world;
|
||||
Test_Data *test_data;
|
||||
|
||||
if (!ephysics_init())
|
||||
return;
|
||||
|
||||
test_data = test_data_new();
|
||||
test_win_add(test_data, "Bouncing 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");
|
||||
elm_object_signal_emit(test_data->layout, "controls,show", "ephysics_test");
|
||||
|
||||
world = ephysics_world_new();
|
||||
ephysics_world_render_geometry_set(world, 50, 40, WIDTH - 100, FLOOR_Y - 40);
|
||||
test_data->world = world;
|
||||
|
||||
boundary = ephysics_body_bottom_boundary_add(test_data->world, 10);
|
||||
ephysics_body_restitution_set(boundary, 0.65);
|
||||
ephysics_body_friction_set(boundary, 4);
|
||||
|
||||
boundary = ephysics_body_right_boundary_add(test_data->world, 10);
|
||||
ephysics_body_restitution_set(boundary, 0.4);
|
||||
ephysics_body_friction_set(boundary, 3);
|
||||
|
||||
boundary = ephysics_body_left_boundary_add(test_data->world, 10);
|
||||
ephysics_body_restitution_set(boundary, 0.4);
|
||||
ephysics_body_friction_set(boundary, 3);
|
||||
|
||||
ephysics_body_top_boundary_add(test_data->world, 10);
|
||||
|
||||
_world_populate(test_data);
|
||||
elm_object_event_callback_add(test_data->win, _on_keydown, test_data->data);
|
||||
}
|
Loading…
Reference in New Issue