diff --git a/legacy/ephysics/src/bin/ephysics_sandbox.c b/legacy/ephysics/src/bin/ephysics_sandbox.c index 9a56094063..3d28ed9a6a 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 74b8e6959b..00736b09c8 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 88787344ab..8dc1dcc74a 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 5d39fddcc5..443ec3f994 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 11987d4f42..6de20f3569 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 70d86e4a2b..5e89163de0 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 3a0b5a07da..b224ff22c6 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 c95e70ab11..887110fcb8 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 25deaff70f..a9d3fc4008 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 b1f9ec1bb9..f92de5f149 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 ee4ab0f69f..d8997e403d 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 47c402ed17..69bcc13b72 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 81de0e803c..b3ee79a9e3 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 57c766a33e..4d94f299bc 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 bf38fb2ca3..e6b2d513ed 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 b595a31542..d99db710dc 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 9f3d4a5d67..0ae8372005 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 e790608230..8df93bfa59 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 ec6d79981e..888e4be004 100644 --- a/legacy/ephysics/src/lib/EPhysics.h +++ b/legacy/ephysics/src/lib/EPhysics.h @@ -2668,6 +2668,30 @@ EAPI void ephysics_body_soft_body_triangle_move(EPhysics_Body *body, int idx, Ev */ EAPI void ephysics_body_soft_body_bending_constraints_add(EPhysics_Body *body, int number); +/** + * @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. diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp index 5c7a061e60..5fde811807 100644 --- a/legacy/ephysics/src/lib/ephysics_body.cpp +++ b/legacy/ephysics/src/lib/ephysics_body.cpp @@ -2840,6 +2840,33 @@ no_collision_shape: return NULL; } +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) { diff --git a/legacy/ephysics/src/lib/ephysics_private.h b/legacy/ephysics/src/lib/ephysics_private.h index 3e7050b480..994561a4a9 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;