summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-10-18 23:27:26 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-10-18 23:27:26 +0000
commit08643f3112c2b1494734aae07a34927275655fac (patch)
treed95c3d627561de8c2c2184b788345a6b84e5aa3c
parent30a0f7c6593e435ac94fe7675ce3ea6ed69bcbae (diff)
ephysics: add perspective support
SVN revision: 78205
-rw-r--r--legacy/ephysics/src/bin/test_bouncing_3d.c1
-rw-r--r--legacy/ephysics/src/lib/EPhysics.h94
-rw-r--r--legacy/ephysics/src/lib/ephysics_body.cpp7
-rw-r--r--legacy/ephysics/src/lib/ephysics_world.cpp72
4 files changed, 174 insertions, 0 deletions
diff --git a/legacy/ephysics/src/bin/test_bouncing_3d.c b/legacy/ephysics/src/bin/test_bouncing_3d.c
index 248f1ec45e..bc1440e91c 100644
--- a/legacy/ephysics/src/bin/test_bouncing_3d.c
+++ b/legacy/ephysics/src/bin/test_bouncing_3d.c
@@ -127,6 +127,7 @@ test_bouncing_3d(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event
127 ephysics_world_gravity_set(world, 0, 0, 0); 127 ephysics_world_gravity_set(world, 0, 0, 0);
128 ephysics_world_render_geometry_set(world, 50, 40, -50, 128 ephysics_world_render_geometry_set(world, 50, 40, -50,
129 WIDTH - 100, FLOOR_Y - 40, DEPTH); 129 WIDTH - 100, FLOOR_Y - 40, DEPTH);
130 ephysics_world_perspective_enabled_set(world, EINA_TRUE);
130 test_data->world = world; 131 test_data->world = world;
131 132
132 boundary = ephysics_body_bottom_boundary_add(test_data->world); 133 boundary = ephysics_body_bottom_boundary_add(test_data->world);
diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h
index f81c3d76e2..fb13874718 100644
--- a/legacy/ephysics/src/lib/EPhysics.h
+++ b/legacy/ephysics/src/lib/EPhysics.h
@@ -1423,6 +1423,100 @@ EAPI void ephysics_world_light_all_bodies_set(EPhysics_World *world, Eina_Bool e
1423EAPI Eina_Bool ephysics_world_light_all_bodies_get(const EPhysics_World *world); 1423EAPI Eina_Bool ephysics_world_light_all_bodies_get(const EPhysics_World *world);
1424 1424
1425/** 1425/**
1426 * @brief
1427 * Set perspective to be applied on the scene.
1428 *
1429 * This applies a given perspective (3D) to the world rendering.
1430 * It will be used when the scene is rendered, after each simulation step,
1431 * by @ref ephysics_body_evas_object_update().
1432 *
1433 * The @p px and @p py points specify the "infinite distance" point in the 3D
1434 * conversion (where all lines converge to like when artists draw 3D by hand).
1435 * The @p z0 value specifies the z value at which there is a 1:1 mapping between
1436 * spatial coordinates and screen coordinates. Any points on this z value will
1437 * not have their X and Y values modified in the transform.
1438 * Those further away (Z value higher) will shrink into the distance, and those
1439 * less than this value will expand and become bigger. The foc value determines
1440 * the "focal length" of the camera. This is in reality the distance between
1441 * the camera lens plane itself (at or closer than this rendering results are
1442 * undefined) and the @p z0 z value. This allows for some "depth" control and
1443 * @p foc must be greater than 0.
1444 *
1445 * Considering the world geometry, by default, perspective is set to
1446 * px = x + w / 2, py = y + h / 2, z0 = z + d / 2 and foc = 10 * (z + d).
1447 * This means the conversion point is centered on render area, and @p z0
1448 * is on the center of render area z axis. It is set when
1449 * @ref ephysics_world_render_geometry_set() is called.
1450 *
1451 * @note The unit used for all parameters is Evas coordinates.
1452 *
1453 * @note To be used, perspective need to be enabled with
1454 * @ref ephysics_world_perspective_enabled_set().
1455 *
1456 * @param world The physics world
1457 * @param px The perspective distance X coordinate
1458 * @param py The perspective distance Y coordinate
1459 * @param z0 The "0" z plane value
1460 * @param foc The focal distance
1461 *
1462 * @see ephysics_world_perspective_get().
1463 * @see ephysics_world_perspective_enabled_set().
1464 *
1465 * @ingroup EPhysics_World
1466 */
1467EAPI void ephysics_world_perspective_set(EPhysics_World *world, Evas_Coord px, Evas_Coord py, Evas_Coord z0, Evas_Coord foc);
1468
1469/**
1470 * @brief
1471 * Get perspective applied on the scene.
1472 *
1473 * @param world The physics world
1474 * @param px The perspective distance X coordinate
1475 * @param py The perspective distance Y coordinate
1476 * @param z0 The "0" z plane value
1477 * @param foc The focal distance
1478 *
1479 * @see ephysics_world_perspective_set() for more details.
1480 * @see ephysics_world_perspective_enabled_get().
1481 *
1482 * @ingroup EPhysics_World
1483 */
1484EAPI void ephysics_world_perspective_get(const EPhysics_World *world, Evas_Coord *px, Evas_Coord *py, Evas_Coord *z0, Evas_Coord *foc);
1485
1486/**
1487 * @brief
1488 * Set if perspective should be applied.
1489 *
1490 * The applied perspective can be set with
1491 * @ref ephysics_world_perspective_set().
1492 *
1493 * @param world The physics world.
1494 * @param enabled @c EINA_TRUE if perspective should be used, or @c EINA_FALSE
1495 * if it shouldn't.
1496 *
1497 * @see ephysics_world_perspective_set() for more details.
1498 * @see ephysics_world_perspective_enabled_get().
1499 *
1500 * @ingroup EPhysics_World
1501 */
1502EAPI void ephysics_world_perspective_enabled_set(EPhysics_World *world, Eina_Bool enabled);
1503
1504/**
1505 * @brief
1506 * Return if perspective is enabled or not.
1507 *
1508 * @param world The physics world.
1509 * @return @c EINA_TRUE if perspective is enabled, or @c EINA_FALSE if it
1510 * isn't, or on error.
1511 *
1512 * @see ephysics_world_perspective_set() for more details.
1513 * @see ephysics_world_perspective_enabled_set().
1514 *
1515 * @ingroup EPhysics_World
1516 */
1517EAPI Eina_Bool ephysics_world_perspective_enabled_get(const EPhysics_World *world);
1518
1519/**
1426 * @} 1520 * @}
1427 */ 1521 */
1428 1522
diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp
index d50558eaf1..88c6034352 100644
--- a/legacy/ephysics/src/lib/ephysics_body.cpp
+++ b/legacy/ephysics/src/lib/ephysics_body.cpp
@@ -1061,6 +1061,13 @@ _ephysics_body_evas_object_default_update(EPhysics_Body *body)
1061 evas_map_util_quat_rotate(map, quat.x(), quat.y(), quat.z(), -quat.w(), 1061 evas_map_util_quat_rotate(map, quat.x(), quat.y(), quat.z(), -quat.w(),
1062 x + (w * body->cm.x), y + (h * body->cm.y), z); 1062 x + (w * body->cm.x), y + (h * body->cm.y), z);
1063 1063
1064 if (ephysics_world_perspective_enabled_get(body->world))
1065 {
1066 int px, py, z0, foc;
1067 ephysics_world_perspective_get(body->world, &px, &py, &z0, &foc);
1068 evas_map_util_3d_perspective(map, px, py, z0, foc);
1069 }
1070
1064 if ((body->light_apply) || 1071 if ((body->light_apply) ||
1065 (ephysics_world_light_all_bodies_get(body->world))) 1072 (ephysics_world_light_all_bodies_get(body->world)))
1066 { 1073 {
diff --git a/legacy/ephysics/src/lib/ephysics_world.cpp b/legacy/ephysics/src/lib/ephysics_world.cpp
index 8c5c77fdce..8b0104fbc2 100644
--- a/legacy/ephysics/src/lib/ephysics_world.cpp
+++ b/legacy/ephysics/src/lib/ephysics_world.cpp
@@ -88,6 +88,15 @@ struct _EPhysics_World {
88 double max_sleeping_time; 88 double max_sleeping_time;
89 Eina_Lock mutex; 89 Eina_Lock mutex;
90 Eina_Condition condition; 90 Eina_Condition condition;
91
92 struct {
93 Evas_Coord px;
94 Evas_Coord py;
95 Evas_Coord z0;
96 Evas_Coord foc;
97 Eina_Bool enabled:1;
98 } perspective;
99
91 Eina_Bool running:1; 100 Eina_Bool running:1;
92 Eina_Bool ticked:1; 101 Eina_Bool ticked:1;
93 Eina_Bool active:1; 102 Eina_Bool active:1;
@@ -1234,6 +1243,9 @@ ephysics_world_render_geometry_set(EPhysics_World *world, Evas_Coord x, Evas_Coo
1234 world->geometry.h = h; 1243 world->geometry.h = h;
1235 world->geometry.d = d; 1244 world->geometry.d = d;
1236 1245
1246 ephysics_world_perspective_set(world, x + w / 2, y + h / 2, z + d / 2,
1247 10 * (z + d));
1248
1237 ephysics_body_world_boundaries_resize(world); 1249 ephysics_body_world_boundaries_resize(world);
1238 ephysics_camera_position_set(world->camera, x, y); 1250 ephysics_camera_position_set(world->camera, x, y);
1239} 1251}
@@ -1623,6 +1635,66 @@ ephysics_world_light_all_bodies_get(const EPhysics_World *world)
1623 return world->light->all_bodies; 1635 return world->light->all_bodies;
1624} 1636}
1625 1637
1638EAPI void
1639ephysics_world_perspective_set(EPhysics_World *world, Evas_Coord px, Evas_Coord py, Evas_Coord z0, Evas_Coord foc)
1640{
1641 if (!world)
1642 {
1643 ERR("No world, can't set perspective.");
1644 return;
1645 }
1646
1647 if (foc <= 0)
1648 {
1649 ERR("Focal distance need to be greater than 0.");
1650 return;
1651 }
1652
1653 world->perspective.px = px;
1654 world->perspective.py = py;
1655 world->perspective.z0 = z0;
1656 world->perspective.foc = foc;
1657}
1658
1659EAPI void
1660ephysics_world_perspective_get(const EPhysics_World *world, Evas_Coord *px, Evas_Coord *py, Evas_Coord *z0, Evas_Coord *foc)
1661{
1662 if (!world)
1663 {
1664 ERR("No world, can't get perspective.");
1665 return;
1666 }
1667
1668 if (px) *px = world->perspective.px;
1669 if (py) *py = world->perspective.py;
1670 if (z0) *z0 = world->perspective.z0;
1671 if (foc) *foc = world->perspective.foc;
1672}
1673
1674EAPI void
1675ephysics_world_perspective_enabled_set(EPhysics_World *world, Eina_Bool enabled)
1676{
1677 if (!world)
1678 {
1679 ERR("No world, can't enable / disable perspective.");
1680 return;
1681 }
1682
1683 world->perspective.enabled = !!enabled;
1684}
1685
1686EAPI Eina_Bool
1687ephysics_world_perspective_enabled_get(const EPhysics_World *world)
1688{
1689 if (!world)
1690 {
1691 ERR("No world, can't get perspective behavior.");
1692 return EINA_FALSE;
1693 }
1694
1695 return world->perspective.enabled;
1696}
1697
1626#ifdef __cplusplus 1698#ifdef __cplusplus
1627} 1699}
1628#endif 1700#endif