From: Enlightenment S. <no-...@en...> - 2012-10-10 19:16:55
|
Log: ephysics: allow to enable angular movement on all the planes Author: bdilly Date: 2012-10-10 12:16:48 -0700 (Wed, 10 Oct 2012) New Revision: 77775 Trac: http://trac.enlightenment.org/e/changeset/77775 Modified: trunk/ephysics/src/bin/ephysics_logo.c trunk/ephysics/src/bin/test_jumping_balls.c trunk/ephysics/src/lib/EPhysics.h trunk/ephysics/src/lib/ephysics_body.cpp Modified: trunk/ephysics/src/bin/ephysics_logo.c =================================================================== --- trunk/ephysics/src/bin/ephysics_logo.c 2012-10-10 19:16:43 UTC (rev 77774) +++ trunk/ephysics/src/bin/ephysics_logo.c 2012-10-10 19:16:48 UTC (rev 77775) @@ -143,7 +143,8 @@ ephysics_body_evas_object_set(body, view, EINA_TRUE); ephysics_body_mass_set(body, 1.2); ephysics_body_restitution_set(body, 0.6); - ephysics_body_rotation_on_z_axis_enable_set(body, EINA_FALSE); + ephysics_body_angular_movement_enable_set(body, EINA_FALSE, EINA_FALSE, + EINA_FALSE); } static EPhysics_Body * @@ -260,7 +261,8 @@ letter_body = _letter_body_circle_add(world, image); ephysics_body_friction_set(letter_body, 1); ephysics_body_mass_set(letter_body, 1); - ephysics_body_rotation_on_z_axis_enable_set(letter_body, EINA_TRUE); + ephysics_body_angular_movement_enable_set(letter_body, EINA_FALSE, + EINA_FALSE, EINA_TRUE); /* make the "E" logo get into the viewport by applying an horizontal force */ ephysics_body_central_impulse_apply(letter_body, 390, 0); Modified: trunk/ephysics/src/bin/test_jumping_balls.c =================================================================== --- trunk/ephysics/src/bin/test_jumping_balls.c 2012-10-10 19:16:43 UTC (rev 77774) +++ trunk/ephysics/src/bin/test_jumping_balls.c 2012-10-10 19:16:48 UTC (rev 77775) @@ -60,6 +60,7 @@ test_data->evas_objs = eina_list_append(test_data->evas_objs, sphere); fall_body = ephysics_body_circle_add(test_data->world); + ephysics_body_linear_movement_enable_set(fall_body, EINA_TRUE, EINA_TRUE, EINA_TRUE); ephysics_body_evas_object_set(fall_body, sphere, EINA_TRUE); ephysics_body_event_callback_add(fall_body, EPHYSICS_CALLBACK_BODY_UPDATE, update_object_cb, shadow); Modified: trunk/ephysics/src/lib/EPhysics.h =================================================================== --- trunk/ephysics/src/lib/EPhysics.h 2012-10-10 19:16:43 UTC (rev 77774) +++ trunk/ephysics/src/lib/EPhysics.h 2012-10-10 19:16:48 UTC (rev 77775) @@ -2693,33 +2693,39 @@ * @brief * Enable or disable body's rotation on z axis. * - * Enabled by default. + * Enabled by default for z axis, so the body only will rotate on x-y plane. * - * If disabled, body won't rotate on x-y plane. - * * @param body The physics body. - * @param enable If @c EINA_TRUE enable rotation on z axis, if @c EINA_FALSE - * disable it. + * @param enable_x If @c EINA_TRUE allow rotation on x axis (y-z plane), + * if @c EINA_FALSE disallow it. + * @param enable_y If @c EINA_TRUE allow rotation on y axis (x-z plane), + *if @c EINA_FALSE disallow it. + * @param enable_z If @c EINA_TRUE allow rotation on z axis (x-y plane), + * if @c EINA_FALSE disallow it. * - * @see ephysics_body_rotation_on_z_axis_enable_get(). + * @see ephysics_body_angular_movement_enable_get(). * * @ingroup EPhysics_Body */ -EAPI void ephysics_body_rotation_on_z_axis_enable_set(EPhysics_Body *body, Eina_Bool enable); +EAPI void ephysics_body_angular_movement_enable_set(EPhysics_Body *body, Eina_Bool enable_x, Eina_Bool enable_y, Eina_Bool enable_z); /** * @brief * Return body's rotation on z axis state. * * @param body The physics body. - * @return @c EINA_TRUE if rotation on z axis is enabled, or @c EINA_FALSE - * if disabled (or on error). + * @param enable_x @c EINA_TRUE if rotation on x axis (y-z plane) is allowed, or + * @c EINA_FALSE if it's not. + * @param enable_y @c EINA_TRUE if rotation on y axis (x-z plane) is allowed, or + * @c EINA_FALSE if it's not. + * @param enable_z @c EINA_TRUE if rotation on z axis (x-y plane) is allowed, or + * @c EINA_FALSE if it's not. * - * @see ephysics_body_rotation_on_z_axis_enable_set() for more details. + * @see ephysics_body_angular_movement_enable_set() for more details. * * @ingroup EPhysics_Body */ -EAPI Eina_Bool ephysics_body_rotation_on_z_axis_enable_get(const EPhysics_Body *body); +EAPI void ephysics_body_angular_movement_enable_get(const EPhysics_Body *body, Eina_Bool *enable_x, Eina_Bool *enable_y, Eina_Bool *enable_z); /** * @brief @@ -2736,7 +2742,7 @@ * disallow it. * * @see ephysics_body_linear_movement_enable_get(). - * @see ephysics_body_rotation_on_z_axis_enable_set(). + * @see ephysics_body_angular_movement_enable_set(). * * @ingroup EPhysics_Body */ @@ -2755,7 +2761,7 @@ * @c EINA_FALSE if it's not. * * @see ephysics_body_linear_movement_enable_set(). - * @see ephysics_body_rotation_on_z_axis_enable_get(). + * @see ephysics_body_angular_movement_enable_get(). * * @ingroup EPhysics_Body */ Modified: trunk/ephysics/src/lib/ephysics_body.cpp =================================================================== --- trunk/ephysics/src/lib/ephysics_body.cpp 2012-10-10 19:16:43 UTC (rev 77774) +++ trunk/ephysics/src/lib/ephysics_body.cpp 2012-10-10 19:16:48 UTC (rev 77775) @@ -2483,7 +2483,7 @@ } EAPI void -ephysics_body_rotation_on_z_axis_enable_set(EPhysics_Body *body, Eina_Bool enable) +ephysics_body_angular_movement_enable_set(EPhysics_Body *body, Eina_Bool enable_x, Eina_Bool enable_y, Eina_Bool enable_z) { if (!body) { @@ -2492,23 +2492,23 @@ } ephysics_world_lock_take(body->world); - if (!enable) - body->rigid_body->setAngularFactor(btVector3(0, 0, 0)); - else - body->rigid_body->setAngularFactor(btVector3(0, 0, 1)); + body->rigid_body->setAngularFactor(btVector3(!!enable_x, !!enable_y, + !!enable_z)); ephysics_world_lock_release(body->world); } -EAPI Eina_Bool -ephysics_body_rotation_on_z_axis_enable_get(const EPhysics_Body *body) +EAPI void +ephysics_body_angular_movement_enable_get(const EPhysics_Body *body, Eina_Bool *enable_x, Eina_Bool *enable_y, Eina_Bool *enable_z) { if (!body) { ERR("Can't check if rotation is enabled, body is null."); - return EINA_FALSE; + return; } - return !!body->rigid_body->getAngularFactor().z(); + if (enable_x) *enable_x = !!body->rigid_body->getAngularFactor().x(); + if (enable_y) *enable_y = !!body->rigid_body->getAngularFactor().y(); + if (enable_z) *enable_z = !!body->rigid_body->getAngularFactor().z(); } EAPI double |