summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorLeandro Dorileo <dorileo@profusion.mobi>2012-11-29 18:51:51 +0000
committerLeandro Dorileo <dorileo@profusion.mobi>2012-11-29 18:51:51 +0000
commit0b558bc80ce7c6ed4bae0c64fd0c37cd0c8a1fab (patch)
tree21bb2b60852cde6eb5d6e9fa2af43b3023380f2e /legacy
parent603239627c12d8f855bc3da610cf6cae1c48749d (diff)
EPhysics: generic constraint
This patch changes how constraints are created and configured, now we use a bullet generic implementation which let us operate on the 6 degrees of freedom(linear and angular ones). We have used 6dof for slider constraint but now we assume 2 types of constraints, single body - simply ephysics_constraint_add(body) - and a linked one - ephysics_constraint_linked_add(body1, body2) used to constrain 2 bodies linked together. Having said that we introduce the following changes: + migrate p2p constraint to 6Dof We want to have a constraint api generic enouth to allow many different constraint behaviour, 6Dof was picked to do that, so p2p needs a migration. + move ephysics_constraint_slider_* functions Since the whole constraint infra-sctructure is being migrated to 6Dof the linear and angular limit functions - previously used only by slider constraint - now looks more generic enough to be used by constraint in general. + add constraint anchor API Instead of telling the anchoring positioning in the constraint creating we have set it's default value to the the middle os the body and if the user wants to change it call ephysics_constraint_anchor_set and reset it. The ephysics_constraint_anchor_set() considers the canvas coordinate instead of using the body orientation. So now one can tell a constraints anchor is set to 100, 10, 0 in the canvas coordinate system and not (body_center.x - 20, body_center.y - 5, body_center.z - 1). + constraint migrate the bt_constraint Since we're working only with 6Dof constraints it is reasonable to change the constraints bt_constraint field to btGeneric6DofConstraint. + add 3 axes to constraints Now constraints API knows about x, y and z axes - linear and angular limiting, anchor setting and the constraint creation functions are fully supported. + constraint calls are renamed The constraint calls were renamed so ephysics_constraint_p2p_add() now is known as ephysics_constraint_linked_add() and ephysics_constraint_slider_add() became ephysics_constraint_add() where the first one is meant for constrain 2 bodies and the second one for single body constraints. --This line, and those below, will be ignored-- SVN revision: 79848
Diffstat (limited to 'legacy')
-rw-r--r--legacy/ephysics/src/bin/test_constraint.c24
-rw-r--r--legacy/ephysics/src/bin/test_slider.c17
-rw-r--r--legacy/ephysics/src/lib/EPhysics.h163
-rw-r--r--legacy/ephysics/src/lib/ephysics_constraints.cpp339
-rw-r--r--legacy/ephysics/src/lib/ephysics_private.h4
-rw-r--r--legacy/ephysics/src/lib/ephysics_world.cpp6
6 files changed, 335 insertions, 218 deletions
diff --git a/legacy/ephysics/src/bin/test_constraint.c b/legacy/ephysics/src/bin/test_constraint.c
index 617b19e1f3..988ed7b415 100644
--- a/legacy/ephysics/src/bin/test_constraint.c
+++ b/legacy/ephysics/src/bin/test_constraint.c
@@ -5,11 +5,26 @@
5#include "ephysics_test.h" 5#include "ephysics_test.h"
6 6
7static void 7static void
8_constraint_set(Test_Data *test_data, EPhysics_Body *body1, EPhysics_Body *body2)
9{
10 EPhysics_Constraint *constraint;
11 Evas_Coord b1x, b1y, b1z, b1w, b1h, b1d, b2x, b2y, b2z, b2w, b2h, b2d;
12
13 ephysics_body_geometry_get(body1, &b1x, &b1y, &b1z, &b1w, &b1h, &b1d);
14 ephysics_body_geometry_get(body2, &b2x, &b2y, &b2z, &b2w, &b2h, &b2d);
15
16 constraint = ephysics_constraint_linked_add(body1, body2);
17
18 ephysics_constraint_anchor_set(constraint, b1x + b1w / 2, b1y + b1h / 2 + 100,
19 b1z, b2x + b2w / 2, b2y + b2h / 2, b2z);
20 test_data->constraints = eina_list_append(test_data->constraints, constraint);
21}
22
23static void
8_world_populate(Test_Data *test_data) 24_world_populate(Test_Data *test_data)
9{ 25{
10 EPhysics_Body *box_body1, *box_body2; 26 EPhysics_Body *box_body1, *box_body2;
11 Evas_Object *box1, *box2, *sh1, *sh2; 27 Evas_Object *box1, *box2, *sh1, *sh2;
12 EPhysics_Constraint *constraint;
13 28
14 sh1 = elm_layout_add(test_data->win); 29 sh1 = elm_layout_add(test_data->win);
15 elm_layout_file_set( 30 elm_layout_file_set(
@@ -52,18 +67,15 @@ _world_populate(Test_Data *test_data)
52 test_data->evas_objs = eina_list_append(test_data->evas_objs, box2); 67 test_data->evas_objs = eina_list_append(test_data->evas_objs, box2);
53 68
54 box_body2 = ephysics_body_box_add(test_data->world); 69 box_body2 = ephysics_body_box_add(test_data->world);
55 ephysics_body_mass_set(box_body2, 5);
56 ephysics_body_evas_object_set(box_body2, box2, EINA_TRUE); 70 ephysics_body_evas_object_set(box_body2, box2, EINA_TRUE);
71 ephysics_body_mass_set(box_body2, 5);
57 ephysics_body_event_callback_add(box_body2, EPHYSICS_CALLBACK_BODY_UPDATE, 72 ephysics_body_event_callback_add(box_body2, EPHYSICS_CALLBACK_BODY_UPDATE,
58 update_object_cb, sh2); 73 update_object_cb, sh2);
59 ephysics_body_restitution_set(box_body2, 0.5); 74 ephysics_body_restitution_set(box_body2, 0.5);
60 ephysics_body_friction_set(box_body2, 0.1); 75 ephysics_body_friction_set(box_body2, 0.1);
61 test_data->bodies = eina_list_append(test_data->bodies, box_body2); 76 test_data->bodies = eina_list_append(test_data->bodies, box_body2);
62 77
63 constraint = ephysics_constraint_p2p_add(box_body1, box_body2, 0, 100, 0, 78 _constraint_set(test_data, box_body1, box_body2);
64 0);
65 test_data->constraints = eina_list_append(test_data->constraints,
66 constraint);
67} 79}
68 80
69static void 81static void
diff --git a/legacy/ephysics/src/bin/test_slider.c b/legacy/ephysics/src/bin/test_slider.c
index 6bb840e6a5..f17ca01d7f 100644
--- a/legacy/ephysics/src/bin/test_slider.c
+++ b/legacy/ephysics/src/bin/test_slider.c
@@ -60,10 +60,10 @@ _world_populate(Test_Data *test_data)
60 ephysics_body_friction_set(box_body2, 0.1); 60 ephysics_body_friction_set(box_body2, 0.1);
61 test_data->bodies = eina_list_append(test_data->bodies, box_body2); 61 test_data->bodies = eina_list_append(test_data->bodies, box_body2);
62 62
63 constraint = ephysics_constraint_slider_add(box_body2); 63 constraint = ephysics_constraint_add(box_body2);
64 ephysics_constraint_slider_linear_limit_set(constraint, 0, 64 ephysics_constraint_linear_limit_set(constraint, 0, 0, 0,
65 HEIGHT - (HEIGHT / 8), 0, 0); 65 HEIGHT - (HEIGHT / 8), 0, 0);
66 ephysics_constraint_slider_angular_limit_set(constraint, 0, 45); 66 ephysics_constraint_angular_limit_set(constraint, 0, 0, 0, 0, 0, 45);
67 test_data->constraints = eina_list_append(test_data->constraints, 67 test_data->constraints = eina_list_append(test_data->constraints,
68 constraint); 68 constraint);
69 69
@@ -91,9 +91,8 @@ _world_populate(Test_Data *test_data)
91 ephysics_body_friction_set(box_body3, 0.1); 91 ephysics_body_friction_set(box_body3, 0.1);
92 test_data->bodies = eina_list_append(test_data->bodies, box_body3); 92 test_data->bodies = eina_list_append(test_data->bodies, box_body3);
93 93
94 constraint = ephysics_constraint_slider_add(box_body3); 94 constraint = ephysics_constraint_add(box_body3);
95 ephysics_constraint_slider_linear_limit_set(constraint, WIDTH - 120, 0, 0, 95 ephysics_constraint_linear_limit_set(constraint, WIDTH - 120, 0, 0, 0, 0, 0);
96 0);
97 ephysics_body_central_impulse_apply(box_body3, -240, 0, 0); 96 ephysics_body_central_impulse_apply(box_body3, -240, 0, 0);
98 test_data->constraints = eina_list_append(test_data->constraints, 97 test_data->constraints = eina_list_append(test_data->constraints,
99 constraint); 98 constraint);
@@ -122,8 +121,8 @@ _world_populate(Test_Data *test_data)
122 ephysics_body_friction_set(box_body4, 0.1); 121 ephysics_body_friction_set(box_body4, 0.1);
123 test_data->bodies = eina_list_append(test_data->bodies, box_body4); 122 test_data->bodies = eina_list_append(test_data->bodies, box_body4);
124 123
125 constraint = ephysics_constraint_slider_add(box_body4); 124 constraint = ephysics_constraint_add(box_body4);
126 ephysics_constraint_slider_linear_limit_set(constraint, WIDTH / 3, 0, 0, 0); 125 ephysics_constraint_linear_limit_set(constraint, WIDTH / 3, 0, 0, 0, 0, 0);
127 ephysics_body_central_impulse_apply(box_body4, -600, 0, 0); 126 ephysics_body_central_impulse_apply(box_body4, -600, 0, 0);
128 test_data->constraints = eina_list_append(test_data->constraints, 127 test_data->constraints = eina_list_append(test_data->constraints,
129 constraint); 128 constraint);
diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h
index f0c0b07e94..affac90c14 100644
--- a/legacy/ephysics/src/lib/EPhysics.h
+++ b/legacy/ephysics/src/lib/EPhysics.h
@@ -4397,123 +4397,192 @@ EAPI Eina_Bool ephysics_body_clockwise_get(const EPhysics_Body *body);
4397 * between bodies and the world. Constraints can limit movement angle, 4397 * between bodies and the world. Constraints can limit movement angle,
4398 * translation, or work like a motor. 4398 * translation, or work like a motor.
4399 * 4399 *
4400 * Constraints can be created with @ref ephysics_constraint_p2p_add() 4400 * Constraints can be created with @ref ephysics_constraint_linked_add()
4401 * or @ref ephysics_constraint_slider_add() and removed 4401 * or @ref ephysics_constraint_add() and removed
4402 * with @ref ephysics_constraint_del(). 4402 * with @ref ephysics_constraint_del().
4403 * Can be applied between two bodies or between a body and the world. 4403 * Can be applied between two bodies or between a body and the world.
4404 */ 4404 */
4405 4405
4406typedef struct _EPhysics_Constraint EPhysics_Constraint; /**< Constraint handle, used to limit bodies movements. Created with @ref ephysics_constraint_p2p_add() or @ref ephysics_constraint_slider_add() and deleted with @ref ephysics_constraint_del(). */ 4406typedef struct _EPhysics_Constraint EPhysics_Constraint; /**< Constraint handle, used to limit bodies movements. Created with @ref ephysics_constraint_linked_add() or @ref ephysics_constraint_add() and deleted with @ref ephysics_constraint_del(). */
4407 4407
4408/** 4408/**
4409 * @brief 4409 * @brief
4410 * Create a new constraint between 2 bodies(Point to Point constraint). 4410 * Create a new constraint between 2 bodies(Point to Point constraint).
4411 * 4411 *
4412 * The constraint will join two bodies(@p body1 and @p body2) limiting their 4412 * The constraint will join two bodies(@p body1 and @p body2) with angular and
4413 * movements based on specified anchors. 4413 * linear movements limited by calling ephysics_constraint_linear_limit_set()
4414 * and ephysics_constraint_angular_limit_set(). Anchors values can be defined
4415 * with ephysics_constraint_anchor_set().
4414 * 4416 *
4415 * @param body1 The first body to apply the constraint. 4417 * @param body1 The first body to apply the constraint.
4416 * @param body2 The second body to apply the constraint. 4418 * @param body2 The second body to apply the constraint.
4419 * @return A new linked(joining 2 bodies) constraint or @c NULL, on errors.
4420 *
4421 * @see ephysics_constraint_del().
4422 *
4423 * @ingroup EPhysics_Constraint
4424 */
4425EAPI EPhysics_Constraint *ephysics_constraint_linked_add(EPhysics_Body *body1, EPhysics_Body *body2);
4426
4427/**
4428 * @brief
4429 * Change the constraints anchors values on both constrained bodies.
4430 *
4431 * @note By default the anchors are in the middle of a body, if a body of 20, 20
4432 * is positioned at (10, 10) then its anchor is set to (20, 20).
4433 *
4434 * @note There`s no need to inform @p anchor_b2_x, @p anchor_b2_y and @p
4435 * anchor_b2_z if the constraint has been created using
4436 * ephysics_constraint_add().
4437 *
4438 * @param constraint The constraint to be set.
4417 * @param anchor_b1_x The first body X anchor. 4439 * @param anchor_b1_x The first body X anchor.
4418 * @param anchor_b1_y The fist body Y anchor. 4440 * @param anchor_b1_y The first body Y anchor.
4441 * @param anchor_b1_z The first body Z anchor.
4419 * @param anchor_b2_x The second body X anchor. 4442 * @param anchor_b2_x The second body X anchor.
4420 * @param anchor_b2_y The second body Y anchor. 4443 * @param anchor_b2_y The second body Y anchor.
4421 * @return A new p2p(point to point) constraint or @c NULL, on errors. 4444 * @param anchor_b2_z The second body Z anchor.
4422 * 4445 *
4423 * @see ephysics_constraint_del(). 4446 * @see ephysics_constraint_anchor_get().
4447 * @see ephysics_constraint_linked_add().
4424 * 4448 *
4425 * @ingroup EPhysics_Constraint 4449 * @ingroup EPhysics_Constraint
4426 */ 4450 */
4427EAPI EPhysics_Constraint *ephysics_constraint_p2p_add(EPhysics_Body *body1, EPhysics_Body *body2, Evas_Coord anchor_b1_x, Evas_Coord anchor_b1_y, Evas_Coord anchor_b2_x, Evas_Coord anchor_b2_y); 4451EAPI void ephysics_constraint_anchor_set(EPhysics_Constraint *constraint, Evas_Coord anchor_b1_x, Evas_Coord anchor_b1_y, Evas_Coord anchor_b1_z, Evas_Coord anchor_b2_x, Evas_Coord anchor_b2_y, Evas_Coord anchor_b2_z);
4428 4452
4429/** 4453/**
4430 * @brief 4454 * @brief
4431 * Create a new slider constraint. 4455 * Get the constraints anchors values on both constrained bodies.
4432 * 4456 *
4433 * The constraint will limit the linear and angular moving of a body. 4457 * @param constraint The constraint to get anchor values from.
4458 * @param anchor_b1_x Pointer to an Evas_Coord in which to store the first body
4459 * X anchor value.
4460 * @param anchor_b1_y Pointer to an Evas_Coord in which to store the first body
4461 * Y anchor value.
4462 * @param anchor_b1_z Pointer to an Evas_Coord in which to store the first body
4463 * Z anchor value.
4464 * @param anchor_b2_x Pointer to an Evas_Coord in which to store the second body
4465 * X anchor value.
4466 * @param anchor_b2_y Pointer to an Evas_Coord in which to store the second body
4467 * Y anchor value.
4468 * @param anchor_b2_z Pointer to an Evas_Coord in which to store the second body
4469 * Z anchor value.
4470 *
4471 * @see ephysics_constraint_anchor_set().
4472 * @see ephysics_constraint_linked_add().
4473 *
4474 * @ingroup EPhysics_Constraint
4475 */
4476EAPI void ephysics_constraint_anchor_get(const EPhysics_Constraint *constraint, Evas_Coord *anchor_b1_x, Evas_Coord *anchor_b1_y, Evas_Coord *anchor_b1_z, Evas_Coord *anchor_b2_x, Evas_Coord *anchor_b2_y, Evas_Coord *anchor_b2_z);
4477
4478/**
4479 * @brief
4480 * Create a new constraint.
4481 *
4482 * The constraint will limit the linear and angular moving of a body. This simple
4483 * constraint is designated to constraint a single body.
4434 * 4484 *
4435 * @param body The body to apply the constraint. 4485 * @param body The body to apply the constraint.
4436 * 4486 *
4437 * @see ephysics_constraint_slider_linear_limit_set() for linear moving limit 4487 * @see ephysics_constraint_linear_limit_set() for linear moving limit
4438 * configuration. 4488 * configuration.
4439 * @see ephysics_constraint_slider_angular_limit_set() for angular moving limit 4489 * @see ephysics_constraint_angular_limit_set() for angular moving limit
4440 * configuration. 4490 * configuration.
4441 * @return A new slider constraint or @c NULL on erros. 4491 * @return A new constraint or @c NULL on erros.
4442 * 4492 *
4443 * @see ephysics_constraint_del(). 4493 * @see ephysics_constraint_del().
4444 * 4494 *
4445 * @ingroup EPhysics_Constraint 4495 * @ingroup EPhysics_Constraint
4446 */ 4496 */
4447EAPI EPhysics_Constraint *ephysics_constraint_slider_add(EPhysics_Body *body); 4497EAPI EPhysics_Constraint *ephysics_constraint_add(EPhysics_Body *body);
4448 4498
4449/** 4499/**
4450 * @brief 4500 * @brief
4451 * Define the linear moving limits of a slider @p constraint. 4501 * Define the linear moving limits of a @p constraint.
4452 * 4502 *
4453 * The linear limits are defined from the body's position on. The user will 4503 * The linear limits are defined from the body's position on. The user will
4454 * want to limit the movements to the left, right, under and above the rigid 4504 * want to limit the movements on X, Y and Z axis where lower == upper axis
4455 * body. The unit for every limits are defined on Evas coordinates. 4505 * will be locked, lower > upper axis is free, lower < upper axis is limited to
4506 * the range.
4507 *
4508 * The unit for every limits are defined on Evas coordinates.
4456 * 4509 *
4457 * @param constraint The constraint to be set. 4510 * @param constraint The constraint to be set.
4458 * @param left_x The moving limit to the left on X axis - from the body's 4511 * @param lower_x The lower linear moving limit on X axis.
4459 * position on. 4512 * @param upper_x The upper linear moving limit on X axis.
4460 * @param under_y The moving limit down on Y axis - from the body's position 4513 * @param lower_y The lower linear moving limit on Y axis.
4461 * on. 4514 * @param upper_y The upper linear moving limit on Y axis.
4462 * @param right_x The moving limit to the right on X axis - from the body's 4515 * @param lower_z The lower linear moving limit on Z axis.
4463 * position on. 4516 * @param upper_z The upper linear moving limit on Z axis.
4464 * @param above_y The moving limit up on Y axis - from the body's position on. 4517 *
4465 * 4518 *
4466 * @see ephysics_constraint_slider_linear_limit_get() 4519 * @see ephysics_constraint_linear_limit_get()
4467 * @ingroup EPhysics_Constraint 4520 * @ingroup EPhysics_Constraint
4468 */ 4521 */
4469EAPI void ephysics_constraint_slider_linear_limit_set(EPhysics_Constraint *constraint, Evas_Coord left_x, Evas_Coord under_y, Evas_Coord right_x, Evas_Coord above_y); 4522EAPI void ephysics_constraint_linear_limit_set(EPhysics_Constraint *constraint, Evas_Coord lower_x, Evas_Coord upper_x, Evas_Coord lower_y, Evas_Coord upper_y, Evas_Coord lower_z, Evas_Coord upper_z);
4470 4523
4471/** 4524/**
4472 * @brief 4525 * @brief
4473 * Get the linear moving limits of a slider constraint. 4526 * Get the linear moving limits of a @p constraint.
4474 * 4527 *
4475 * @param constraint The constraint to get linear limits from. 4528 * @param constraint The constraint to get linear limits from.
4476 * @param left_x Pointer to set with the limit to the left on X axis. 4529 * @param lower_x Pointer to set with the lower limit to the X axis.
4477 * @param under_y Pointer to set with the limit down on Y axis. 4530 * @param upper_x Pointer to set with the upper limit to the X axis.
4478 * @param right_x Pointer to set with the limit to the right on X axis. 4531 * @param lower_y Pointer to set with the lower limit to the Y axis.
4479 * @param above_y Pointer to set with the limit up on Y axis. 4532 * @param upper_y Pointer to set with the upper limit to the Y axis.
4480 * 4533 * @param lower_z Pointer to set with the lower limit to the Z axis.
4481 * @see ephysics_constraint_slider_linear_limit_set() 4534 * @param upper_z Pointer to set with the upper limit to the Z axis.
4535 *
4536 * @see ephysics_constraint_linear_limit_set()
4482 * @ingroup EPhysics_Constraint 4537 * @ingroup EPhysics_Constraint
4483 */ 4538 */
4484EAPI void ephysics_constraint_slider_linear_limit_get(const EPhysics_Constraint *constraint, Evas_Coord *left_x, Evas_Coord *under_y, Evas_Coord *right_x, Evas_Coord *above_y); 4539EAPI void ephysics_constraint_linear_limit_get(const EPhysics_Constraint *constraint, Evas_Coord *lower_x, Evas_Coord *upper_x, Evas_Coord *lower_y, Evas_Coord *upper_y, Evas_Coord *lower_z, Evas_Coord *upper_z);
4485 4540
4486/** 4541/**
4487 * @brief 4542 * @brief
4488 * Set the angular moving limits of a slider @p constraint. 4543 * Set the angular moving limits of a @p constraint.
4489 * 4544 *
4490 * The angular moving limits is defined in degrees and will limit the moving on 4545 * The angular moving limits is defined in degrees and will limit the moving on
4491 * Z axis - counter clockwise and clockwise directions. 4546 * Z axis - counter clockwise and clockwise directions.
4492 * 4547 *
4493 * @param constraint The constraint to be set. 4548 * @param constraint The constraint to be set.
4549 * @param counter_clock_x Amount of degrees from 0.0 to 360.0 to limit counter
4550 * clockwise rotation on X axis.
4551 * @param clock_wise_x Amount of degrees from 0.0 to 360.0 to limit clockwise
4552 * rotation on X axis.
4553 * @param counter_clock_y Amount of degrees from 0.0 to 360.0 to limit counter
4554 * clockwise rotation o Y axis.
4555 * @param clock_wise_y Amount of degrees from 0.0 to 360.0 to limit clockwise
4556 * rotation on Y axis.
4494 * @param counter_clock_z Amount of degrees from 0.0 to 360.0 to limit 4557 * @param counter_clock_z Amount of degrees from 0.0 to 360.0 to limit
4495 * counter clockwise rotation. 4558 * counter clockwise rotation on Z axis.
4496 * @param clock_wise_z Amount of degrees from 0.0 to 360.0 to limit clockwise 4559 * @param clock_wise_z Amount of degrees from 0.0 to 360.0 to limit clockwise
4497 * rotation. 4560 * rotation on Z axis.
4498 * 4561 *
4499 * @see ephysics_constraint_slider_angular_limit_get() 4562 * @see ephysics_constraint_angular_limit_get()
4500 * @ingroup EPhysics_Constraint 4563 * @ingroup EPhysics_Constraint
4501 */ 4564 */
4502EAPI void ephysics_constraint_slider_angular_limit_set(EPhysics_Constraint *constraint, double counter_clock_z, double clock_wise_z); 4565EAPI void ephysics_constraint_angular_limit_set(EPhysics_Constraint *constraint, double counter_clock_x, double clock_wise_x, double counter_clock_y, double clock_wise_y, double counter_clock_z, double clock_wise_z);
4503 4566
4504/** 4567/**
4505 * @brief 4568 * @brief
4506 * Get the angular moving limits of a slider @p constraint. 4569 * Get the angular moving limits of a @p constraint.
4507 * 4570 *
4508 * @param constraint The constraint to get the angular limits from. 4571 * @param constraint The constraint to get the angular limits from.
4572 * @param counter_clock_x Pointer to set with the counter clockwise limmit
4573 * degrees on X axis.
4574 * @param clock_wise_x Pointer to set with the clockwise limit degrees on X axis.
4575 * @param counter_clock_y Pointer to set with the counter clockwise limit
4576 * degrees on Y axis.
4577 * @param clock_wise_y Pointer to set with the clockwise limit degrees on Y axis.
4509 * @param counter_clock_z Pointer to set with the counter clockwise limit 4578 * @param counter_clock_z Pointer to set with the counter clockwise limit
4510 * degrees. 4579 * degrees on Z axis.
4511 * @param clock_wise_z Pointer to set with the clockwise limit degrees. 4580 * @param clock_wise_z Pointer to set with the clockwise limit degrees on Z axis.
4512 * 4581 *
4513 * @see ephysics_constraint_slider_angular_limit_set() 4582 * @see ephysics_constraint_angular_limit_set()
4514 * @ingroup EPhysics_Constraint 4583 * @ingroup EPhysics_Constraint
4515 */ 4584 */
4516EAPI void ephysics_constraint_slider_angular_limit_get(const EPhysics_Constraint *constraint, double *counter_clock_z, double *clock_wise_z); 4585EAPI void ephysics_constraint_angular_limit_get(const EPhysics_Constraint *constraint, double *counter_clock_x, double *clock_wise_x, double *counter_clock_y, double *clock_wise_y, double *counter_clock_z, double *clock_wise_z);
4517 4586
4518/** 4587/**
4519 * @brief 4588 * @brief
@@ -4521,7 +4590,7 @@ EAPI void ephysics_constraint_slider_angular_limit_get(const EPhysics_Constraint
4521 * 4590 *
4522 * @param constraint The constraint to be deleted. 4591 * @param constraint The constraint to be deleted.
4523 * 4592 *
4524 * @see ephysics_constraint_p2p_add() for more details. 4593 * @see ephysics_constraint_linked_add() for more details.
4525 * @see ephysics_constraint_slider_add() for more details. 4594 * @see ephysics_constraint_slider_add() for more details.
4526 * 4595 *
4527 * @ingroup EPhysics_Constraint 4596 * @ingroup EPhysics_Constraint
diff --git a/legacy/ephysics/src/lib/ephysics_constraints.cpp b/legacy/ephysics/src/lib/ephysics_constraints.cpp
index ed5c5c8411..f97af58659 100644
--- a/legacy/ephysics/src/lib/ephysics_constraints.cpp
+++ b/legacy/ephysics/src/lib/ephysics_constraints.cpp
@@ -8,107 +8,67 @@
8extern "C" { 8extern "C" {
9#endif 9#endif
10 10
11typedef enum _EPhysics_Constraint_Type {
12 EPHYSICS_CONSTRAINT_P2P,
13 EPHYSICS_CONSTRAINT_SLIDER,
14} EPhysics_Constraint_Type;
15
16struct _EPhysics_Constraint { 11struct _EPhysics_Constraint {
17 btTypedConstraint *bt_constraint; 12 btGeneric6DofConstraint *bt_constraint;
18 EPhysics_World *world; 13 EPhysics_World *world;
19 EPhysics_Constraint_Type type; 14 EPhysics_Body *bodies[2];
20 struct {
21 EPhysics_Body *body1;
22 EPhysics_Body *body2;
23 Evas_Coord anchor_b1_x;
24 Evas_Coord anchor_b1_y;
25 Evas_Coord anchor_b2_x;
26 Evas_Coord anchor_b2_y;
27 } p2p;
28}; 15};
29 16
30/* FIXME: it shouldn't be this way. 17static void
31 * All constraints should be generic and have all these options 18_ephysics_constraint_linear_limit_get(const EPhysics_Constraint *constraint, Evas_Coord *lower_x, Evas_Coord *upper_x, Evas_Coord *lower_y, Evas_Coord *upper_y, Evas_Coord *lower_z, Evas_Coord *upper_z, double rate)
32 * set after add().
33 */
34static Eina_Bool
35_ephysics_constraint_p2p_set(EPhysics_Constraint *constraint, double rate)
36{ 19{
37 if (!constraint->p2p.body2) 20 btVector3 linear_limit;
38 constraint->bt_constraint = new btPoint2PointConstraint(
39 *ephysics_body_rigid_body_get(constraint->p2p.body1),
40 btVector3(constraint->p2p.anchor_b1_x / rate,
41 constraint->p2p.anchor_b1_y / rate, 0));
42 else
43 constraint->bt_constraint = new btPoint2PointConstraint(
44 *ephysics_body_rigid_body_get(constraint->p2p.body1),
45 *ephysics_body_rigid_body_get(constraint->p2p.body2),
46 btVector3(constraint->p2p.anchor_b1_x / rate,
47 constraint->p2p.anchor_b1_y / rate, 0),
48 btVector3(constraint->p2p.anchor_b2_x / rate,
49 constraint->p2p.anchor_b2_y / rate, 0));
50 21
51 if (!constraint->bt_constraint) 22 if (lower_x || lower_y || lower_z)
52 { 23 {
53 ERR("Failed to create a btConstraint"); 24 constraint->bt_constraint->getLinearLowerLimit(linear_limit);
54 free(constraint);
55 return EINA_FALSE;
56 }
57
58 constraint->type = EPHYSICS_CONSTRAINT_P2P;
59 ephysics_world_constraint_add(constraint->world, constraint,
60 constraint->bt_constraint);
61 25
62 return EINA_TRUE; 26 if (lower_x) *lower_x = linear_limit.getX() * rate;
63} 27 if (lower_y) *lower_y = linear_limit.getY() * rate;
28 if (lower_z) *lower_z = linear_limit.getZ() * rate;
29 }
64 30
65static void 31 if (upper_x || upper_y || upper_z)
66_ephysics_constraint_p2p_recalc(EPhysics_Constraint *constraint, double rate) 32 {
67{ 33 constraint->bt_constraint->getLinearUpperLimit(linear_limit);
68 ephysics_world_constraint_del(constraint->world, constraint,
69 constraint->bt_constraint);
70 delete constraint->bt_constraint;
71 34
72 _ephysics_constraint_p2p_set(constraint, rate); 35 if (upper_x) *upper_x = linear_limit.getX() * rate;
36 if (upper_y) *upper_y = linear_limit.getY() * rate;
37 if (upper_z) *upper_z = linear_limit.getZ() * rate;
38 }
73} 39}
74 40
75static void 41static void
76_ephysics_constraint_slider_linear_limit_set(EPhysics_Constraint *constraint, Evas_Coord left_x, Evas_Coord under_y, Evas_Coord right_x, Evas_Coord above_y, double rate) 42_ephysics_constraint_linear_limit_set(EPhysics_Constraint *constraint, Evas_Coord lower_x, Evas_Coord upper_x, Evas_Coord lower_y, Evas_Coord upper_y, Evas_Coord lower_z, Evas_Coord upper_z, double rate)
77{ 43{
78 btGeneric6DofConstraint *slider_constraint; 44 lower_x = (lower_x) / rate;
79 45 upper_x = (upper_x) / rate;
80 slider_constraint = (btGeneric6DofConstraint *)constraint->bt_constraint;
81 rate = ephysics_world_rate_get(constraint->world);
82 46
83 left_x = (left_x) / rate; 47 lower_y = (lower_y) / rate;
84 right_x = (right_x) / rate; 48 upper_y = (upper_y) / rate;
85 49
86 under_y = (under_y) / rate; 50 lower_z = (lower_z) / rate;
87 above_y = (above_y) / rate; 51 upper_z = (upper_z) / rate;
88 52
89 slider_constraint->setLinearLowerLimit(btVector3(-left_x, -under_y, 0)); 53 constraint->bt_constraint->setLinearLowerLimit(btVector3(-lower_x, -upper_y,
90 slider_constraint->setLinearUpperLimit(btVector3(right_x, above_y, 0)); 54 -lower_z));
55 constraint->bt_constraint->setLinearUpperLimit(btVector3(upper_x, upper_y,
56 upper_z));
91} 57}
92 58
93void 59void
94ephysics_constraint_recalc(EPhysics_Constraint *constraint, double rate) 60ephysics_constraint_recalc(EPhysics_Constraint *constraint, double rate)
95{ 61{
96 Evas_Coord left_x, under_y, right_x, above_y; 62 Evas_Coord lower_x, upper_x, lower_y, upper_y, lower_z, upper_z;
97 63
98 if (constraint->type == EPHYSICS_CONSTRAINT_P2P) 64 _ephysics_constraint_linear_limit_get(constraint, &lower_x, &upper_x,
99 { 65 &lower_y, &upper_y, &lower_z, &upper_z, rate);
100 _ephysics_constraint_p2p_recalc(constraint, rate); 66 _ephysics_constraint_linear_limit_set(constraint, lower_x, upper_x, lower_y,
101 return; 67 upper_y, lower_z, upper_z, rate);
102 }
103
104 ephysics_constraint_slider_linear_limit_get(constraint, &left_x, &under_y,
105 &right_x, &above_y);
106 _ephysics_constraint_slider_linear_limit_set(constraint, left_x, under_y,
107 right_x, above_y, rate);
108} 68}
109 69
110EAPI EPhysics_Constraint * 70EAPI EPhysics_Constraint *
111ephysics_constraint_slider_add(EPhysics_Body *body) 71ephysics_constraint_add(EPhysics_Body *body)
112{ 72{
113 EPhysics_Constraint *constraint; 73 EPhysics_Constraint *constraint;
114 btTransform trans; 74 btTransform trans;
@@ -119,13 +79,6 @@ ephysics_constraint_slider_add(EPhysics_Body *body)
119 return NULL; 79 return NULL;
120 } 80 }
121 81
122 if (body->type == EPHYSICS_BODY_TYPE_CLOTH)
123 {
124 ERR("Constraints are allowed only between rigid -> rigid bodies or "
125 "rigid -> soft bodies");
126 return NULL;
127 }
128
129 constraint = (EPhysics_Constraint *) calloc(1, sizeof(EPhysics_Constraint)); 82 constraint = (EPhysics_Constraint *) calloc(1, sizeof(EPhysics_Constraint));
130 if (!constraint) 83 if (!constraint)
131 { 84 {
@@ -135,6 +88,7 @@ ephysics_constraint_slider_add(EPhysics_Body *body)
135 88
136 ephysics_world_lock_take(ephysics_body_world_get(body)); 89 ephysics_world_lock_take(ephysics_body_world_get(body));
137 trans.setIdentity(); 90 trans.setIdentity();
91 trans.setOrigin(btVector3(0, 0, 0));
138 constraint->bt_constraint = new 92 constraint->bt_constraint = new
139 btGeneric6DofConstraint(*ephysics_body_rigid_body_get(body), trans, 93 btGeneric6DofConstraint(*ephysics_body_rigid_body_get(body), trans,
140 false); 94 false);
@@ -146,7 +100,7 @@ ephysics_constraint_slider_add(EPhysics_Body *body)
146 return NULL; 100 return NULL;
147 } 101 }
148 102
149 constraint->type = EPHYSICS_CONSTRAINT_SLIDER; 103 constraint->bodies[0] = body;
150 constraint->world = ephysics_body_world_get(body); 104 constraint->world = ephysics_body_world_get(body);
151 ephysics_world_constraint_add(constraint->world, constraint, 105 ephysics_world_constraint_add(constraint->world, constraint,
152 constraint->bt_constraint); 106 constraint->bt_constraint);
@@ -157,32 +111,26 @@ ephysics_constraint_slider_add(EPhysics_Body *body)
157} 111}
158 112
159EAPI void 113EAPI void
160ephysics_constraint_slider_linear_limit_set(EPhysics_Constraint *constraint, Evas_Coord left_x, Evas_Coord under_y, Evas_Coord right_x, Evas_Coord above_y) 114ephysics_constraint_linear_limit_set(EPhysics_Constraint *constraint, Evas_Coord lower_x, Evas_Coord upper_x, Evas_Coord lower_y, Evas_Coord upper_y, Evas_Coord lower_z, Evas_Coord upper_z)
161{ 115{
116 double rate;
117
162 if (!constraint) 118 if (!constraint)
163 { 119 {
164 ERR("Can't set constraint's linear limit, constraint is null."); 120 ERR("Can't set constraint's linear limit, constraint is null.");
165 return; 121 return;
166 } 122 }
167 123
168 if (constraint->type != EPHYSICS_CONSTRAINT_SLIDER)
169 {
170 ERR("Can't set linear limit, this is not an slider constraint.");
171 return;
172 }
173
174 ephysics_world_lock_take(constraint->world); 124 ephysics_world_lock_take(constraint->world);
175 _ephysics_constraint_slider_linear_limit_set( 125 rate = ephysics_world_rate_get(constraint->world);
176 constraint, left_x, under_y, right_x, above_y, 126 _ephysics_constraint_linear_limit_set(constraint, lower_x, upper_x, lower_y,
177 ephysics_world_rate_get(constraint->world)); 127 upper_y, lower_z, upper_z, rate);
178 ephysics_world_lock_release(constraint->world); 128 ephysics_world_lock_release(constraint->world);
179} 129}
180 130
181EAPI void 131EAPI void
182ephysics_constraint_slider_linear_limit_get(const EPhysics_Constraint *constraint, Evas_Coord *left_x, Evas_Coord *under_y, Evas_Coord *right_x, Evas_Coord *above_y) 132ephysics_constraint_linear_limit_get(const EPhysics_Constraint *constraint, Evas_Coord *lower_x, Evas_Coord *upper_x, Evas_Coord *lower_y, Evas_Coord *upper_y, Evas_Coord *lower_z, Evas_Coord *upper_z)
183{ 133{
184 btGeneric6DofConstraint *slider_constraint;
185 btVector3 linear_limit;
186 int rate; 134 int rate;
187 135
188 if (!constraint) 136 if (!constraint)
@@ -191,31 +139,14 @@ ephysics_constraint_slider_linear_limit_get(const EPhysics_Constraint *constrain
191 return; 139 return;
192 } 140 }
193 141
194 if (constraint->type != EPHYSICS_CONSTRAINT_SLIDER)
195 {
196 ERR("Can't get linear limit, this is not an slider constraint.");
197 return;
198 }
199
200 rate = ephysics_world_rate_get(constraint->world); 142 rate = ephysics_world_rate_get(constraint->world);
201 slider_constraint = (btGeneric6DofConstraint *)constraint->bt_constraint; 143 _ephysics_constraint_linear_limit_get(constraint, lower_x, upper_x, lower_y,
202 if (left_x || under_y) 144 upper_y, lower_z, upper_z, rate);
203 slider_constraint->getLinearLowerLimit(linear_limit);
204
205 if (left_x) *left_x = linear_limit.getX() * rate;
206 if (under_y) *under_y = linear_limit.getY() * rate;
207
208 if (right_x || above_y)
209 slider_constraint->getLinearUpperLimit(linear_limit);
210
211 if (right_x) *right_x = linear_limit.getX() * rate;
212 if (above_y) *above_y = linear_limit.getY() * rate;
213} 145}
214 146
215EAPI void 147EAPI void
216ephysics_constraint_slider_angular_limit_set(EPhysics_Constraint *constraint, double counter_clock_z, double clock_wise_z) 148ephysics_constraint_angular_limit_set(EPhysics_Constraint *constraint, double counter_clock_x, double clock_wise_x, double counter_clock_y, double clock_wise_y, double counter_clock_z, double clock_wise_z)
217{ 149{
218 btGeneric6DofConstraint *slider_constraint;
219 150
220 if (!constraint) 151 if (!constraint)
221 { 152 {
@@ -223,25 +154,20 @@ ephysics_constraint_slider_angular_limit_set(EPhysics_Constraint *constraint, do
223 return; 154 return;
224 } 155 }
225 156
226 if (constraint->type != EPHYSICS_CONSTRAINT_SLIDER)
227 {
228 ERR("Can't set angular limit, this is not an slider constraint.");
229 return;
230 }
231
232 ephysics_world_lock_take(constraint->world); 157 ephysics_world_lock_take(constraint->world);
233 slider_constraint = (btGeneric6DofConstraint *)constraint->bt_constraint; 158
234 slider_constraint->setAngularLowerLimit(btVector3(0, 0, 159 constraint->bt_constraint->setAngularLowerLimit(btVector3(
235 -counter_clock_z/RAD_TO_DEG)); 160 -counter_clock_x / RAD_TO_DEG, -counter_clock_y / RAD_TO_DEG,
236 slider_constraint->setAngularUpperLimit(btVector3(0, 0, 161 -counter_clock_z/RAD_TO_DEG));
237 clock_wise_z/RAD_TO_DEG)); 162 constraint->bt_constraint->setAngularUpperLimit(btVector3(
163 clock_wise_x / RAD_TO_DEG, clock_wise_y / RAD_TO_DEG,
164 clock_wise_z/RAD_TO_DEG));
238 ephysics_world_lock_release(constraint->world); 165 ephysics_world_lock_release(constraint->world);
239} 166}
240 167
241EAPI void 168EAPI void
242ephysics_constraint_slider_angular_limit_get(const EPhysics_Constraint *constraint, double *counter_clock_z, double *clock_wise_z) 169ephysics_constraint_angular_limit_get(const EPhysics_Constraint *constraint, double *counter_clock_x, double *clock_wise_x, double *counter_clock_y, double *clock_wise_y, double *counter_clock_z, double *clock_wise_z)
243{ 170{
244 btGeneric6DofConstraint *slider_constraint;
245 btVector3 angular_limit; 171 btVector3 angular_limit;
246 172
247 if (!constraint) 173 if (!constraint)
@@ -250,39 +176,148 @@ ephysics_constraint_slider_angular_limit_get(const EPhysics_Constraint *constrai
250 return; 176 return;
251 } 177 }
252 178
253 if (constraint->type != EPHYSICS_CONSTRAINT_SLIDER) 179 if (counter_clock_x)
254 { 180 {
255 ERR("Can't get angular limit, this is not an slider constraint."); 181 constraint->bt_constraint->getAngularLowerLimit(angular_limit);
256 return; 182 *counter_clock_x = angular_limit.getX() * RAD_TO_DEG;
183 }
184
185 if (clock_wise_x)
186 {
187 constraint->bt_constraint->getAngularUpperLimit(angular_limit);
188 *clock_wise_x = angular_limit.getX() * RAD_TO_DEG;
189 }
190
191 if (counter_clock_y)
192 {
193 constraint->bt_constraint->getAngularLowerLimit(angular_limit);
194 *counter_clock_y = angular_limit.getY() * RAD_TO_DEG;
195 }
196
197 if (clock_wise_y)
198 {
199 constraint->bt_constraint->getAngularUpperLimit(angular_limit);
200 *clock_wise_y = angular_limit.getY() * RAD_TO_DEG;
257 } 201 }
258 202
259 slider_constraint = (btGeneric6DofConstraint *)constraint->bt_constraint;
260 if (counter_clock_z) 203 if (counter_clock_z)
261 { 204 {
262 slider_constraint->getAngularLowerLimit(angular_limit); 205 constraint->bt_constraint->getAngularLowerLimit(angular_limit);
263 *counter_clock_z = angular_limit.getZ(); 206 *counter_clock_z = angular_limit.getZ() * RAD_TO_DEG;
264 } 207 }
265 208
266 if (clock_wise_z) 209 if (clock_wise_z)
267 { 210 {
268 slider_constraint->getAngularUpperLimit(angular_limit); 211 constraint->bt_constraint->getAngularUpperLimit(angular_limit);
269 *clock_wise_z = angular_limit.getZ(); 212 *clock_wise_z = angular_limit.getZ() * RAD_TO_DEG;
213 }
214}
215
216EAPI void
217ephysics_constraint_anchor_set(EPhysics_Constraint *constraint, Evas_Coord anchor_b1_x, Evas_Coord anchor_b1_y, Evas_Coord anchor_b1_z, Evas_Coord anchor_b2_x, Evas_Coord anchor_b2_y, Evas_Coord anchor_b2_z)
218{
219 btTransform anchor_b1;
220 btTransform anchor_b2;
221 btTransform center_mass;
222 double rate;
223 Evas_Coord b1x, b1y, b1z, b1w, b1h, b1d, b2x, b2y, b2z, b2w, b2h, b2d, wx, wy,
224 wh;
225 btScalar ab1x, ab1y, ab1z, ab2x, ab2y, ab2z;
226
227 if (!constraint)
228 {
229 ERR("Can't set constraint's anchors, constraint is null.");
230 return;
231 }
232
233 ephysics_world_lock_take(constraint->world);
234
235 ephysics_world_render_geometry_get(constraint->world, &wx, &wy, NULL, NULL,
236 &wh, NULL);
237
238 ephysics_body_geometry_get(constraint->bodies[0], &b1x, &b1y, &b1z, &b1w,
239 &b1h, &b1d);
240
241 rate = ephysics_world_rate_get(constraint->world);
242
243 ab1x = (anchor_b1_x - (b1x + b1w / 2)) / rate;
244 ab1y = (anchor_b1_y - (b1y + b1h / 2)) / rate;
245 ab1z = (anchor_b1_z - (b1z + b1d / 2)) / rate;
246 DBG("body1 anchor set to: %lf, %lf, %lf", ab1x, ab1y, ab1z);
247
248 anchor_b1.setIdentity();
249 anchor_b1.setOrigin(btVector3(ab1x, ab1y, ab1z));
250
251 if (constraint->bodies[1])
252 {
253 ephysics_body_geometry_get(constraint->bodies[1], &b2x, &b2y, &b2z, &b2w,
254 &b2h, &b2d);
255
256 ab2x = (anchor_b2_x - (b2x + b2w / 2)) / rate;
257 ab2y = (anchor_b2_y - (b2y + b2h / 2)) / rate;
258 ab2z = (anchor_b2_z - (b2z + b2d / 2)) / rate;
259
260 DBG("body2 anchor set to: %lf, %lf, %lf", ab2x, ab2y, ab2z);
261
262 anchor_b2.setIdentity();
263 anchor_b2.setOrigin(btVector3(ab2x, ab2y, ab2z));
264 }
265 else
266 {
267 anchor_b2.setIdentity();
268 anchor_b2.setOrigin(btVector3(anchor_b1.getOrigin().x(),
269 anchor_b1.getOrigin().y(),
270 anchor_b1.getOrigin().z()));
271
272 center_mass = constraint->bodies[0]->rigid_body->
273 getCenterOfMassTransform();
274
275 anchor_b1.setIdentity();
276 anchor_b1 = center_mass * anchor_b2;
270 } 277 }
278
279 constraint->bt_constraint->setFrames(anchor_b1, anchor_b2);
280 ephysics_world_lock_release(constraint->world);
281}
282
283EAPI void
284ephysics_constraint_anchor_get(const EPhysics_Constraint *constraint, Evas_Coord *anchor_b1_x, Evas_Coord *anchor_b1_y, Evas_Coord *anchor_b1_z, Evas_Coord *anchor_b2_x, Evas_Coord *anchor_b2_y, Evas_Coord *anchor_b2_z)
285{
286 btTransform anchor_b1;
287 btTransform anchor_b2;
288 double rate;
289
290 if (!constraint)
291 {
292 ERR("Can't set constraint's anchors, constraint is null.");
293 return;
294 }
295
296 rate = ephysics_world_rate_get(constraint->world);
297
298 anchor_b1 = constraint->bt_constraint->getFrameOffsetA();
299 anchor_b2 = constraint->bt_constraint->getFrameOffsetB();
300
301 if (anchor_b1_x) *anchor_b1_x = round(anchor_b1.getOrigin().x() * rate);
302 if (anchor_b1_y) *anchor_b1_y = round(anchor_b1.getOrigin().y() * rate);
303 if (anchor_b1_z) *anchor_b1_z = round(anchor_b1.getOrigin().z() * rate);
304 if (anchor_b2_x) *anchor_b2_x = round(anchor_b2.getOrigin().x() * rate);
305 if (anchor_b2_y) *anchor_b2_y = round(anchor_b2.getOrigin().y() * rate);
306 if (anchor_b2_z) *anchor_b2_z = round(anchor_b2.getOrigin().z() * rate);
271} 307}
272 308
273EAPI EPhysics_Constraint * 309EAPI EPhysics_Constraint *
274ephysics_constraint_p2p_add(EPhysics_Body *body1, EPhysics_Body *body2, Evas_Coord anchor_b1_x, Evas_Coord anchor_b1_y, Evas_Coord anchor_b2_x, Evas_Coord anchor_b2_y) 310ephysics_constraint_linked_add(EPhysics_Body *body1, EPhysics_Body *body2)
275{ 311{
276 EPhysics_Constraint *constraint; 312 EPhysics_Constraint *constraint;
277 313
278 if (!body1) 314 if (!body1 || !body2)
279 { 315 {
280 ERR("To create a constraint body1 must to be non null."); 316 ERR("To create a linked constraint body1 and bod2 must to be non null.");
281 return NULL; 317 return NULL;
282 } 318 }
283 319
284 if ((body2) && 320 if (ephysics_body_world_get(body1) != ephysics_body_world_get(body2))
285 (ephysics_body_world_get(body1) != ephysics_body_world_get(body2)))
286 { 321 {
287 ERR("To create a constraint both bodies must belong to the same" 322 ERR("To create a constraint both bodies must belong to the same"
288 "world."); 323 "world.");
@@ -305,23 +340,25 @@ ephysics_constraint_p2p_add(EPhysics_Body *body1, EPhysics_Body *body2, Evas_Coo
305 } 340 }
306 341
307 constraint->world = ephysics_body_world_get(body1); 342 constraint->world = ephysics_body_world_get(body1);
308 constraint->p2p.body1 = body1; 343 constraint->bodies[0] = body1;
309 constraint->p2p.body2 = body2; 344 constraint->bodies[1] = body2;
310 constraint->p2p.anchor_b1_x = anchor_b1_x;
311 constraint->p2p.anchor_b1_y = anchor_b1_y;
312 constraint->p2p.anchor_b2_x = anchor_b2_x;
313 constraint->p2p.anchor_b2_y = anchor_b2_y;
314 345
315 ephysics_world_lock_take(constraint->world); 346 ephysics_world_lock_take(constraint->world);
316 if (!_ephysics_constraint_p2p_set( 347
317 constraint, ephysics_world_rate_get(ephysics_body_world_get( 348 constraint->bt_constraint = new btGeneric6DofConstraint(
318 constraint->p2p.body1)))) 349 *ephysics_body_rigid_body_get(body1), *ephysics_body_rigid_body_get(body2),
350 btTransform(), btTransform(), false);
351
352 if (!constraint->bt_constraint)
319 { 353 {
320 ephysics_world_lock_release(constraint->world); 354 ephysics_world_lock_release(constraint->world);
321 free(constraint); 355 free(constraint);
322 return NULL; 356 return NULL;
323 } 357 }
324 358
359 ephysics_world_constraint_add(constraint->world, constraint,
360 constraint->bt_constraint);
361
325 ephysics_world_lock_release(constraint->world); 362 ephysics_world_lock_release(constraint->world);
326 INF("Constraint added."); 363 INF("Constraint added.");
327 return constraint; 364 return constraint;
diff --git a/legacy/ephysics/src/lib/ephysics_private.h b/legacy/ephysics/src/lib/ephysics_private.h
index 141edee503..818ec706b1 100644
--- a/legacy/ephysics/src/lib/ephysics_private.h
+++ b/legacy/ephysics/src/lib/ephysics_private.h
@@ -175,8 +175,8 @@ int ephysics_world_shutdown(void);
175Eina_Bool ephysics_world_body_add(EPhysics_World *world, EPhysics_Body *body); 175Eina_Bool ephysics_world_body_add(EPhysics_World *world, EPhysics_Body *body);
176Eina_Bool ephysics_world_body_del(EPhysics_World *world, EPhysics_Body *body); 176Eina_Bool ephysics_world_body_del(EPhysics_World *world, EPhysics_Body *body);
177Eina_Bool ephysics_world_soft_body_add(EPhysics_World *world, EPhysics_Body *body); 177Eina_Bool ephysics_world_soft_body_add(EPhysics_World *world, EPhysics_Body *body);
178void ephysics_world_constraint_add(EPhysics_World *world, EPhysics_Constraint *constraint, btTypedConstraint *bt_constraint); 178void ephysics_world_constraint_add(EPhysics_World *world, EPhysics_Constraint *constraint, btGeneric6DofConstraint *bt_constraint);
179void ephysics_world_constraint_del(EPhysics_World *world, EPhysics_Constraint *constraint, btTypedConstraint *bt_constraint); 179void ephysics_world_constraint_del(EPhysics_World *world, EPhysics_Constraint *constraint, btGeneric6DofConstraint *bt_constraint);
180void ephysics_body_world_boundaries_resize(EPhysics_World *world); 180void ephysics_body_world_boundaries_resize(EPhysics_World *world);
181void ephysics_world_boundary_set(EPhysics_World *world, EPhysics_World_Boundary boundary, EPhysics_Body *body); 181void ephysics_world_boundary_set(EPhysics_World *world, EPhysics_World_Boundary boundary, EPhysics_Body *body);
182EPhysics_Body *ephysics_world_boundary_get(const EPhysics_World *world, EPhysics_World_Boundary boundary); 182EPhysics_Body *ephysics_world_boundary_get(const EPhysics_World *world, EPhysics_World_Boundary boundary);
diff --git a/legacy/ephysics/src/lib/ephysics_world.cpp b/legacy/ephysics/src/lib/ephysics_world.cpp
index 8ee9481d5a..f1004bb3c8 100644
--- a/legacy/ephysics/src/lib/ephysics_world.cpp
+++ b/legacy/ephysics/src/lib/ephysics_world.cpp
@@ -500,14 +500,14 @@ ephysics_world_soft_body_add(EPhysics_World *world, EPhysics_Body *body)
500} 500}
501 501
502void 502void
503ephysics_world_constraint_add(EPhysics_World *world, EPhysics_Constraint *constraint, btTypedConstraint *bt_constraint) 503ephysics_world_constraint_add(EPhysics_World *world, EPhysics_Constraint *constraint, btGeneric6DofConstraint *bt_constraint)
504{ 504{
505 world->dynamics_world->addConstraint(bt_constraint); 505 world->dynamics_world->addConstraint(bt_constraint, true);
506 world->constraints = eina_list_append(world->constraints, constraint); 506 world->constraints = eina_list_append(world->constraints, constraint);
507} 507}
508 508
509void 509void
510ephysics_world_constraint_del(EPhysics_World *world, EPhysics_Constraint *constraint, btTypedConstraint *bt_constraint) 510ephysics_world_constraint_del(EPhysics_World *world, EPhysics_Constraint *constraint, btGeneric6DofConstraint *bt_constraint)
511{ 511{
512 world->dynamics_world->removeConstraint(bt_constraint); 512 world->dynamics_world->removeConstraint(bt_constraint);
513 world->constraints = eina_list_remove(world->constraints, constraint); 513 world->constraints = eina_list_remove(world->constraints, constraint);