summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-10-19 18:50:46 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-10-19 18:50:46 +0000
commit22cc05a9fe0df94a83f6cee175617e93632347e4 (patch)
treec6cb06dfa5069420a9e360980d64044849a7c7b0 /legacy
parente46c4e83d5d9bf121400b0e64877173371a9d26d (diff)
ephysics: support back-face culling
SVN revision: 78265
Diffstat (limited to 'legacy')
-rw-r--r--legacy/ephysics/src/lib/EPhysics.h62
-rw-r--r--legacy/ephysics/src/lib/ephysics_body.cpp51
-rw-r--r--legacy/ephysics/src/lib/ephysics_private.h11
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
@@ -3642,6 +3642,68 @@ EAPI void ephysics_body_light_set(EPhysics_Body *body, Eina_Bool enable);
3642EAPI Eina_Bool ephysics_body_light_get(const EPhysics_Body *body); 3642EAPI Eina_Bool ephysics_body_light_get(const EPhysics_Body *body);
3643 3643
3644/** 3644/**
3645 * @brief
3646 * Set body's evas object to be hidden when it is counter-clockwise.
3647 *
3648 * @param body The physics body.
3649 * @param enable If @c EINA_TRUE, evas object will be hidden,
3650 * otherwise it will be visible, rotated.
3651 *
3652 * An object is said to be facing the user when all its points are placed in
3653 * a clockwise fashion.
3654 *
3655 * @note When back-face culling is enabled, evas object visibility
3656 * will be handled by @ref ephysics_body_evas_object_update().
3657 *
3658 * @see ephysics_body_back_face_culling_get().
3659 * @see ephysics_body_clockwise_get().
3660 * @see ephysics_body_evas_object_set().
3661 *
3662 * @ingroup EPhysics_Body
3663 */
3664EAPI void ephysics_body_back_face_culling_set(EPhysics_Body *body, Eina_Bool enable);
3665
3666/**
3667 * @brief
3668 * Return if body's evas object will be hidden when it is counter-clockwise or
3669 * not.
3670 *
3671 * @param body The physics body.
3672 * @return @c EINA_TRUE if evas object will be hidden, or @c EINA_FALSE
3673 * in the other case, or on error.
3674 *
3675 * @see ephysics_body_back_face_culling_set() for more details.
3676 * @see ephysics_body_clockwise_get().
3677 *
3678 * @ingroup EPhysics_Body
3679 */
3680EAPI Eina_Bool ephysics_body_back_face_culling_get(const EPhysics_Body *body);
3681
3682/**
3683 * @brief
3684 * Get the clockwise state of a body.
3685 *
3686 * This determines if the points of the evas object associated to the @p body
3687 * are clockwise or counter-clockwise. This can be used for "back-face culling". * This is where you hide objects that "face away" from you.
3688 * In this case objects that are not clockwise.
3689 *
3690 * It can be set with @ref ephysics_body_back_face_culling_set(), so EPhysics
3691 * will handle visibility automatically on evas object update.
3692 *
3693 * @note This information only will be updated on
3694 * ephysics_body_evas_object_update(). So if a custom rendering is being done,
3695 * this function won't return the current value of the evas object.
3696 *
3697 * @param body The physics body.
3698 * @return @c EINA_TRUE if clockwise, @c EINA_FALSE otherwise or on error.
3699 *
3700 * @see ephysics_body_back_face_culling_set() for more details.
3701 *
3702 * @ingroup EPhysics_Body
3703 */
3704EAPI Eina_Bool ephysics_body_clockwise_get(const EPhysics_Body *body);
3705
3706/**
3645 * @} 3707 * @}
3646 */ 3708 */
3647 3709
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)
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
1071 if (body->back_face_culling)
1072 {
1073 if (evas_map_util_clockwise_get(map))
1074 {
1075 body->clockwise = EINA_TRUE;
1076 evas_object_show(body->evas_obj);
1077 }
1078 else
1079 {
1080 body->clockwise = EINA_FALSE;
1081 evas_map_free(map);
1082 evas_object_hide(body->evas_obj);
1083 return;
1084 }
1085 }
1086
1071 if ((body->light_apply) || 1087 if ((body->light_apply) ||
1072 (ephysics_world_light_all_bodies_get(body->world))) 1088 (ephysics_world_light_all_bodies_get(body->world)))
1073 { 1089 {
@@ -2173,8 +2189,6 @@ ephysics_body_evas_object_set(EPhysics_Body *body, Evas_Object *evas_obj, Eina_B
2173 } 2189 }
2174 2190
2175 body->evas_obj = evas_obj; 2191 body->evas_obj = evas_obj;
2176
2177
2178 evas_object_event_callback_add(evas_obj, EVAS_CALLBACK_DEL, 2192 evas_object_event_callback_add(evas_obj, EVAS_CALLBACK_DEL,
2179 _ephysics_body_evas_obj_del_cb, body); 2193 _ephysics_body_evas_obj_del_cb, body);
2180 2194
@@ -3160,6 +3174,39 @@ ephysics_body_volume_get(const EPhysics_Body *body)
3160 return _ephysics_body_volume_get(body); 3174 return _ephysics_body_volume_get(body);
3161} 3175}
3162 3176
3177EAPI void
3178ephysics_body_back_face_culling_set(EPhysics_Body *body, Eina_Bool enable)
3179{
3180 if (!body)
3181 {
3182 ERR("Body is NULL.");
3183 return;
3184 }
3185 body->back_face_culling = !!enable;
3186}
3187
3188EAPI Eina_Bool
3189ephysics_body_back_face_culling_get(const EPhysics_Body *body)
3190{
3191 if (!body)
3192 {
3193 ERR("Body is NULL.");
3194 return EINA_FALSE;
3195 }
3196 return body->back_face_culling;
3197}
3198
3199EAPI Eina_Bool
3200ephysics_body_clockwise_get(const EPhysics_Body *body)
3201{
3202 if (!body)
3203 {
3204 ERR("Body is NULL.");
3205 return EINA_FALSE;
3206 }
3207 return body->clockwise;
3208}
3209
3163#ifdef __cplusplus 3210#ifdef __cplusplus
3164} 3211}
3165#endif 3212#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 {
112 int cloth_columns; 112 int cloth_columns;
113 int cloth_rows; 113 int cloth_rows;
114 int anchor_prop; 114 int anchor_prop;
115 Eina_Bool active:1;
116 Eina_Bool deleted:1;
117 Eina_Bool light_apply:1;
118 int material_index; 115 int material_index;
119 Eina_Bool rebounding;
120 struct { 116 struct {
121 int triangle; 117 int triangle;
122 double mass[3]; 118 double mass[3];
123 Eina_Bool dragging; 119 Eina_Bool dragging;
124 } dragging_data; 120 } dragging_data;
121
122 Eina_Bool active:1;
123 Eina_Bool deleted:1;
124 Eina_Bool light_apply:1;
125 Eina_Bool rebounding:1;
126 Eina_Bool back_face_culling:1;
127 Eina_Bool clockwise:1;
125}; 128};
126 129
127extern int _ephysics_log_dom; 130extern int _ephysics_log_dom;