ephysics: break up light functions

Long list of same typed parameters is very error prone.
Not the scene will have a initial light configuration, that can
be enabled and modified.



SVN revision: 78678
This commit is contained in:
Bruno Dilly 2012-10-30 18:31:32 +00:00
parent f9b904ae03
commit 54a8f1678d
6 changed files with 166 additions and 122 deletions

View File

@ -88,6 +88,7 @@ test_bouncing_ball(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *eve
elm_object_signal_emit(test_data->layout, "arrows,show", "ephysics_test");
world = ephysics_world_new();
ephysics_world_light_all_bodies_set(world, EINA_TRUE);
ephysics_world_render_geometry_set(world, 50, 40, -50,
WIDTH - 100, FLOOR_Y - 40, DEPTH);
test_data->world = world;

View File

@ -154,7 +154,7 @@ test_flag(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info _
WIDTH - 100, FLOOR_Y - 40, DEPTH);
test_data->world = world;
ephysics_world_light_set(world, 300, 50, -200, 255, 255, 255, 0, 0, 0);
ephysics_world_point_light_position_set(world, 300, 50, -200);
ephysics_world_light_all_bodies_set(world, EINA_TRUE);
ephysics_camera_perspective_enabled_set(ephysics_world_camera_get(world),
EINA_TRUE);

View File

@ -75,9 +75,10 @@ test_light(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info
ephysics_body_restitution_set(boundary, 0.65);
ephysics_body_friction_set(boundary, 4);
ephysics_world_light_set(world, 200, 300, -120, 255, 120, 120, 40, 40, 40);
ephysics_world_point_light_position_set(world, 200, 300, -120);
ephysics_world_point_light_color_set(world, 255, 120, 120);
ephysics_world_ambient_light_color_set(world, 40, 40, 40);
ephysics_world_light_all_bodies_set(world, EINA_TRUE);
_world_populate(test_data);
}

View File

@ -1413,7 +1413,7 @@ EAPI void ephysics_world_simulation_get(const EPhysics_World *world, double *fix
/**
* @brief
* Set light properties to be applied on the scene.
* Set position of point light to be applied on the scene.
*
* It will perform lighting calculations on the evas map applied on evas
* objects associated with all the bodies to have light applied over.
@ -1434,63 +1434,110 @@ EAPI void ephysics_world_simulation_get(const EPhysics_World *world, double *fix
* @ref ephysics_world_light_all_bodies_set(). The other, is to set each body
* individually, with @ref ephysics_body_light_set().
*
* By default, no light is set. And after a light is set, by default,
* no body will be affected. No change will be visible until
* By default, point light is set to position (0, 0, -200) and has white color
* (r=255, g=255, b=255). The ambient color is black (r=0, g=0, b=0).
* But no body will be affected. No change will be visible until
* some bodies are set to be enlightened.
*
* @param world The physics world.
* @param lx X coordinate in space of light point
* @param ly Y coordinate in space of light point
* @param lz Z coordinate in space of light point
*
* @see ephysics_world_point_light_position_get().
* @see ephysics_world_point_light_color_set().
* @see ephysics_world_ambient_light_color_set().
*
* @ingroup EPhysics_World
*/
EAPI void ephysics_world_point_light_position_set(EPhysics_World *world, Evas_Coord lx, Evas_Coord ly, Evas_Coord lz);
/**
* @brief
* Set color of point light to be applied on the scene.
*
* By default color of point light is r=255, g=255, b=255.
*
* @param world The physics world.
* @param lr light red value (0 - 255)
* @param lg light green value (0 - 255)
* @param lb light blue value (0 - 255)
*
* @see ephysics_world_point_light_position_set() for more details.
* @see ephysics_world_point_light_color_get().
*
* @ingroup EPhysics_World
*/
EAPI void ephysics_world_point_light_color_set(EPhysics_World *world, int lr, int lg, int lb);
/**
* @brief
* Set color of the ambient light to be applied on the scene.
*
* By default, ambient color is set to r=0, g=0, b=0.
*
* @param world The physics world.
* @param ar ambient color red value (0 - 255)
* @param ag ambient color green value (0 - 255)
* @param ab ambient color blue value (0 - 255)
*
* @see ephysics_world_light_get().
* @see ephysics_world_point_light_position_set() for more details.
* @see ephysics_world_ambient_light_color_get().
*
* @ingroup EPhysics_World
*/
EAPI void ephysics_world_light_set(EPhysics_World *world, Evas_Coord lx, Evas_Coord ly, Evas_Coord lz, int lr, int lg, int lb, int ar, int ag, int ab);
EAPI void ephysics_world_ambient_light_color_set(EPhysics_World *world, int ar, int ag, int ab);
/**
* @brief
* Get light properties.
* Get position of point light applied on the scene.
*
* @param world The physics world.
* @param lx X coordinate in space of light point
* @param ly Y coordinate in space of light point
* @param lz Z coordinate in space of light point
* @param lr light red value (0 - 255)
* @param lg light green value (0 - 255)
* @param lb light blue value (0 - 255)
* @param ar ambient color red value (0 - 255)
* @param ag ambient color green value (0 - 255)
* @param ab ambient color blue value (0 - 255)
* @return @c EINA_TRUE if light is set, or @c EINA_FALSE if it isn't set,
* or on error. On this case the other parameters won't be set.
*
* @see ephysics_world_light_set() for more details.
* @see ephysics_world_point_light_position_set() for details.
*
* @ingroup EPhysics_World
*/
EAPI Eina_Bool ephysics_world_light_get(const EPhysics_World *world, Evas_Coord *lx, Evas_Coord *ly, Evas_Coord *lz, int *lr, int *lg, int *lb, int *ar, int *ag, int *ab);
EAPI void ephysics_world_point_light_position_get(const EPhysics_World *world, Evas_Coord *lx, Evas_Coord *ly, Evas_Coord *lz);
/**
* @brief
* Unset light on the scene.
* Get color of point light applied on the scene.
*
* It will unset light, so no body will be enlightened anymore.
* By default color of point light is r=255, g=255, b=255.
*
* @param world The physics world.
* @param lr light red value (0 - 255)
* @param lg light green value (0 - 255)
* @param lb light blue value (0 - 255)
*
* @see ephysics_world_light_set() for more details.
* @see ephysics_world_point_light_position_set() for more details.
* @see ephysics_world_point_light_color_set().
*
* @ingroup EPhysics_World
*/
EAPI void ephysics_world_light_unset(EPhysics_World *world);
EAPI void ephysics_world_point_light_color_get(const EPhysics_World *world, int *lr, int *lg, int *lb);
/**
* @brief
* Set color of the ambient light to be applied on the scene.
*
* By default, ambient color is set to r=0, g=0, b=0.
*
* @param world The physics world.
* @param ar ambient color red value (0 - 255)
* @param ag ambient color green value (0 - 255)
* @param ab ambient color blue value (0 - 255)
*
* @see ephysics_world_point_light_position_set() for more details.
* @see ephysics_world_ambient_light_color_set().
*
* @ingroup EPhysics_World
*/
EAPI void ephysics_world_ambient_light_color_get(const EPhysics_World *world, int *ar, int *ag, int *ab);
/**
* @brief
@ -1501,7 +1548,7 @@ EAPI void ephysics_world_light_unset(EPhysics_World *world);
* all the bodies, or @c EINA_FALSE if it only should be applied on bodies with
* light property set.
*
* @see ephysics_world_light_set() for more details.
* @see ephysics_world_point_light_position_set() for more details.
* @see ephysics_world_light_all_bodies_get().
*
* @ingroup EPhysics_World

View File

@ -92,10 +92,10 @@ _ephysics_body_soft_body_slices_apply(void *data __UNUSED__, Evas *e __UNUSED__,
if ((body->light_apply) ||
(ephysics_world_light_all_bodies_get(body->world)))
{
if (ephysics_world_light_get(body->world, &lx, &ly, &lz,
&lr, &lg, &lb, &ar, &ag, &ab))
light = EINA_TRUE;
ephysics_world_point_light_position_get(body->world, &lx, &ly, &lz);
ephysics_world_point_light_color_get(body->world, &lr, &lg, &lb);
ephysics_world_ambient_light_color_get(body->world, &ar, &ag, &ab);
light = EINA_TRUE;
}
if (ephysics_camera_perspective_enabled_get(camera))
@ -1160,9 +1160,10 @@ _ephysics_body_evas_object_default_update(EPhysics_Body *body)
int lr, lg, lb, ar, ag, ab;
Evas_Coord lx, ly, lz;
if (ephysics_world_light_get(body->world, &lx, &ly, &lz,
&lr, &lg, &lb, &ar, &ag, &ab))
evas_map_util_3d_lighting(map, lx, ly, lz, lr, lg, lb, ar, ag, ab);
ephysics_world_point_light_position_get(body->world, &lx, &ly, &lz);
ephysics_world_point_light_color_get(body->world, &lr, &lg, &lb);
ephysics_world_ambient_light_color_get(body->world, &ar, &ag, &ab);
evas_map_util_3d_lighting(map, lx, ly, lz, lr, lg, lb, ar, ag, ab);
}
evas_object_map_set(body->evas_obj, map);

View File

@ -32,21 +32,6 @@ struct _EPhysics_World_Callback {
Eina_Bool deleted:1;
};
typedef struct _EPhysics_Light EPhysics_Light;
struct _EPhysics_Light {
Evas_Coord lx;
Evas_Coord ly;
Evas_Coord lz;
int lr;
int lg;
int lb;
int ar;
int ag;
int ab;
Eina_Bool all_bodies:1;
};
struct _EPhysics_World {
EINA_INLIST;
@ -70,7 +55,6 @@ struct _EPhysics_World {
EPhysics_Body *boundaries[6];
EPhysics_Camera *camera;
EPhysics_Light *light;
Eina_Inlist *callbacks;
Eina_Inlist *bodies;
Eina_List *to_delete;
@ -89,6 +73,19 @@ struct _EPhysics_World {
Eina_Lock mutex;
Eina_Condition condition;
struct {
Evas_Coord lx;
Evas_Coord ly;
Evas_Coord lz;
int lr;
int lg;
int lb;
int ar;
int ag;
int ab;
Eina_Bool all_bodies:1;
} light;
Eina_Bool running:1;
Eina_Bool ticked:1;
Eina_Bool active:1;
@ -381,9 +378,6 @@ _ephysics_world_free(EPhysics_World *world)
eina_condition_free(&world->condition);
eina_lock_free(&world->mutex);
if (world->light)
free(world->light);
free(world);
INF("World %p deleted.", world);
ephysics_dom_count_dec();
@ -756,6 +750,11 @@ ephysics_world_new(void)
world->dynamics_world->getPairCache()->setOverlapFilterCallback(
world->filter_cb);
world->light.lr = 255;
world->light.lg = 255;
world->light.lb = 255;
world->light.lz = -200;
world->stacking = EINA_TRUE;
world->rate = 30;
world->max_sub_steps = 3;
@ -1518,83 +1517,87 @@ ephysics_world_lock_release(EPhysics_World *world)
}
EAPI void
ephysics_world_light_set(EPhysics_World *world,
Evas_Coord lx, Evas_Coord ly, Evas_Coord lz,
int lr, int lg, int lb,
int ar, int ag, int ab)
ephysics_world_point_light_position_set(EPhysics_World *world, Evas_Coord lx, Evas_Coord ly, Evas_Coord lz)
{
if (!world)
{
ERR("No world, can't set light.");
ERR("No world, can't set light properties.");
return;
}
if (!world->light)
world->light = (EPhysics_Light *) calloc(1, sizeof(EPhysics_Light));
if (!world->light)
{
ERR("Failed to create light.");
return;
}
world->light->lx = lx;
world->light->ly = ly;
world->light->lz = lz;
world->light->lr = lr;
world->light->lg = lg;
world->light->lb = lb;
world->light->ar = ar;
world->light->ag = ag;
world->light->ab = ab;
world->light->all_bodies = EINA_FALSE;
}
EAPI Eina_Bool
ephysics_world_light_get(const EPhysics_World *world,
Evas_Coord *lx, Evas_Coord *ly, Evas_Coord *lz,
int *lr, int *lg, int *lb,
int *ar, int *ag, int *ab)
{
if (!world)
{
ERR("No world, can't get light.");
return EINA_FALSE;
}
if (!world->light)
{
INF("Light isn't set.");
return EINA_FALSE;
}
if (lx) *lx = world->light->lx;
if (ly) *ly = world->light->ly;
if (lz) *lz = world->light->lz;
if (lr) *lr = world->light->lr;
if (lg) *lg = world->light->lg;
if (lb) *lb = world->light->lb;
if (ar) *ar = world->light->ar;
if (ag) *ag = world->light->ag;
if (ab) *ab = world->light->ab;
return EINA_TRUE;
world->light.lx = lx;
world->light.ly = ly;
world->light.lz = lz;
}
EAPI void
ephysics_world_light_unset(EPhysics_World *world)
ephysics_world_point_light_color_set(EPhysics_World *world, int lr, int lg, int lb)
{
if (!world)
{
ERR("No world, can't unset light.");
ERR("No world, can't set light properties.");
return;
}
if (!world->light)
return;
world->light.lr = lr;
world->light.lg = lg;
world->light.lb = lb;
}
free(world->light);
world->light = NULL;
EAPI void
ephysics_world_ambient_light_color_set(EPhysics_World *world, int ar, int ag, int ab)
{
if (!world)
{
ERR("No world, can't set light properties.");
return;
}
world->light.ar = ar;
world->light.ag = ag;
world->light.ab = ab;
}
EAPI void
ephysics_world_ambient_light_color_get(const EPhysics_World *world, int *ar, int *ag, int *ab)
{
if (!world)
{
ERR("No world, can't get light properties.");
return;
}
if (ar) *ar = world->light.ar;
if (ag) *ag = world->light.ag;
if (ab) *ab = world->light.ab;
}
EAPI void
ephysics_world_point_light_color_get(const EPhysics_World *world, int *lr, int *lg, int *lb)
{
if (!world)
{
ERR("No world, can't get light properties.");
return;
}
if (lr) *lr = world->light.lr;
if (lg) *lg = world->light.lg;
if (lb) *lb = world->light.lb;
}
EAPI void
ephysics_world_point_light_position_get(const EPhysics_World *world, Evas_Coord *lx, Evas_Coord *ly, Evas_Coord *lz)
{
if (!world)
{
ERR("No world, can't get light properties.");
return;
}
if (lx) *lx = world->light.lx;
if (ly) *ly = world->light.ly;
if (lz) *lz = world->light.lz;
}
EAPI void
@ -1606,13 +1609,7 @@ ephysics_world_light_all_bodies_set(EPhysics_World *world, Eina_Bool enable)
return;
}
if (!world->light)
{
ERR("Light isn't set, can't apply on bodies");
return;
}
world->light->all_bodies = !!enable;
world->light.all_bodies = !!enable;
}
EAPI Eina_Bool
@ -1624,10 +1621,7 @@ ephysics_world_light_all_bodies_get(const EPhysics_World *world)
return EINA_FALSE;
}
if (!world->light)
return EINA_FALSE;
return world->light->all_bodies;
return world->light.all_bodies;
}
EAPI void