From 22cc05a9fe0df94a83f6cee175617e93632347e4 Mon Sep 17 00:00:00 2001 From: Bruno Dilly Date: Fri, 19 Oct 2012 18:50:46 +0000 Subject: [PATCH] ephysics: support back-face culling SVN revision: 78265 --- legacy/ephysics/src/lib/EPhysics.h | 62 ++++++++++++++++++++++ legacy/ephysics/src/lib/ephysics_body.cpp | 51 +++++++++++++++++- legacy/ephysics/src/lib/ephysics_private.h | 11 ++-- 3 files changed, 118 insertions(+), 6 deletions(-) diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h index 072c1be325..2c40b7707b 100644 --- a/legacy/ephysics/src/lib/EPhysics.h +++ b/legacy/ephysics/src/lib/EPhysics.h @@ -3641,6 +3641,68 @@ EAPI void ephysics_body_light_set(EPhysics_Body *body, Eina_Bool enable); */ EAPI Eina_Bool ephysics_body_light_get(const EPhysics_Body *body); +/** + * @brief + * Set body's evas object to be hidden when it is counter-clockwise. + * + * @param body The physics body. + * @param enable If @c EINA_TRUE, evas object will be hidden, + * otherwise it will be visible, rotated. + * + * An object is said to be facing the user when all its points are placed in + * a clockwise fashion. + * + * @note When back-face culling is enabled, evas object visibility + * will be handled by @ref ephysics_body_evas_object_update(). + * + * @see ephysics_body_back_face_culling_get(). + * @see ephysics_body_clockwise_get(). + * @see ephysics_body_evas_object_set(). + * + * @ingroup EPhysics_Body + */ +EAPI void ephysics_body_back_face_culling_set(EPhysics_Body *body, Eina_Bool enable); + +/** + * @brief + * Return if body's evas object will be hidden when it is counter-clockwise or + * not. + * + * @param body The physics body. + * @return @c EINA_TRUE if evas object will be hidden, or @c EINA_FALSE + * in the other case, or on error. + * + * @see ephysics_body_back_face_culling_set() for more details. + * @see ephysics_body_clockwise_get(). + * + * @ingroup EPhysics_Body + */ +EAPI Eina_Bool ephysics_body_back_face_culling_get(const EPhysics_Body *body); + +/** + * @brief + * Get the clockwise state of a body. + * + * This determines if the points of the evas object associated to the @p body + * are clockwise or counter-clockwise. This can be used for "back-face culling". * This is where you hide objects that "face away" from you. + * In this case objects that are not clockwise. + * + * It can be set with @ref ephysics_body_back_face_culling_set(), so EPhysics + * will handle visibility automatically on evas object update. + * + * @note This information only will be updated on + * ephysics_body_evas_object_update(). So if a custom rendering is being done, + * this function won't return the current value of the evas object. + * + * @param body The physics body. + * @return @c EINA_TRUE if clockwise, @c EINA_FALSE otherwise or on error. + * + * @see ephysics_body_back_face_culling_set() for more details. + * + * @ingroup EPhysics_Body + */ +EAPI Eina_Bool ephysics_body_clockwise_get(const EPhysics_Body *body); + /** * @} */ diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp index c775a0dc19..574e37166f 100644 --- a/legacy/ephysics/src/lib/ephysics_body.cpp +++ b/legacy/ephysics/src/lib/ephysics_body.cpp @@ -1068,6 +1068,22 @@ _ephysics_body_evas_object_default_update(EPhysics_Body *body) evas_map_util_3d_perspective(map, px, py, z0, foc); } + if (body->back_face_culling) + { + if (evas_map_util_clockwise_get(map)) + { + body->clockwise = EINA_TRUE; + evas_object_show(body->evas_obj); + } + else + { + body->clockwise = EINA_FALSE; + evas_map_free(map); + evas_object_hide(body->evas_obj); + return; + } + } + if ((body->light_apply) || (ephysics_world_light_all_bodies_get(body->world))) { @@ -2173,8 +2189,6 @@ ephysics_body_evas_object_set(EPhysics_Body *body, Evas_Object *evas_obj, Eina_B } body->evas_obj = evas_obj; - - evas_object_event_callback_add(evas_obj, EVAS_CALLBACK_DEL, _ephysics_body_evas_obj_del_cb, body); @@ -3160,6 +3174,39 @@ ephysics_body_volume_get(const EPhysics_Body *body) return _ephysics_body_volume_get(body); } +EAPI void +ephysics_body_back_face_culling_set(EPhysics_Body *body, Eina_Bool enable) +{ + if (!body) + { + ERR("Body is NULL."); + return; + } + body->back_face_culling = !!enable; +} + +EAPI Eina_Bool +ephysics_body_back_face_culling_get(const EPhysics_Body *body) +{ + if (!body) + { + ERR("Body is NULL."); + return EINA_FALSE; + } + return body->back_face_culling; +} + +EAPI Eina_Bool +ephysics_body_clockwise_get(const EPhysics_Body *body) +{ + if (!body) + { + ERR("Body is NULL."); + return EINA_FALSE; + } + return body->clockwise; +} + #ifdef __cplusplus } #endif diff --git a/legacy/ephysics/src/lib/ephysics_private.h b/legacy/ephysics/src/lib/ephysics_private.h index 8cf6994354..1a0ba3e647 100644 --- a/legacy/ephysics/src/lib/ephysics_private.h +++ b/legacy/ephysics/src/lib/ephysics_private.h @@ -112,16 +112,19 @@ struct _EPhysics_Body { int cloth_columns; int cloth_rows; int anchor_prop; - Eina_Bool active:1; - Eina_Bool deleted:1; - Eina_Bool light_apply:1; int material_index; - Eina_Bool rebounding; struct { int triangle; double mass[3]; Eina_Bool dragging; } dragging_data; + + Eina_Bool active:1; + Eina_Bool deleted:1; + Eina_Bool light_apply:1; + Eina_Bool rebounding:1; + Eina_Bool back_face_culling:1; + Eina_Bool clockwise:1; }; extern int _ephysics_log_dom;