summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-10-18 23:55:45 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-10-18 23:55:45 +0000
commit211d38aac0745164814ea5db5e27e8f071d1a364 (patch)
treee68c970317b7dd9d0f236549ac8710506f34d292
parent08643f3112c2b1494734aae07a34927275655fac (diff)
ephysics: move perspective stuff to camera component
Looks like it fits better the camera component than world. SVN revision: 78206
-rw-r--r--legacy/ephysics/src/bin/test_bouncing_3d.c3
-rw-r--r--legacy/ephysics/src/lib/EPhysics.h188
-rw-r--r--legacy/ephysics/src/lib/ephysics_body.cpp4
-rw-r--r--legacy/ephysics/src/lib/ephysics_camera.cpp67
-rw-r--r--legacy/ephysics/src/lib/ephysics_world.cpp72
5 files changed, 167 insertions, 167 deletions
diff --git a/legacy/ephysics/src/bin/test_bouncing_3d.c b/legacy/ephysics/src/bin/test_bouncing_3d.c
index bc1440e91c..e0d6758e5c 100644
--- a/legacy/ephysics/src/bin/test_bouncing_3d.c
+++ b/legacy/ephysics/src/bin/test_bouncing_3d.c
@@ -127,7 +127,8 @@ 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 ephysics_camera_perspective_enabled_set(ephysics_world_camera_get(world),
131 EINA_TRUE);
131 test_data->world = world; 132 test_data->world = world;
132 133
133 boundary = ephysics_body_bottom_boundary_add(test_data->world); 134 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 fb13874718..072c1be325 100644
--- a/legacy/ephysics/src/lib/EPhysics.h
+++ b/legacy/ephysics/src/lib/EPhysics.h
@@ -429,6 +429,100 @@ EAPI void ephysics_camera_body_track(EPhysics_Camera *camera, EPhysics_Body *bod
429EAPI void ephysics_camera_tracked_body_get(EPhysics_Camera *camera, EPhysics_Body **body, Eina_Bool *horizontal, Eina_Bool *vertical); 429EAPI void ephysics_camera_tracked_body_get(EPhysics_Camera *camera, EPhysics_Body **body, Eina_Bool *horizontal, Eina_Bool *vertical);
430 430
431/** 431/**
432 * @brief
433 * Set perspective to be applied on the scene.
434 *
435 * This applies a given perspective (3D) to the world rendering.
436 * It will be used when the scene is rendered, after each simulation step,
437 * by @ref ephysics_body_evas_object_update().
438 *
439 * The @p px and @p py points specify the "infinite distance" point in the 3D
440 * conversion (where all lines converge to like when artists draw 3D by hand).
441 * The @p z0 value specifies the z value at which there is a 1:1 mapping between
442 * spatial coordinates and screen coordinates. Any points on this z value will
443 * not have their X and Y values modified in the transform.
444 * Those further away (Z value higher) will shrink into the distance, and those
445 * less than this value will expand and become bigger. The foc value determines
446 * the "focal length" of the camera. This is in reality the distance between
447 * the camera lens plane itself (at or closer than this rendering results are
448 * undefined) and the @p z0 z value. This allows for some "depth" control and
449 * @p foc must be greater than 0.
450 *
451 * Considering the world geometry, by default, perspective is set to
452 * px = x + w / 2, py = y + h / 2, z0 = z + d / 2 and foc = 10 * (z + d).
453 * This means the conversion point is centered on render area, and @p z0
454 * is on the center of render area z axis. It is set when
455 * @ref ephysics_world_render_geometry_set() is called.
456 *
457 * @note The unit used for all parameters is Evas coordinates.
458 *
459 * @note To be used, perspective need to be enabled with
460 * @ref ephysics_camera_perspective_enabled_set().
461 *
462 * @param camera The world's camera.
463 * @param px The perspective distance X coordinate
464 * @param py The perspective distance Y coordinate
465 * @param z0 The "0" z plane value
466 * @param foc The focal distance
467 *
468 * @see ephysics_camera_perspective_get().
469 * @see ephysics_camera_perspective_enabled_set().
470 *
471 * @ingroup EPhysics_Camera
472 */
473EAPI void ephysics_camera_perspective_set(EPhysics_Camera *camera, Evas_Coord px, Evas_Coord py, Evas_Coord z0, Evas_Coord foc);
474
475/**
476 * @brief
477 * Get perspective applied on the scene.
478 *
479 * @param camera The world's camera.
480 * @param px The perspective distance X coordinate
481 * @param py The perspective distance Y coordinate
482 * @param z0 The "0" z plane value
483 * @param foc The focal distance
484 *
485 * @see ephysics_camera_perspective_set() for more details.
486 * @see ephysics_camera_perspective_enabled_get().
487 *
488 * @ingroup EPhysics_Camera
489 */
490EAPI void ephysics_camera_perspective_get(const EPhysics_Camera *camera, Evas_Coord *px, Evas_Coord *py, Evas_Coord *z0, Evas_Coord *foc);
491
492/**
493 * @brief
494 * Set if perspective should be applied.
495 *
496 * The applied perspective can be set with
497 * @ref ephysics_camera_perspective_set().
498 *
499 * @param camera The world's camera.
500 * @param enabled @c EINA_TRUE if perspective should be used, or @c EINA_FALSE
501 * if it shouldn't.
502 *
503 * @see ephysics_camera_perspective_set() for more details.
504 * @see ephysics_camera_perspective_enabled_get().
505 *
506 * @ingroup EPhysics_Camera
507 */
508EAPI void ephysics_camera_perspective_enabled_set(EPhysics_Camera *camera, Eina_Bool enabled);
509
510/**
511 * @brief
512 * Return if perspective is enabled or not.
513 *
514 * @param camera The world's camera.
515 * @return @c EINA_TRUE if perspective is enabled, or @c EINA_FALSE if it
516 * isn't, or on error.
517 *
518 * @see ephysics_camera_perspective_set() for more details.
519 * @see ephysics_camera_perspective_enabled_set().
520 *
521 * @ingroup EPhysics_Camera
522 */
523EAPI Eina_Bool ephysics_camera_perspective_enabled_get(const EPhysics_Camera *camera);
524
525/**
432 * @} 526 * @}
433 */ 527 */
434 528
@@ -1423,100 +1517,6 @@ 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); 1517EAPI Eina_Bool ephysics_world_light_all_bodies_get(const EPhysics_World *world);
1424 1518
1425/** 1519/**
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/**
1520 * @} 1520 * @}
1521 */ 1521 */
1522 1522
diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp
index 88c6034352..c775a0dc19 100644
--- a/legacy/ephysics/src/lib/ephysics_body.cpp
+++ b/legacy/ephysics/src/lib/ephysics_body.cpp
@@ -1061,10 +1061,10 @@ _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)) 1064 if (ephysics_camera_perspective_enabled_get(camera))
1065 { 1065 {
1066 int px, py, z0, foc; 1066 int px, py, z0, foc;
1067 ephysics_world_perspective_get(body->world, &px, &py, &z0, &foc); 1067 ephysics_camera_perspective_get(camera, &px, &py, &z0, &foc);
1068 evas_map_util_3d_perspective(map, px, py, z0, foc); 1068 evas_map_util_3d_perspective(map, px, py, z0, foc);
1069 } 1069 }
1070 1070
diff --git a/legacy/ephysics/src/lib/ephysics_camera.cpp b/legacy/ephysics/src/lib/ephysics_camera.cpp
index 9d48c264fb..f315f5d82e 100644
--- a/legacy/ephysics/src/lib/ephysics_camera.cpp
+++ b/legacy/ephysics/src/lib/ephysics_camera.cpp
@@ -14,6 +14,13 @@ struct _EPhysics_Camera {
14 EPhysics_World *world; 14 EPhysics_World *world;
15 EPhysics_Body *target; 15 EPhysics_Body *target;
16 int x, y; 16 int x, y;
17 struct {
18 Evas_Coord px;
19 Evas_Coord py;
20 Evas_Coord z0;
21 Evas_Coord foc;
22 Eina_Bool enabled:1;
23 } perspective;
17 Eina_Bool track_horizontal:1; 24 Eina_Bool track_horizontal:1;
18 Eina_Bool track_vertical:1; 25 Eina_Bool track_vertical:1;
19 Eina_Bool moved:1; 26 Eina_Bool moved:1;
@@ -202,6 +209,66 @@ ephysics_camera_tracked_body_get(EPhysics_Camera *camera, EPhysics_Body **body,
202 if (vertical) *vertical = camera->track_vertical; 209 if (vertical) *vertical = camera->track_vertical;
203} 210}
204 211
212EAPI void
213ephysics_camera_perspective_set(EPhysics_Camera *camera, Evas_Coord px, Evas_Coord py, Evas_Coord z0, Evas_Coord foc)
214{
215 if (!camera)
216 {
217 ERR("No camera, can't set perspective.");
218 return;
219 }
220
221 if (foc <= 0)
222 {
223 ERR("Focal distance need to be greater than 0.");
224 return;
225 }
226
227 camera->perspective.px = px;
228 camera->perspective.py = py;
229 camera->perspective.z0 = z0;
230 camera->perspective.foc = foc;
231}
232
233EAPI void
234ephysics_camera_perspective_get(const EPhysics_Camera *camera, Evas_Coord *px, Evas_Coord *py, Evas_Coord *z0, Evas_Coord *foc)
235{
236 if (!camera)
237 {
238 ERR("No camera, can't get perspective.");
239 return;
240 }
241
242 if (px) *px = camera->perspective.px;
243 if (py) *py = camera->perspective.py;
244 if (z0) *z0 = camera->perspective.z0;
245 if (foc) *foc = camera->perspective.foc;
246}
247
248EAPI void
249ephysics_camera_perspective_enabled_set(EPhysics_Camera *camera, Eina_Bool enabled)
250{
251 if (!camera)
252 {
253 ERR("No camera, can't enable / disable perspective.");
254 return;
255 }
256
257 camera->perspective.enabled = !!enabled;
258}
259
260EAPI Eina_Bool
261ephysics_camera_perspective_enabled_get(const EPhysics_Camera *camera)
262{
263 if (!camera)
264 {
265 ERR("No camera, can't get perspective behavior.");
266 return EINA_FALSE;
267 }
268
269 return camera->perspective.enabled;
270}
271
205#ifdef __cplusplus 272#ifdef __cplusplus
206} 273}
207#endif 274#endif
diff --git a/legacy/ephysics/src/lib/ephysics_world.cpp b/legacy/ephysics/src/lib/ephysics_world.cpp
index 8b0104fbc2..8900f69cb3 100644
--- a/legacy/ephysics/src/lib/ephysics_world.cpp
+++ b/legacy/ephysics/src/lib/ephysics_world.cpp
@@ -89,14 +89,6 @@ struct _EPhysics_World {
89 Eina_Lock mutex; 89 Eina_Lock mutex;
90 Eina_Condition condition; 90 Eina_Condition condition;
91 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
100 Eina_Bool running:1; 92 Eina_Bool running:1;
101 Eina_Bool ticked:1; 93 Eina_Bool ticked:1;
102 Eina_Bool active:1; 94 Eina_Bool active:1;
@@ -1243,8 +1235,8 @@ ephysics_world_render_geometry_set(EPhysics_World *world, Evas_Coord x, Evas_Coo
1243 world->geometry.h = h; 1235 world->geometry.h = h;
1244 world->geometry.d = d; 1236 world->geometry.d = d;
1245 1237
1246 ephysics_world_perspective_set(world, x + w / 2, y + h / 2, z + d / 2, 1238 ephysics_camera_perspective_set(world->camera, x + w / 2, y + h / 2,
1247 10 * (z + d)); 1239 z + d / 2, 10 * (z + d));
1248 1240
1249 ephysics_body_world_boundaries_resize(world); 1241 ephysics_body_world_boundaries_resize(world);
1250 ephysics_camera_position_set(world->camera, x, y); 1242 ephysics_camera_position_set(world->camera, x, y);
@@ -1635,66 +1627,6 @@ ephysics_world_light_all_bodies_get(const EPhysics_World *world)
1635 return world->light->all_bodies; 1627 return world->light->all_bodies;
1636} 1628}
1637 1629
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
1698#ifdef __cplusplus 1630#ifdef __cplusplus
1699} 1631}
1700#endif 1632#endif