From c4832ceda5c0293f841767b4fb269ed2322dea11 Mon Sep 17 00:00:00 2001 From: Bruno Dilly Date: Mon, 10 Dec 2012 14:19:03 +0000 Subject: [PATCH] edje: add soft body stuff SVN revision: 80609 --- legacy/edje/data/edc.vim | 2 +- legacy/edje/data/include/edje.inc | 3 +- legacy/edje/src/bin/edje_cc_handlers.c | 30 +++ legacy/edje/src/examples/Makefile.am | 3 +- legacy/edje/src/examples/physics_basic.edc | 3 +- .../edje/src/examples/physics_soft_bodies.edc | 180 ++++++++++++++++++ legacy/edje/src/lib/edje_calc.c | 9 + legacy/edje/src/lib/edje_data.c | 2 + legacy/edje/src/lib/edje_embryo.c | 10 + legacy/edje/src/lib/edje_private.h | 7 +- 10 files changed, 243 insertions(+), 6 deletions(-) create mode 100644 legacy/edje/src/examples/physics_soft_bodies.edc diff --git a/legacy/edje/data/edc.vim b/legacy/edje/data/edc.vim index 3dfc3502fd..5bb7cc6b67 100644 --- a/legacy/edje/data/edc.vim +++ b/legacy/edje/data/edc.vim @@ -47,7 +47,7 @@ syn keyword cLabel external params size_range border_scale minmul syn keyword cLabel mass density material restitution friction syn keyword cLabel ignore_part_pos light_on damping sleep -syn keyword cLabel physics_body +syn keyword cLabel physics_body hardness syn keyword cConditional if else switch syn keyword cRepeat while for do diff --git a/legacy/edje/data/include/edje.inc b/legacy/edje/data/include/edje.inc index aa94919e82..91215cee34 100644 --- a/legacy/edje/data/include/edje.inc +++ b/legacy/edje/data/include/edje.inc @@ -219,7 +219,8 @@ enum State_Param STATE_PHYSICS_MATERIAL = 48, STATE_PHYSICS_DENSITY = 49, STATE_PHYSICS_IGNORE_PART_POS = 50, - STATE_PHYSICS_LIGHT_ON = 51 + STATE_PHYSICS_LIGHT_ON = 51, + STATE_PHYSICS_HARDNESS = 52 }; native set_state_val(part_id, State_Param:p, ...); diff --git a/legacy/edje/src/bin/edje_cc_handlers.c b/legacy/edje/src/bin/edje_cc_handlers.c index 962f503f40..e96b52584a 100644 --- a/legacy/edje/src/bin/edje_cc_handlers.c +++ b/legacy/edje/src/bin/edje_cc_handlers.c @@ -317,6 +317,7 @@ static void st_collections_group_parts_part_description_physics_damping(void); static void st_collections_group_parts_part_description_physics_sleep(void); static void st_collections_group_parts_part_description_physics_material(void); static void st_collections_group_parts_part_description_physics_density(void); +static void st_collections_group_parts_part_description_physics_hardness(void); static void st_collections_group_parts_part_description_physics_ignore_part_pos(void); static void st_collections_group_parts_part_description_physics_light_on(void); #endif @@ -608,6 +609,7 @@ New_Statement_Handler statement_handlers[] = {"collections.group.parts.part.description.physics.sleep", st_collections_group_parts_part_description_physics_sleep}, {"collections.group.parts.part.description.physics.material", st_collections_group_parts_part_description_physics_material}, {"collections.group.parts.part.description.physics.density", st_collections_group_parts_part_description_physics_density}, + {"collections.group.parts.part.description.physics.hardness", st_collections_group_parts_part_description_physics_hardness}, {"collections.group.parts.part.description.physics.ignore_part_pos", st_collections_group_parts_part_description_physics_ignore_part_pos}, {"collections.group.parts.part.description.physics.light_on", st_collections_group_parts_part_description_physics_light_on}, #endif @@ -1103,6 +1105,7 @@ _edje_part_description_alloc(unsigned char type, const char *collection, const c result->physics.friction = FROM_DOUBLE(0.5); result->physics.sleep.linear = FROM_DOUBLE(24); result->physics.sleep.angular = FROM_DOUBLE(57.29); + result->physics.hardness = FROM_DOUBLE(1.0); result->physics.ignore_part_pos = 1; #endif @@ -7201,6 +7204,7 @@ st_collections_group_parts_part_description_table_min(void) sleep: 32 18.9; material: IRON; density: 3.2; + hardness: 0.42; light_on: 1; } .. @@ -7441,6 +7445,32 @@ st_collections_group_parts_part_description_physics_density(void) } #endif +/** + @page edcref + @property + hardness + @parameters + [soft bodie or cloth hardness] + @effect + The hardness is set with a double value (0.0 - 1.0), defining + how the soft body is supposed to deform. + Its default is set to 1.0. The soft body mass will also interfere on + soft body deformation, so bare in mind that the bodies mass must also + be changed to have different deformation results. + Valid values vary from 0.0 to 1.0. Only works on soft bodies and cloths. + @endproperty + @since 1.8.0 +*/ +#ifdef HAVE_EPHYSICS +static void +st_collections_group_parts_part_description_physics_hardness(void) +{ + check_arg_count(1); + + current_desc->physics.hardness = parse_float_range(0, 0, 1.0); +} +#endif + /** @page edcref @property diff --git a/legacy/edje/src/examples/Makefile.am b/legacy/edje/src/examples/Makefile.am index 5debecdf4e..31dc21b5a7 100644 --- a/legacy/edje/src/examples/Makefile.am +++ b/legacy/edje/src/examples/Makefile.am @@ -56,7 +56,8 @@ if ENABLE_EPHYSICS EDCS += \ physics_actions.edc \ physics_basic.edc \ -physics_complex.edc +physics_complex.edc \ +physics_soft_bodies.edc endif .edc.edj: diff --git a/legacy/edje/src/examples/physics_basic.edc b/legacy/edje/src/examples/physics_basic.edc index 8784a044db..cdbd11f782 100644 --- a/legacy/edje/src/examples/physics_basic.edc +++ b/legacy/edje/src/examples/physics_basic.edc @@ -59,7 +59,8 @@ collections { state: "default" 0.0; visible: 0; physics { - restitution: 0.7; + restitution: 0.92; + friction: 0.6; } } } diff --git a/legacy/edje/src/examples/physics_soft_bodies.edc b/legacy/edje/src/examples/physics_soft_bodies.edc new file mode 100644 index 0000000000..34946bcf1e --- /dev/null +++ b/legacy/edje/src/examples/physics_soft_bodies.edc @@ -0,0 +1,180 @@ +collections { + + images { + image: "bubble-blue.png" COMP; + } + + group { + name: "example_group"; + + parts { + part { + name: "background"; + type: RECT; + physics_body: NONE; + description { + state: "default" 0.0; + color: 255 255 255 255; /* white */ + rel1.relative: 0.0 0.0; + rel2.relative: 1.0 1.0; + } + } + + part { + name: "red_box"; + type: RECT; + physics_body: SOFT_BOX; + description { + state: "default" 0.0; + color: 255 0 0 255; /* red */ + rel1.relative: 0.75 0.1; + rel2.relative: 0.95 0.3; + aspect: 1 1; + physics { + ignore_part_pos: 0; + restitution: 0.85; + } + } + description { + state: "soft" 0.0; + inherit: "default" 0.0; + physics { + hardness: 0.5; + } + } + description { + state: "very_soft" 0.0; + inherit: "default" 0.0; + physics { + hardness: 0.2; + } + } + } + + part { + name: "blue_circle"; + type: IMAGE; + physics_body: SOFT_CIRCLE; + description { + state: "default" 0.0; + rel1.relative: 0.25 0.1; + rel2.relative: 0.45 0.3; + aspect: 1 1; + image { + normal: "bubble-blue.png"; + } + physics { + ignore_part_pos: 0; + restitution: 0.85; + hardness: 1; + } + } + description { + state: "soft" 0.0; + inherit: "default" 0.0; + physics.hardness: 0.5; + } + description { + state: "very_soft" 0.0; + inherit: "default" 0.0; + physics.hardness: 0.2; + } + } + + part { + name: "floor"; + type: RECT; + physics_body: BOUNDARY_BOTTOM; + description { + state: "default" 0.0; + visible: 0; + physics { + restitution: 0.7; + } + } + } + + part { + name: "right_wall"; + type: RECT; + physics_body: BOUNDARY_RIGHT; + description { + state: "default" 0.0; + visible: 0; + physics { + restitution: 1.0; + } + } + } + + part { + name: "left_wall"; + type: RECT; + physics_body: BOUNDARY_LEFT; + description { + state: "default" 0.0; + visible: 0; + physics { + restitution: 1.0; + } + } + } + + } + + programs { + program { + name: "stop,go_soft"; + signal: "load"; + in: 3 0; + action: PHYSICS_STOP; + target: "red_box"; + target: "blue_circle"; + after: "go_soft"; + } + + program { + name: "go_soft"; + action: STATE_SET "soft" 0.0; + target: "red_box"; + target: "blue_circle"; + after: "stop,go_very_soft"; + } + + program { + name: "stop,go_very_soft"; + in: 3 0; + action: PHYSICS_STOP; + target: "red_box"; + target: "blue_circle"; + after: "go_very_soft"; + } + + program { + name: "go_very_soft"; + action: STATE_SET "very_soft" 0.0; + target: "red_box"; + target: "blue_circle"; + after: "stop,go_default"; + } + + program { + name: "stop,go_default"; + in: 3 0; + action: PHYSICS_STOP; + target: "red_box"; + target: "blue_circle"; + after: "go_default"; + } + + program { + name: "go_default"; + action: STATE_SET "default" 0.0; + target: "red_box"; + target: "blue_circle"; + after: "stop,go_soft"; + } + } + + } +} diff --git a/legacy/edje/src/lib/edje_calc.c b/legacy/edje/src/lib/edje_calc.c index c0cb36164e..a94fbf0f05 100644 --- a/legacy/edje/src/lib/edje_calc.c +++ b/legacy/edje/src/lib/edje_calc.c @@ -2305,6 +2305,7 @@ _edje_part_recalc_single(Edje *ed, params->physics.sleep.angular = desc->physics.sleep.angular; params->physics.material = desc->physics.material; params->physics.density = desc->physics.density; + params->physics.hardness = desc->physics.hardness; params->physics.ignore_part_pos = desc->physics.ignore_part_pos; params->physics.light_on = desc->physics.light_on; #endif @@ -2487,6 +2488,12 @@ _edje_physics_body_props_update(Edje_Real_Part *ep, Edje_Calc_Params *pf, Eina_B else ephysics_body_mass_set(ep->body, pf->physics.mass); } + + if ((ep->part->physics_body == EDJE_PART_PHYSICS_BODY_SOFT_BOX) || + (ep->part->physics_body == EDJE_PART_PHYSICS_BODY_SOFT_CIRCLE) || + (ep->part->physics_body == EDJE_PART_PHYSICS_BODY_CLOTH)) + ephysics_body_soft_body_hardness_set(ep->body, + pf->physics.hardness * 100); } if (!pf->physics.material) @@ -2953,6 +2960,8 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta p2->physics.friction, pos)); p3->physics.density = TO_DOUBLE(FINTP(p1->physics.density, p2->physics.density, pos)); + p3->physics.hardness = TO_DOUBLE(FINTP(p1->physics.hardness, + p2->physics.hardness, pos)); p3->physics.damping.linear = TO_DOUBLE(FINTP( p1->physics.damping.linear, p2->physics.damping.linear, pos)); diff --git a/legacy/edje/src/lib/edje_data.c b/legacy/edje/src/lib/edje_data.c index 1fdc3f32d6..78d5e1fbfa 100644 --- a/legacy/edje/src/lib/edje_data.c +++ b/legacy/edje/src/lib/edje_data.c @@ -528,6 +528,7 @@ _edje_edd_init(void) EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.sleep.angular", physics.sleep.angular, EET_T_DOUBLE); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.material", physics.material, EET_T_UCHAR); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.density", physics.density, EET_T_DOUBLE); \ + EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.hardness", physics.hardness, EET_T_DOUBLE); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.ignore_part_pos", physics.ignore_part_pos, EET_T_UCHAR); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.light_on", physics.light_on, EET_T_UCHAR); \ } @@ -603,6 +604,7 @@ _edje_edd_init(void) EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.sleep.angular", Dec.physics.sleep.angular, EET_T_DOUBLE); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.material", Dec.physics.material, EET_T_UCHAR); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.density", Dec.physics.density, EET_T_DOUBLE); \ + EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.hardness", Dec.physics.hardness, EET_T_DOUBLE); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.ignore_part_pos", Dec.physics.ignore_part_pos, EET_T_UCHAR); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.light_on", Dec.physics.light_on, EET_T_UCHAR); \ } diff --git a/legacy/edje/src/lib/edje_embryo.c b/legacy/edje/src/lib/edje_embryo.c index 653a5257d8..bb64480220 100644 --- a/legacy/edje/src/lib/edje_embryo.c +++ b/legacy/edje/src/lib/edje_embryo.c @@ -2302,6 +2302,11 @@ _edje_embryo_fn_set_state_val(Embryo_Program *ep, Embryo_Cell *params) GETFLOAT_T(rp->custom->description->physics.density, params[3]); break; + case EDJE_STATE_PARAM_PHYSICS_HARDNESS: + CHKPARAM(3); + + GETFLOAT_T(rp->custom->description->physics.hardness, params[3]); + break; case EDJE_STATE_PARAM_PHYSICS_IGNORE_PART_POS: CHKPARAM(3); @@ -2806,6 +2811,11 @@ _edje_embryo_fn_get_state_val(Embryo_Program *ep, Embryo_Cell *params) SETFLOAT_T(rp->custom->description->physics.density, params[3]); break; + case EDJE_STATE_PARAM_PHYSICS_HARDNESS: + CHKPARAM(3); + + SETFLOAT_T(rp->custom->description->physics.hardness, params[3]); + break; case EDJE_STATE_PARAM_PHYSICS_IGNORE_PART_POS: CHKPARAM(3); diff --git a/legacy/edje/src/lib/edje_private.h b/legacy/edje/src/lib/edje_private.h index 67ee38be16..be5b587b4c 100644 --- a/legacy/edje/src/lib/edje_private.h +++ b/legacy/edje/src/lib/edje_private.h @@ -423,7 +423,8 @@ typedef struct _Edje_Markup_Filter_Callback Edje_Markup_Filter_Callback; #define EDJE_STATE_PARAM_PHYSICS_DENSITY 49 #define EDJE_STATE_PARAM_PHYSICS_IGNORE_PART_POS 50 #define EDJE_STATE_PARAM_PHYSICS_LIGHT_ON 51 -#define EDJE_STATE_PARAM_LAST 52 +#define EDJE_STATE_PARAM_PHYSICS_HARDNESS 52 +#define EDJE_STATE_PARAM_LAST 53 #define EDJE_ENTRY_EDIT_MODE_NONE 0 #define EDJE_ENTRY_EDIT_MODE_SELECTABLE 1 @@ -980,6 +981,7 @@ struct _Edje_Part_Description_Common double restitution; double friction; double density; + double hardness; struct { double linear; double angular; @@ -1328,6 +1330,7 @@ struct _Edje_Calc_Params double restitution; // 8 double friction; // 8 double density; // 8 + double hardness; // 8 struct { double linear; //8 double angular; //8 @@ -1339,7 +1342,7 @@ struct _Edje_Calc_Params unsigned char material; // 1 unsigned char light_on; // 1 unsigned char ignore_part_pos; //1 - } physics; // 67 + } physics; // 75 #endif unsigned char persp_on : 1; unsigned char lighted : 1;