summaryrefslogtreecommitdiff
path: root/legacy/ephysics
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-10-10 20:32:08 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-10-10 20:32:08 +0000
commitc9700902546d31e9a7e6d98d416c922b6f61b27d (patch)
tree2f1c03a0b7eb1726aa1f64ab5cc29ee43f94fc69 /legacy/ephysics
parent3acb5dde8b745950a055446486a5cbac02b792ec (diff)
ephysics: lights, camera, action!
Add light support. It uses evas_map_util_3d_lighting() internally and is only applied over selected bodies. SVN revision: 77803
Diffstat (limited to 'legacy/ephysics')
-rw-r--r--legacy/ephysics/src/lib/EPhysics.h158
-rw-r--r--legacy/ephysics/src/lib/ephysics_body.cpp37
-rw-r--r--legacy/ephysics/src/lib/ephysics_private.h5
-rw-r--r--legacy/ephysics/src/lib/ephysics_world.cpp135
4 files changed, 332 insertions, 3 deletions
diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h
index 1603fd5fdf..dc10eb38af 100644
--- a/legacy/ephysics/src/lib/EPhysics.h
+++ b/legacy/ephysics/src/lib/EPhysics.h
@@ -1227,6 +1227,118 @@ EAPI void ephysics_world_simulation_set(EPhysics_World *world, double fixed_time
1227EAPI void ephysics_world_simulation_get(const EPhysics_World *world, double *fixed_time_step, int *max_sub_steps); 1227EAPI void ephysics_world_simulation_get(const EPhysics_World *world, double *fixed_time_step, int *max_sub_steps);
1228 1228
1229/** 1229/**
1230 * @brief
1231 * Set light properties to be applied on the scene.
1232 *
1233 * It will perform lighting calculations on the evas map applied on evas
1234 * objects associated with all the bodies to have light applied over.
1235 *
1236 * This is used to apply lighting calculations (from a single light source)
1237 * to a given object. The R, G and B values of each vertex will be modified to
1238 * reflect the lighting based on the lixth point coordinates, the light color
1239 * and the ambient color, and at what angle the map is facing the light source.
1240 * A surface should have its points be declared in a clockwise fashion if the
1241 * face is "facing" towards you (as opposed to away from you) as faces have a
1242 * "logical" side for lighting.
1243 *
1244 * More details can be found on evas_map_util_3d_lighting() documentation,
1245 * since this function is used internally by EPhysics.
1246 *
1247 * There are two ways of setting a body to receive lighting. One is to simple
1248 * set all the bodies to be affected, with
1249 * @ref ephysics_world_light_all_bodies_set(). The other, is to set each body
1250 * individually, with @ref ephysics_body_light_set().
1251 *
1252 * By default, no light is set. And after a light is set, by default,
1253 * no body will be affected. No change will be visible until
1254 * some bodies are set to be enlightened.
1255 *
1256 * @param world The physics world.
1257 * @param lx X coordinate in space of light point
1258 * @param ly Y coordinate in space of light point
1259 * @param lz Z coordinate in space of light point
1260 * @param lr light red value (0 - 255)
1261 * @param lg light green value (0 - 255)
1262 * @param lb light blue value (0 - 255)
1263 * @param ar ambient color red value (0 - 255)
1264 * @param ag ambient color green value (0 - 255)
1265 * @param ab ambient color blue value (0 - 255)
1266 *
1267 * @see ephysics_world_light_get().
1268 *
1269 * @ingroup EPhysics_World
1270 */
1271EAPI 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);
1272
1273/**
1274 * @brief
1275 * Get light properties.
1276 *
1277 * @param world The physics world.
1278 * @param lx X coordinate in space of light point
1279 * @param ly Y coordinate in space of light point
1280 * @param lz Z coordinate in space of light point
1281 * @param lr light red value (0 - 255)
1282 * @param lg light green value (0 - 255)
1283 * @param lb light blue value (0 - 255)
1284 * @param ar ambient color red value (0 - 255)
1285 * @param ag ambient color green value (0 - 255)
1286 * @param ab ambient color blue value (0 - 255)
1287 * @return @c EINA_TRUE if light is set, or @c EINA_FALSE if it isn't set,
1288 * or on error. On this case the other parameters won't be set.
1289 *
1290 * @see ephysics_world_light_set() for more details.
1291 *
1292 * @ingroup EPhysics_World
1293 */
1294EAPI 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);
1295
1296/**
1297 * @brief
1298 * Unset light on the scene.
1299 *
1300 * It will unset light, so no body will be enlightened anymore.
1301 *
1302 * @param world The physics world.
1303 *
1304 * @see ephysics_world_light_set() for more details.
1305 *
1306 * @ingroup EPhysics_World
1307 */
1308EAPI void ephysics_world_light_unset(EPhysics_World *world);
1309
1310/**
1311 * @brief
1312 * Set if light should be applied over all the bodies.
1313 *
1314 * @param world The physics world.
1315 * @param enable @c EINA_TRUE if light should be obligatory applied over
1316 * all the bodies, or @c EINA_FALSE if it only should be applied on bodies with
1317 * light property set.
1318 *
1319 * @see ephysics_world_light_set() for more details.
1320 * @see ephysics_world_light_all_bodies_get().
1321 *
1322 * @ingroup EPhysics_World
1323 */
1324EAPI void ephysics_world_light_all_bodies_set(EPhysics_World *world, Eina_Bool enable);
1325
1326/**
1327 * @brief
1328 * Get light setting regarding being applied over all the bodies.
1329 *
1330 * @param world The physics world.
1331 * @return @c EINA_TRUE if light will be obligatory applied over all the bodies,
1332 * or @c EINA_FALSE if it only will be applied on bodies with light property
1333 * set, or on error.
1334 *
1335 * @see ephysics_world_light_all_bodies_set() for details.
1336 *
1337 * @ingroup EPhysics_World
1338 */
1339EAPI Eina_Bool ephysics_world_light_all_bodies_get(const EPhysics_World *world);
1340
1341/**
1230 * @} 1342 * @}
1231 */ 1343 */
1232 1344
@@ -3159,13 +3271,57 @@ EAPI void ephysics_body_material_set(EPhysics_Body *body, EPhysics_Body_Material
3159 * @param body The physics body. 3271 * @param body The physics body.
3160 * @return the @p material used by the body. 3272 * @return the @p material used by the body.
3161 * 3273 *
3162 * @see ephysics_body_body_set() for more details. 3274 * @see ephysics_body_material_set() for more details.
3163 * 3275 *
3164 * @ingroup EPhysics_Body 3276 * @ingroup EPhysics_Body
3165 */ 3277 */
3166EAPI EPhysics_Body_Material ephysics_body_material_get(const EPhysics_Body *body); 3278EAPI EPhysics_Body_Material ephysics_body_material_get(const EPhysics_Body *body);
3167 3279
3168/** 3280/**
3281 * @brief
3282 * Set light effect over body.
3283 *
3284 * @param body The physics body.
3285 * @param enable If @c EINA_TRUE, light will be applied over this @p body,
3286 * otherwise it won't.
3287 *
3288 * It's possible to set the light to apply over all the bodies with
3289 * @ref ephysics_world_light_all_bodies_set(). This will have priority
3290 * over body's individual light settings.
3291 *
3292 * So, if @p body is set to doesn't be affect by the light, but light
3293 * is set to be applied over all the bodies, @p body will be displayed
3294 * with light over it.
3295 *
3296 * Also, if no light is set on the world with @ref ephysics_world_light_set(),
3297 * nothing will happens.
3298 *
3299 * @see ephysics_body_light_get().
3300 * @see ephysics_world_light_set() for more details regarding lighting.
3301 *
3302 * @ingroup EPhysics_Body
3303 */
3304EAPI void ephysics_body_light_set(EPhysics_Body *body, Eina_Bool enable);
3305
3306/**
3307 * @brief
3308 * Get light effect over body.
3309 *
3310 * @param body The physics body.
3311 * @return @c EINA_TRUE if light is applied over this @p body or @c EINA_FALSE
3312 * in the other case, or on error.
3313 *
3314 * @note If light is applied over all the bodies it may return @c EINA_FALSE
3315 * even if it's being affect by lights. This need to be checked with
3316 * @ref ephysics_world_light_all_bodies_get().
3317 *
3318 * @see ephysics_body_light_set() for more details.
3319 *
3320 * @ingroup EPhysics_Body
3321 */
3322EAPI Eina_Bool ephysics_body_light_get(const EPhysics_Body *body);
3323
3324/**
3169 * @} 3325 * @}
3170 */ 3326 */
3171 3327
diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp
index b48bb435f3..44d3e42b8d 100644
--- a/legacy/ephysics/src/lib/ephysics_body.cpp
+++ b/legacy/ephysics/src/lib/ephysics_body.cpp
@@ -1045,6 +1045,18 @@ _ephysics_body_evas_object_default_update(EPhysics_Body *body)
1045 1045
1046 evas_map_util_rotate(map, rot, x + (w * body->cm.x), y + 1046 evas_map_util_rotate(map, rot, x + (w * body->cm.x), y +
1047 (h * body->cm.y)); 1047 (h * body->cm.y));
1048
1049 if ((body->light_apply) ||
1050 (ephysics_world_light_all_bodies_get(body->world)))
1051 {
1052 int lr, lg, lb, ar, ag, ab;
1053 Evas_Coord lx, ly, lz;
1054
1055 if (ephysics_world_light_get(body->world, &lx, &ly, &lz,
1056 &lr, &lg, &lb, &ar, &ag, &ab))
1057 evas_map_util_3d_lighting(map, lx, ly, lz, lr, lg, lb, ar, ag, ab);
1058 }
1059
1048 evas_object_map_set(body->evas_obj, map); 1060 evas_object_map_set(body->evas_obj, map);
1049 evas_object_map_enable_set(body->evas_obj, EINA_TRUE); 1061 evas_object_map_enable_set(body->evas_obj, EINA_TRUE);
1050 evas_map_free(map); 1062 evas_map_free(map);
@@ -2816,6 +2828,31 @@ ephysics_body_material_get(const EPhysics_Body *body)
2816 return body->material; 2828 return body->material;
2817} 2829}
2818 2830
2831EAPI void
2832ephysics_body_light_set(EPhysics_Body *body, Eina_Bool enable)
2833{
2834 if (!body)
2835 {
2836 ERR("No body, no light.");
2837 return;
2838 }
2839
2840 body->light_apply = !!enable;
2841}
2842
2843EAPI Eina_Bool
2844ephysics_body_light_get(const EPhysics_Body *body)
2845{
2846 if (!body)
2847 {
2848 ERR("No body, no light.");
2849 return EINA_FALSE;
2850 }
2851
2852 return body->light_apply;
2853}
2854
2855
2819#ifdef __cplusplus 2856#ifdef __cplusplus
2820} 2857}
2821#endif 2858#endif
diff --git a/legacy/ephysics/src/lib/ephysics_private.h b/legacy/ephysics/src/lib/ephysics_private.h
index 56dcb6e845..b9f8b7d22a 100644
--- a/legacy/ephysics/src/lib/ephysics_private.h
+++ b/legacy/ephysics/src/lib/ephysics_private.h
@@ -104,14 +104,15 @@ struct _EPhysics_Body {
104 double y; 104 double y;
105 double z; 105 double z;
106 } cm; 106 } cm;
107 Eina_Bool active:1;
108 Eina_Bool deleted:1;
109 int slices; 107 int slices;
110 int *points_deform; 108 int *points_deform;
111 EPhysics_Body_Type type; 109 EPhysics_Body_Type type;
112 int cloth_columns; 110 int cloth_columns;
113 int cloth_rows; 111 int cloth_rows;
114 int anchor_prop; 112 int anchor_prop;
113 Eina_Bool active:1;
114 Eina_Bool deleted:1;
115 Eina_Bool light_apply:1;
115}; 116};
116 117
117extern int _ephysics_log_dom; 118extern int _ephysics_log_dom;
diff --git a/legacy/ephysics/src/lib/ephysics_world.cpp b/legacy/ephysics/src/lib/ephysics_world.cpp
index 937478664f..d90d597b69 100644
--- a/legacy/ephysics/src/lib/ephysics_world.cpp
+++ b/legacy/ephysics/src/lib/ephysics_world.cpp
@@ -32,6 +32,21 @@ struct _EPhysics_World_Callback {
32 Eina_Bool deleted:1; 32 Eina_Bool deleted:1;
33}; 33};
34 34
35typedef struct _EPhysics_Light EPhysics_Light;
36
37struct _EPhysics_Light {
38 Evas_Coord lx;
39 Evas_Coord ly;
40 Evas_Coord lz;
41 int lr;
42 int lg;
43 int lb;
44 int ar;
45 int ag;
46 int ab;
47 Eina_Bool all_bodies:1;
48};
49
35struct _EPhysics_World { 50struct _EPhysics_World {
36 EINA_INLIST; 51 EINA_INLIST;
37 btBroadphaseInterface* broadphase; 52 btBroadphaseInterface* broadphase;
@@ -45,6 +60,7 @@ struct _EPhysics_World {
45 60
46 EPhysics_Body *boundaries[4]; 61 EPhysics_Body *boundaries[4];
47 EPhysics_Camera *camera; 62 EPhysics_Camera *camera;
63 EPhysics_Light *light;
48 Evas_Coord x, y, w, h; 64 Evas_Coord x, y, w, h;
49 Eina_Inlist *callbacks; 65 Eina_Inlist *callbacks;
50 Eina_Inlist *bodies; 66 Eina_Inlist *bodies;
@@ -349,6 +365,9 @@ _ephysics_world_free(EPhysics_World *world)
349 eina_condition_free(&world->condition); 365 eina_condition_free(&world->condition);
350 eina_lock_free(&world->mutex); 366 eina_lock_free(&world->mutex);
351 367
368 if (world->light)
369 free(world->light);
370
352 free(world); 371 free(world);
353 INF("World %p deleted.", world); 372 INF("World %p deleted.", world);
354 ephysics_dom_count_dec(); 373 ephysics_dom_count_dec();
@@ -1412,6 +1431,122 @@ ephysics_world_lock_release(EPhysics_World *world)
1412 eina_lock_release(&world->mutex); 1431 eina_lock_release(&world->mutex);
1413} 1432}
1414 1433
1434EAPI void
1435ephysics_world_light_set(EPhysics_World *world,
1436 Evas_Coord lx, Evas_Coord ly, Evas_Coord lz,
1437 int lr, int lg, int lb,
1438 int ar, int ag, int ab)
1439{
1440 if (!world)
1441 {
1442 ERR("No world, can't set light.");
1443 return;
1444 }
1445
1446 if (!world->light)
1447 world->light = (EPhysics_Light *) calloc(1, sizeof(EPhysics_Light));
1448
1449 if (!world->light)
1450 {
1451 ERR("Failed to create light.");
1452 return;
1453 }
1454
1455 world->light->lx = lx;
1456 world->light->ly = ly;
1457 world->light->lz = lz;
1458 world->light->lr = lr;
1459 world->light->lg = lg;
1460 world->light->lb = lb;
1461 world->light->ar = ar;
1462 world->light->ag = ag;
1463 world->light->ab = ab;
1464 world->light->all_bodies = EINA_FALSE;
1465}
1466
1467EAPI Eina_Bool
1468ephysics_world_light_get(const EPhysics_World *world,
1469 Evas_Coord *lx, Evas_Coord *ly, Evas_Coord *lz,
1470 int *lr, int *lg, int *lb,
1471 int *ar, int *ag, int *ab)
1472{
1473 if (!world)
1474 {
1475 ERR("No world, can't get light.");
1476 return EINA_FALSE;
1477 }
1478
1479 if (!world->light)
1480 {
1481 INF("Light isn't set.");
1482 return EINA_FALSE;
1483 }
1484
1485 if (lx) *lx = world->light->lx;
1486 if (ly) *ly = world->light->ly;
1487 if (lz) *lz = world->light->lz;
1488 if (lr) *lr = world->light->lr;
1489 if (lg) *lg = world->light->lg;
1490 if (lb) *lb = world->light->lb;
1491 if (ar) *ar = world->light->ar;
1492 if (ag) *ag = world->light->ag;
1493 if (ab) *ab = world->light->ab;
1494
1495 return EINA_TRUE;
1496}
1497
1498EAPI void
1499ephysics_world_light_unset(EPhysics_World *world)
1500{
1501 if (!world)
1502 {
1503 ERR("No world, can't unset light.");
1504 return;
1505 }
1506
1507 if (!world->light)
1508 return;
1509
1510 free(world->light);
1511 world->light = NULL;
1512}
1513
1514EAPI void
1515ephysics_world_light_all_bodies_set(EPhysics_World *world, Eina_Bool enable)
1516{
1517 if (!world)
1518 {
1519 ERR("No world, can't set light property.");
1520 return;
1521 }
1522
1523 if (!world->light)
1524 {
1525 ERR("Light isn't set, can't apply on bodies");
1526 return;
1527 }
1528
1529 world->light->all_bodies = !!enable;
1530}
1531
1532EAPI Eina_Bool
1533ephysics_world_light_all_bodies_get(const EPhysics_World *world)
1534{
1535 if (!world)
1536 {
1537 ERR("No world, can't get light property.");
1538 return EINA_FALSE;
1539 }
1540
1541 if (!world->light)
1542 {
1543 INF("Light isn't set, can't get light property");
1544 return EINA_FALSE;
1545 }
1546
1547 return world->light->all_bodies;
1548}
1549
1415#ifdef __cplusplus 1550#ifdef __cplusplus
1416} 1551}
1417#endif 1552#endif