ephysics: support back-face culling

SVN revision: 78265
This commit is contained in:
Bruno Dilly 2012-10-19 18:50:46 +00:00
parent e46c4e83d5
commit 22cc05a9fe
3 changed files with 118 additions and 6 deletions

View File

@ -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);
/**
* @}
*/

View File

@ -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

View File

@ -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;