edje: support basic body attributes - friction and
restitution SVN revision: 80099
This commit is contained in:
parent
ced8d4f56d
commit
68a34bdd34
|
@ -311,6 +311,8 @@ static void st_collections_group_parts_part_description_table_padding(void);
|
|||
static void st_collections_group_parts_part_description_table_min(void);
|
||||
#ifdef HAVE_EPHYSICS
|
||||
static void st_collections_group_parts_part_description_physics_mass(void);
|
||||
static void st_collections_group_parts_part_description_physics_restitution(void);
|
||||
static void st_collections_group_parts_part_description_physics_friction(void);
|
||||
#endif
|
||||
static void st_collections_group_parts_part_description_map_perspective(void);
|
||||
static void st_collections_group_parts_part_description_map_light(void);
|
||||
|
@ -594,6 +596,8 @@ New_Statement_Handler statement_handlers[] =
|
|||
{"collections.group.parts.part.description.table.min", st_collections_group_parts_part_description_table_min},
|
||||
#ifdef HAVE_EPHYSICS
|
||||
{"collections.group.parts.part.description.physics.mass", st_collections_group_parts_part_description_physics_mass},
|
||||
{"collections.group.parts.part.description.physics.restitution", st_collections_group_parts_part_description_physics_restitution},
|
||||
{"collections.group.parts.part.description.physics.friction", st_collections_group_parts_part_description_physics_friction},
|
||||
#endif
|
||||
{"collections.group.parts.part.description.map.perspective", st_collections_group_parts_part_description_map_perspective},
|
||||
{"collections.group.parts.part.description.map.light", st_collections_group_parts_part_description_map_light},
|
||||
|
@ -1084,6 +1088,7 @@ _edje_part_description_alloc(unsigned char type, const char *collection, const c
|
|||
|
||||
#ifdef HAVE_EPHYSICS
|
||||
result->physics.mass = FROM_DOUBLE(1.0);
|
||||
result->physics.friction = FROM_DOUBLE(0.5);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
|
@ -7172,6 +7177,8 @@ st_collections_group_parts_part_description_table_min(void)
|
|||
..
|
||||
physics {
|
||||
mass: 5.31;
|
||||
friction: 0.5;
|
||||
restitution: 0.82;
|
||||
}
|
||||
..
|
||||
}
|
||||
|
@ -7202,6 +7209,66 @@ st_collections_group_parts_part_description_physics_mass(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
@page edcref
|
||||
@property
|
||||
restitution
|
||||
@parameters
|
||||
[body's restitution]
|
||||
@effect
|
||||
The coefficient of restitution is proporcion between speed after and
|
||||
before a collision. It's 0 by default.
|
||||
|
||||
COR = relative speed after collision / relative speed before collision
|
||||
|
||||
@li elastically collide for COR == 1;
|
||||
@li inelastically collide for 0 < COR < 1;
|
||||
@li completelly stop (no bouncing at all) for COR == 0.
|
||||
|
||||
@endproperty
|
||||
@since 1.8.0
|
||||
*/
|
||||
|
||||
#ifdef HAVE_EPHYSICS
|
||||
static void
|
||||
st_collections_group_parts_part_description_physics_restitution(void)
|
||||
{
|
||||
check_arg_count(1);
|
||||
|
||||
current_desc->physics.restitution = parse_float(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
@page edcref
|
||||
@property
|
||||
friction
|
||||
@parameters
|
||||
[body's friction]
|
||||
@effect
|
||||
Friction is used to make objects slide along each ot
|
||||
|
||||
The friction parameter is usually set between 0 and 1, but can be any
|
||||
non-negative value. A friction value of 0 turns off friction and a value
|
||||
of 1 makes the friction strong.
|
||||
|
||||
By default friction value is 0.5 and simulation resulsts will be better
|
||||
when friction in non-zero.
|
||||
|
||||
@endproperty
|
||||
@since 1.8.0
|
||||
*/
|
||||
|
||||
#ifdef HAVE_EPHYSICS
|
||||
static void
|
||||
st_collections_group_parts_part_description_physics_friction(void)
|
||||
{
|
||||
check_arg_count(1);
|
||||
|
||||
current_desc->physics.friction = parse_float(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
@edcsubsection{collections_group_parts_description_map,Map}
|
||||
*/
|
||||
|
|
|
@ -33,6 +33,8 @@ collections {
|
|||
aspect: 1 1;
|
||||
physics {
|
||||
mass: 10.8;
|
||||
restitution: 0.7;
|
||||
friction: 1.0;
|
||||
}
|
||||
}
|
||||
description {
|
||||
|
@ -40,6 +42,7 @@ collections {
|
|||
inherit: "default" 0.0;
|
||||
physics {
|
||||
mass: 6.66;
|
||||
friction: 1.2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2291,6 +2291,8 @@ _edje_part_recalc_single(Edje *ed,
|
|||
|
||||
#ifdef HAVE_EPHYSICS
|
||||
params->physics.mass = desc->physics.mass;
|
||||
params->physics.restitution = desc->physics.restitution;
|
||||
params->physics.friction = desc->physics.friction;
|
||||
#endif
|
||||
_edje_part_recalc_single_map(ed, ep, center, light, persp, desc, chosen_desc, params);
|
||||
}
|
||||
|
@ -2808,6 +2810,11 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta
|
|||
#ifdef HAVE_EPHYSICS
|
||||
p3->physics.mass = TO_DOUBLE(FINTP(p1->physics.mass, p2->physics.mass,
|
||||
pos));
|
||||
p3->physics.restitution = TO_DOUBLE(FINTP(p1->physics.restitution,
|
||||
p2->physics.restitution,
|
||||
pos));
|
||||
p3->physics.friction = TO_DOUBLE(FINTP(p1->physics.friction,
|
||||
p2->physics.friction, pos));
|
||||
#endif
|
||||
|
||||
switch (part_type)
|
||||
|
@ -3001,6 +3008,9 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta
|
|||
ephysics_body_move(ep->body,
|
||||
ed->x + pf->x, ed->y + pf->y, z);
|
||||
ephysics_body_mass_set(ep->body, pf->physics.mass);
|
||||
ephysics_body_restitution_set(ep->body,
|
||||
pf->physics.restitution);
|
||||
ephysics_body_friction_set(ep->body, pf->physics.friction);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
|
|
@ -514,6 +514,8 @@ _edje_edd_init(void)
|
|||
{ \
|
||||
EDJE_DATA_DESCRIPTOR_DESCRIPTION_COMMON_FIELDS(Edd, Type) \
|
||||
EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.mass", physics.mass, EET_T_DOUBLE); \
|
||||
EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.restitution", physics.restitution, EET_T_DOUBLE); \
|
||||
EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.friction", physics.friction, EET_T_DOUBLE); \
|
||||
}
|
||||
#else
|
||||
#define EDJE_DATA_DESCRIPTOR_DESCRIPTION_COMMON(Edd, Type) \
|
||||
|
@ -579,6 +581,8 @@ _edje_edd_init(void)
|
|||
{ \
|
||||
EDJE_DATA_DESCRIPTOR_DESCRIPTION_COMMON_SUB_FIELDS(Edd, Type, Dec) \
|
||||
EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.mass", Dec.physics.mass, EET_T_DOUBLE); \
|
||||
EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.restitution", Dec.physics.restitution, EET_T_DOUBLE); \
|
||||
EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.friction", Dec.physics.friction, EET_T_DOUBLE); \
|
||||
}
|
||||
#else
|
||||
#define EDJE_DATA_DESCRIPTOR_DESCRIPTION_COMMON_SUB(Edd, Type, Dec) \
|
||||
|
|
|
@ -961,6 +961,8 @@ struct _Edje_Part_Description_Common
|
|||
#ifdef HAVE_EPHYSICS
|
||||
struct {
|
||||
double mass;
|
||||
double restitution;
|
||||
double friction;
|
||||
} physics;
|
||||
#endif
|
||||
|
||||
|
@ -1295,7 +1297,9 @@ struct _Edje_Calc_Params
|
|||
#ifdef HAVE_EPHYSICS
|
||||
struct {
|
||||
double mass; // 8
|
||||
} physics; // 8
|
||||
double restitution; // 8
|
||||
double friction; // 8
|
||||
} physics; // 24
|
||||
#endif
|
||||
unsigned char persp_on : 1;
|
||||
unsigned char lighted : 1;
|
||||
|
|
Loading…
Reference in New Issue