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
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;
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);
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);
}
-
/**
* @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.
* @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
+ *
+ * @see ephysics_world_point_light_position_set() for details.
+ *
+ * @ingroup EPhysics_World
+ */
+EAPI void ephysics_world_point_light_position_get(const EPhysics_World *world, Evas_Coord *lx, Evas_Coord *ly, Evas_Coord *lz);
+
+/**
+ * @brief
+ * Get color of point light 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)
- * @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 more details.
+ * @see ephysics_world_point_light_color_set().
*
* @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_color_get(const EPhysics_World *world, int *lr, int *lg, int *lb);
/**
* @brief
- * Unset light on the scene.
+ * Set color of the ambient light to be applied on the scene.
*
- * It will unset light, so no body will be enlightened anymore.
+ * 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_set() for more details.
+ * @see ephysics_world_point_light_position_set() for more details.
+ * @see ephysics_world_ambient_light_color_set().
*
* @ingroup EPhysics_World
*/
-EAPI void ephysics_world_light_unset(EPhysics_World *world);
+EAPI void ephysics_world_ambient_light_color_get(const EPhysics_World *world, int *ar, int *ag, int *ab);
/**
* @brief
* 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
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))
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);
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;
EPhysics_Body *boundaries[6];
EPhysics_Camera *camera;
- EPhysics_Light *light;
Eina_Inlist *callbacks;
Eina_Inlist *bodies;
Eina_List *to_delete;
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;
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();
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;
}
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));
+ world->light.lx = lx;
+ world->light.ly = ly;
+ world->light.lz = lz;
+}
- if (!world->light)
+EAPI void
+ephysics_world_point_light_color_set(EPhysics_World *world, int lr, int lg, int lb)
+{
+ if (!world)
{
- ERR("Failed to create light.");
+ ERR("No world, can't set light properties.");
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;
+ world->light.lr = lr;
+ world->light.lg = lg;
+ world->light.lb = lb;
}
-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_ambient_light_color_set(EPhysics_World *world, int ar, int ag, int ab)
{
if (!world)
{
- ERR("No world, can't get light.");
- return EINA_FALSE;
+ ERR("No world, can't set light properties.");
+ return;
}
- if (!world->light)
+ 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)
{
- INF("Light isn't set.");
- return EINA_FALSE;
+ 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;
- 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;
+ if (ar) *ar = world->light.ar;
+ if (ag) *ag = world->light.ag;
+ if (ab) *ab = world->light.ab;
}
EAPI void
-ephysics_world_light_unset(EPhysics_World *world)
+ephysics_world_point_light_color_get(const EPhysics_World *world, int *lr, int *lg, int *lb)
{
if (!world)
{
- ERR("No world, can't unset light.");
+ ERR("No world, can't get light properties.");
return;
}
- if (!world->light)
- return;
-
- free(world->light);
- world->light = NULL;
+ if (lr) *lr = world->light.lr;
+ if (lg) *lg = world->light.lg;
+ if (lb) *lb = world->light.lb;
}
EAPI void
-ephysics_world_light_all_bodies_set(EPhysics_World *world, Eina_Bool enable)
+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 set light property.");
+ ERR("No world, can't get light properties.");
return;
}
- if (!world->light)
+ if (lx) *lx = world->light.lx;
+ if (ly) *ly = world->light.ly;
+ if (lz) *lz = world->light.lz;
+}
+
+EAPI void
+ephysics_world_light_all_bodies_set(EPhysics_World *world, Eina_Bool enable)
+{
+ if (!world)
{
- ERR("Light isn't set, can't apply on bodies");
+ ERR("No world, can't set light property.");
return;
}
- world->light->all_bodies = !!enable;
+ world->light.all_bodies = !!enable;
}
EAPI Eina_Bool
return EINA_FALSE;
}
- if (!world->light)
- return EINA_FALSE;
-
- return world->light->all_bodies;
+ return world->light.all_bodies;
}
EAPI void