From 44a9b9a350589b53682381f2a5b0dfceb3acd7fc Mon Sep 17 00:00:00 2001 From: Leandro Dorileo Date: Tue, 11 Dec 2012 21:11:00 +0000 Subject: [PATCH] EPhysics: add ephysics_body_sphere_add() API SVN revision: 80717 --- legacy/ephysics/src/bin/ephysics_sandbox.c | 2 +- legacy/ephysics/src/bin/test_bouncing_ball.c | 2 +- legacy/ephysics/src/bin/test_camera.c | 8 +++---- legacy/ephysics/src/bin/test_camera_track.c | 2 +- legacy/ephysics/src/bin/test_colliding_balls.c | 4 ++-- legacy/ephysics/src/bin/test_collision_detection.c | 4 ++-- legacy/ephysics/src/bin/test_collision_filter.c | 2 +- legacy/ephysics/src/bin/test_collision_speed.c | 2 +- legacy/ephysics/src/bin/test_delete.c | 4 ++-- legacy/ephysics/src/bin/test_growing_balls.c | 2 +- legacy/ephysics/src/bin/test_heavy.c | 2 +- legacy/ephysics/src/bin/test_jumping_balls.c | 6 ++--- legacy/ephysics/src/bin/test_light.c | 2 +- legacy/ephysics/src/bin/test_material.c | 2 +- legacy/ephysics/src/bin/test_sleeping_threshold.c | 4 ++-- legacy/ephysics/src/bin/test_soft_body.c | 2 +- legacy/ephysics/src/bin/test_velocity.c | 2 +- legacy/ephysics/src/bin/test_win_resize.c | 2 +- legacy/ephysics/src/lib/EPhysics.h | 24 +++++++++++++++++++ legacy/ephysics/src/lib/ephysics_body.cpp | 27 ++++++++++++++++++++++ legacy/ephysics/src/lib/ephysics_private.h | 1 + 21 files changed, 78 insertions(+), 28 deletions(-) diff --git a/legacy/ephysics/src/bin/ephysics_sandbox.c b/legacy/ephysics/src/bin/ephysics_sandbox.c index 9a56094..3d28ed9 100644 --- a/legacy/ephysics/src/bin/ephysics_sandbox.c +++ b/legacy/ephysics/src/bin/ephysics_sandbox.c @@ -146,7 +146,7 @@ _type_set_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__) } else { - body = ephysics_body_cylinder_add(world); + body = ephysics_body_sphere_add(world); elm_object_disabled_set(bd->controls.hardness, EINA_TRUE); } diff --git a/legacy/ephysics/src/bin/test_bouncing_ball.c b/legacy/ephysics/src/bin/test_bouncing_ball.c index 74b8e69..00736b0 100644 --- a/legacy/ephysics/src/bin/test_bouncing_ball.c +++ b/legacy/ephysics/src/bin/test_bouncing_ball.c @@ -47,7 +47,7 @@ _world_populate(Test_Data *test_data) evas_object_show(sphere); test_data->evas_objs = eina_list_append(test_data->evas_objs, sphere); - fall_body = ephysics_body_cylinder_add(test_data->world); + fall_body = ephysics_body_sphere_add(test_data->world); ephysics_body_evas_object_set(fall_body, sphere, EINA_TRUE); ephysics_body_restitution_set(fall_body, 0.95); ephysics_body_friction_set(fall_body, 0.1); diff --git a/legacy/ephysics/src/bin/test_camera.c b/legacy/ephysics/src/bin/test_camera.c index 8878734..8dc1dcc 100644 --- a/legacy/ephysics/src/bin/test_camera.c +++ b/legacy/ephysics/src/bin/test_camera.c @@ -95,10 +95,10 @@ _world_populate(Camera_Data *camera_data) camera_data->base.evas_objs = eina_list_append(camera_data->base.evas_objs, sphere); - fall_body = ephysics_body_cylinder_add(camera_data->base.world); + fall_body = ephysics_body_sphere_add(camera_data->base.world); ephysics_body_evas_object_set(fall_body, sphere, EINA_TRUE); ephysics_body_restitution_set(fall_body, 0.2); - ephysics_body_friction_set(fall_body, 0.5); + ephysics_body_friction_set(fall_body, 1); ephysics_body_event_callback_add(fall_body, EPHYSICS_CALLBACK_BODY_UPDATE, update_object_cb, shadow); camera_data->base.bodies = eina_list_append(camera_data->base.bodies, @@ -123,8 +123,8 @@ _world_populate(Camera_Data *camera_data) camera_data->base.evas_objs = eina_list_append(camera_data->base.evas_objs, sphere); - fall_body = ephysics_body_cylinder_add(camera_data->base.world); - ephysics_body_mass_set(fall_body, 3.7); + fall_body = ephysics_body_sphere_add(camera_data->base.world); + ephysics_body_mass_set(fall_body, 4.6); ephysics_body_evas_object_set(fall_body, sphere, EINA_TRUE); ephysics_body_restitution_set(fall_body, 0.12); ephysics_body_friction_set(fall_body, 2); diff --git a/legacy/ephysics/src/bin/test_camera_track.c b/legacy/ephysics/src/bin/test_camera_track.c index 5d39fdd..443ec3f 100644 --- a/legacy/ephysics/src/bin/test_camera_track.c +++ b/legacy/ephysics/src/bin/test_camera_track.c @@ -126,7 +126,7 @@ _world_populate(Track_Data *track_data) track_data->base.evas_objs = eina_list_append(track_data->base.evas_objs, sphere); - body = ephysics_body_cylinder_add(track_data->base.world); + body = ephysics_body_sphere_add(track_data->base.world); ephysics_body_evas_object_set(body, sphere, EINA_TRUE); ephysics_body_restitution_set(body, 0.95); ephysics_body_friction_set(body, 1); diff --git a/legacy/ephysics/src/bin/test_colliding_balls.c b/legacy/ephysics/src/bin/test_colliding_balls.c index 11987d4..6de20f3 100644 --- a/legacy/ephysics/src/bin/test_colliding_balls.c +++ b/legacy/ephysics/src/bin/test_colliding_balls.c @@ -36,13 +36,13 @@ _world_populate(Test_Data *test_data) evas_object_show(sphere); test_data->evas_objs = eina_list_append(test_data->evas_objs, sphere); - fall_body = ephysics_body_cylinder_add(test_data->world); + fall_body = ephysics_body_sphere_add(test_data->world); 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); ephysics_body_restitution_set(fall_body, 0.95); - ephysics_body_friction_set(fall_body, 0.1); + ephysics_body_friction_set(fall_body, 1); test_data->bodies = eina_list_append(test_data->bodies, fall_body); } } diff --git a/legacy/ephysics/src/bin/test_collision_detection.c b/legacy/ephysics/src/bin/test_collision_detection.c index 70d86e4..5e89163 100644 --- a/legacy/ephysics/src/bin/test_collision_detection.c +++ b/legacy/ephysics/src/bin/test_collision_detection.c @@ -58,7 +58,7 @@ _world_populate(Collision_Data *collision_data) collision_data->base.evas_objs = eina_list_append( collision_data->base.evas_objs, sphere1); - sphere_body1 = ephysics_body_cylinder_add(collision_data->base.world); + sphere_body1 = ephysics_body_sphere_add(collision_data->base.world); ephysics_body_evas_object_set(sphere_body1, sphere1, EINA_TRUE); ephysics_body_event_callback_add(sphere_body1, EPHYSICS_CALLBACK_BODY_UPDATE, @@ -88,7 +88,7 @@ _world_populate(Collision_Data *collision_data) collision_data->base.evas_objs = eina_list_append( collision_data->base.evas_objs, sphere2); - sphere_body2 = ephysics_body_cylinder_add(collision_data->base.world); + sphere_body2 = ephysics_body_sphere_add(collision_data->base.world); ephysics_body_evas_object_set(sphere_body2, sphere2, EINA_TRUE); ephysics_body_event_callback_add(sphere_body2, EPHYSICS_CALLBACK_BODY_UPDATE, diff --git a/legacy/ephysics/src/bin/test_collision_filter.c b/legacy/ephysics/src/bin/test_collision_filter.c index 3a0b5a0..b224ff2 100644 --- a/legacy/ephysics/src/bin/test_collision_filter.c +++ b/legacy/ephysics/src/bin/test_collision_filter.c @@ -29,7 +29,7 @@ _world_populate(Test_Data *test_data) evas_object_show(sphere); test_data->evas_objs = eina_list_append(test_data->evas_objs, sphere); - fall_body = ephysics_body_cylinder_add(test_data->world); + fall_body = ephysics_body_sphere_add(test_data->world); ephysics_body_evas_object_set(fall_body, sphere, EINA_TRUE); ephysics_body_restitution_set(fall_body, 0.95); ephysics_body_friction_set(fall_body, 0.1); diff --git a/legacy/ephysics/src/bin/test_collision_speed.c b/legacy/ephysics/src/bin/test_collision_speed.c index c95e70a..887110f 100644 --- a/legacy/ephysics/src/bin/test_collision_speed.c +++ b/legacy/ephysics/src/bin/test_collision_speed.c @@ -50,7 +50,7 @@ _world_populate(Speed_Data *speed_data) speed_data->base.evas_objs = eina_list_append(speed_data->base.evas_objs, sphere); - ball = ephysics_body_cylinder_add(speed_data->base.world); + ball = ephysics_body_sphere_add(speed_data->base.world); ephysics_body_evas_object_set(ball, sphere, EINA_TRUE); ephysics_body_restitution_set(ball, 0.8); ephysics_body_friction_set(ball, 0.2); diff --git a/legacy/ephysics/src/bin/test_delete.c b/legacy/ephysics/src/bin/test_delete.c index 25deaff..a9d3fc4 100644 --- a/legacy/ephysics/src/bin/test_delete.c +++ b/legacy/ephysics/src/bin/test_delete.c @@ -75,7 +75,7 @@ _world_populate(Collision_Data *collision_data) collision_data->base.evas_objs = eina_list_append( collision_data->base.evas_objs, sphere1); - sphere_body1 = ephysics_body_cylinder_add(collision_data->base.world); + sphere_body1 = ephysics_body_sphere_add(collision_data->base.world); ephysics_body_evas_object_set(sphere_body1, sphere1, EINA_TRUE); ephysics_body_event_callback_add(sphere_body1, EPHYSICS_CALLBACK_BODY_UPDATE, @@ -108,7 +108,7 @@ _world_populate(Collision_Data *collision_data) collision_data->base.evas_objs = eina_list_append( collision_data->base.evas_objs, sphere2); - sphere_body2 = ephysics_body_cylinder_add(collision_data->base.world); + sphere_body2 = ephysics_body_sphere_add(collision_data->base.world); ephysics_body_evas_object_set(sphere_body2, sphere2, EINA_TRUE); ephysics_body_event_callback_add(sphere_body2, EPHYSICS_CALLBACK_BODY_UPDATE, diff --git a/legacy/ephysics/src/bin/test_growing_balls.c b/legacy/ephysics/src/bin/test_growing_balls.c index b1f9ec1..f92de5f 100644 --- a/legacy/ephysics/src/bin/test_growing_balls.c +++ b/legacy/ephysics/src/bin/test_growing_balls.c @@ -41,7 +41,7 @@ _add_sphere(Test_Data *test_data, const char *group, int size, int x, int y) evas_object_show(sphere); test_data->evas_objs = eina_list_append(test_data->evas_objs, sphere); - sphere_body = ephysics_body_cylinder_add(test_data->world); + sphere_body = ephysics_body_sphere_add(test_data->world); ephysics_body_evas_object_set(sphere_body, sphere, EINA_TRUE); ephysics_body_restitution_set(sphere_body, 0.5); ephysics_body_central_impulse_apply(sphere_body, 300, 0, 0); diff --git a/legacy/ephysics/src/bin/test_heavy.c b/legacy/ephysics/src/bin/test_heavy.c index ee4ab0f..d8997e4 100644 --- a/legacy/ephysics/src/bin/test_heavy.c +++ b/legacy/ephysics/src/bin/test_heavy.c @@ -19,7 +19,7 @@ _add_sphere(Test_Data *test_data, int i) evas_object_show(sphere); test_data->evas_objs = eina_list_append(test_data->evas_objs, sphere); - body = ephysics_body_cylinder_add(test_data->world); + body = ephysics_body_sphere_add(test_data->world); ephysics_body_restitution_set(body, 0.85); ephysics_body_evas_object_set(body, sphere, EINA_TRUE); test_data->bodies = eina_list_append(test_data->bodies, body); diff --git a/legacy/ephysics/src/bin/test_jumping_balls.c b/legacy/ephysics/src/bin/test_jumping_balls.c index 47c402e..69bcc13 100644 --- a/legacy/ephysics/src/bin/test_jumping_balls.c +++ b/legacy/ephysics/src/bin/test_jumping_balls.c @@ -59,14 +59,12 @@ _add_sphere(Test_Data *test_data, int i) evas_object_show(sphere); test_data->evas_objs = eina_list_append(test_data->evas_objs, sphere); - fall_body = ephysics_body_cylinder_add(test_data->world); - ephysics_body_linear_movement_enable_set(fall_body, EINA_TRUE, EINA_TRUE, - EINA_TRUE); + fall_body = ephysics_body_sphere_add(test_data->world); 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); ephysics_body_restitution_set(fall_body, 0.95); - ephysics_body_friction_set(fall_body, 0.1); + ephysics_body_friction_set(fall_body, 1); test_data->bodies = eina_list_append(test_data->bodies, fall_body); } diff --git a/legacy/ephysics/src/bin/test_light.c b/legacy/ephysics/src/bin/test_light.c index 81de0e8..b3ee79a 100644 --- a/legacy/ephysics/src/bin/test_light.c +++ b/legacy/ephysics/src/bin/test_light.c @@ -33,7 +33,7 @@ _ball_add(Test_Data *test_data, int x) evas_object_show(sphere); test_data->evas_objs = eina_list_append(test_data->evas_objs, sphere); - ball = ephysics_body_cylinder_add(test_data->world); + ball = ephysics_body_sphere_add(test_data->world); ephysics_body_evas_object_set(ball, sphere, EINA_TRUE); ephysics_body_restitution_set(ball, 0.95); ephysics_body_friction_set(ball, 0.1); diff --git a/legacy/ephysics/src/bin/test_material.c b/legacy/ephysics/src/bin/test_material.c index 57c766a..4d94f29 100644 --- a/legacy/ephysics/src/bin/test_material.c +++ b/legacy/ephysics/src/bin/test_material.c @@ -56,7 +56,7 @@ _world_populate(Test_Data *test_data) evas_object_show(sphere); test_data->evas_objs = eina_list_append(test_data->evas_objs, sphere); - fall_body = ephysics_body_cylinder_add(test_data->world); + fall_body = ephysics_body_sphere_add(test_data->world); 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); diff --git a/legacy/ephysics/src/bin/test_sleeping_threshold.c b/legacy/ephysics/src/bin/test_sleeping_threshold.c index bf38fb2..e6b2d51 100644 --- a/legacy/ephysics/src/bin/test_sleeping_threshold.c +++ b/legacy/ephysics/src/bin/test_sleeping_threshold.c @@ -27,7 +27,7 @@ _world_populate(Test_Data *test_data) evas_object_show(sphere1); test_data->evas_objs = eina_list_append(test_data->evas_objs, sphere1); - sphere_body1 = ephysics_body_cylinder_add(test_data->world); + sphere_body1 = ephysics_body_sphere_add(test_data->world); ephysics_body_evas_object_set(sphere_body1, sphere1, EINA_TRUE); ephysics_body_event_callback_add(sphere_body1, EPHYSICS_CALLBACK_BODY_UPDATE, @@ -55,7 +55,7 @@ _world_populate(Test_Data *test_data) evas_object_show(sphere2); test_data->evas_objs = eina_list_append(test_data->evas_objs, sphere2); - sphere_body2 = ephysics_body_cylinder_add(test_data->world); + sphere_body2 = ephysics_body_sphere_add(test_data->world); ephysics_body_evas_object_set(sphere_body2, sphere2, EINA_TRUE); ephysics_body_event_callback_add(sphere_body2, EPHYSICS_CALLBACK_BODY_UPDATE, diff --git a/legacy/ephysics/src/bin/test_soft_body.c b/legacy/ephysics/src/bin/test_soft_body.c index b595a31..d99db71 100644 --- a/legacy/ephysics/src/bin/test_soft_body.c +++ b/legacy/ephysics/src/bin/test_soft_body.c @@ -76,7 +76,7 @@ _world_populate(Test_Data *test_data) evas_object_show(evas_obj); test_data->evas_objs = eina_list_append(test_data->evas_objs, evas_obj); - fall_body = ephysics_body_cylinder_add(test_data->world); + fall_body = ephysics_body_sphere_add(test_data->world); ephysics_body_mass_set(fall_body, 2); ephysics_body_evas_object_set(fall_body, evas_obj, EINA_TRUE); ephysics_body_restitution_set(fall_body, 0.95); diff --git a/legacy/ephysics/src/bin/test_velocity.c b/legacy/ephysics/src/bin/test_velocity.c index 9f3d4a5..0ae8372 100644 --- a/legacy/ephysics/src/bin/test_velocity.c +++ b/legacy/ephysics/src/bin/test_velocity.c @@ -106,7 +106,7 @@ _world_populate(Velocity_Data *velocity_data) velocity_data->base.evas_objs = eina_list_append( velocity_data->base.evas_objs, sphere); - sphere_body = ephysics_body_cylinder_add(velocity_data->base.world); + sphere_body = ephysics_body_sphere_add(velocity_data->base.world); ephysics_body_evas_object_set(sphere_body, sphere, EINA_TRUE); ephysics_body_restitution_set(sphere_body, 0.8); ephysics_body_friction_set(sphere_body, 1); diff --git a/legacy/ephysics/src/bin/test_win_resize.c b/legacy/ephysics/src/bin/test_win_resize.c index e790608..8df93bf 100644 --- a/legacy/ephysics/src/bin/test_win_resize.c +++ b/legacy/ephysics/src/bin/test_win_resize.c @@ -136,7 +136,7 @@ _world_populate(Test_Data *test_data) evas_object_show(sphere); test_data->evas_objs = eina_list_append(test_data->evas_objs, sphere); - sphere_body = ephysics_body_cylinder_add(test_data->world); + sphere_body = ephysics_body_sphere_add(test_data->world); ephysics_body_evas_object_set(sphere_body, sphere, EINA_TRUE); ephysics_body_restitution_set(sphere_body, 1.0); ephysics_body_event_callback_add(sphere_body, EPHYSICS_CALLBACK_BODY_UPDATE, diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h index ec6d799..888e4be 100644 --- a/legacy/ephysics/src/lib/EPhysics.h +++ b/legacy/ephysics/src/lib/EPhysics.h @@ -2670,6 +2670,30 @@ EAPI void ephysics_body_soft_body_bending_constraints_add(EPhysics_Body *body, i /** * @brief + * Create a new sphere physics body. + * + * Its collision shape will be a sphere of diameter 1. To change its size @ref + * ephysics_body_geometry_set(), @p ephysics_body_resize() should be used. + * + * Any evas object can be associated to it with @p + * ephysics_body_evas_object_set(), and it will collid as a sphere(even if + * you`ve associated an evas rectangle). + * + * For deformable sphere use @p ephysics_body_soft_ellipsoid_add() instead. + * + * @param world The world this body will belong to. + * @return a new body or @c NULL, on errors. + * + * @see ephysics_body_del(). + * @see ephysics_body_evas_object_set(). + * @see ephysics_body_face_evas_object_set(). + * + * @ingroup EPhysics_Body + */ +EAPI EPhysics_Body *ephysics_body_sphere_add(EPhysics_World *world); + +/** + * @brief * Create a new cylinder physics body. * * Its collision shape will be a cylinder of diameter 1. To change it's size diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp index 5c7a061..5fde811 100644 --- a/legacy/ephysics/src/lib/ephysics_body.cpp +++ b/legacy/ephysics/src/lib/ephysics_body.cpp @@ -2841,6 +2841,33 @@ no_collision_shape: } EAPI EPhysics_Body * +ephysics_body_sphere_add(EPhysics_World *world) +{ + btCollisionShape *collision_shape; + EPhysics_Body *body; + + if (!world) + { + ERR("Can't add sphere, world is null."); + return NULL; + } + + collision_shape = new btSphereShape(0.5); + if (!collision_shape) + { + ERR("Couldn't create a new sphere shape."); + return NULL; + } + + ephysics_world_lock_take(world); + body = _ephysics_body_rigid_body_add(world, collision_shape, "sphere", 0.5, + 0.5, 0.5); + body->shape = EPHYSICS_BODY_SHAPE_SPHERE; + ephysics_world_lock_release(world); + return body; +} + +EAPI EPhysics_Body * ephysics_body_cylinder_add(EPhysics_World *world) { btCollisionShape *collision_shape; diff --git a/legacy/ephysics/src/lib/ephysics_private.h b/legacy/ephysics/src/lib/ephysics_private.h index 3e7050b..994561a 100644 --- a/legacy/ephysics/src/lib/ephysics_private.h +++ b/legacy/ephysics/src/lib/ephysics_private.h @@ -66,6 +66,7 @@ typedef enum _EPhysics_Body_Shape EPHYSICS_BODY_SHAPE_BOX, EPHYSICS_BODY_SHAPE_CUSTOM, EPHYSICS_BODY_SHAPE_CYLINDER, + EPHYSICS_BODY_SHAPE_SPHERE, EPHYSICS_BODY_SHAPE_ELLIPSOID, EPHYSICS_BODY_SHAPE_LAST, } EPhysics_Body_Shape; -- 2.7.4