summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-08-16 21:35:09 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-08-16 21:35:09 +0000
commit3fe6e1dc4098c73171d2333dab66e0556d034982 (patch)
tree478ea09e516201d25b520af5ab95b0f6540cd0d4 /legacy
parent44aeda07ae66f5007e4334b70b68b9755c457683 (diff)
EPhysics: constraint recalc
Just making it possible to fix world rate set. This code will be modified when all constraints are added as generic and modified later. SVN revision: 75333
Diffstat (limited to 'legacy')
-rw-r--r--legacy/ephysics/src/lib/ephysics_constraints.cpp142
-rw-r--r--legacy/ephysics/src/lib/ephysics_private.h8
2 files changed, 110 insertions, 40 deletions
diff --git a/legacy/ephysics/src/lib/ephysics_constraints.cpp b/legacy/ephysics/src/lib/ephysics_constraints.cpp
index 546ceed539..1263a52ec5 100644
--- a/legacy/ephysics/src/lib/ephysics_constraints.cpp
+++ b/legacy/ephysics/src/lib/ephysics_constraints.cpp
@@ -17,8 +17,97 @@ struct _EPhysics_Constraint {
17 btTypedConstraint *bt_constraint; 17 btTypedConstraint *bt_constraint;
18 EPhysics_World *world; 18 EPhysics_World *world;
19 EPhysics_Constraint_Type type; 19 EPhysics_Constraint_Type type;
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;
20}; 28};
21 29
30/* FIXME: it shouldn't be this way.
31 * All constraints should be generic and have all these options
32 * set after add().
33 */
34static Eina_Bool
35_ephysics_constraint_p2p_set(EPhysics_Constraint *constraint, double rate)
36{
37 if (!constraint->p2p.body2)
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
51 if (!constraint->bt_constraint)
52 {
53 ERR("Failed to create a btConstraint");
54 free(constraint);
55 return EINA_FALSE;
56 }
57
58 constraint->type = EPHYSICS_CONSTRAINT_P2P;
59 constraint->world = ephysics_body_world_get(constraint->p2p.body1);
60 ephysics_world_constraint_add(constraint->world, constraint,
61 constraint->bt_constraint);
62
63 return EINA_TRUE;
64}
65
66static void
67_ephysics_constraint_p2p_recalc(EPhysics_Constraint *constraint, double rate)
68{
69 ephysics_world_constraint_del(constraint->world, constraint,
70 constraint->bt_constraint);
71 delete constraint->bt_constraint;
72
73 _ephysics_constraint_p2p_set(constraint, rate);
74}
75
76static void
77_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)
78{
79 btGeneric6DofConstraint *slider_constraint;
80
81 slider_constraint = (btGeneric6DofConstraint *)constraint->bt_constraint;
82 rate = ephysics_world_rate_get(constraint->world);
83
84 left_x = (left_x) / rate;
85 right_x = (right_x) / rate;
86
87 under_y = (under_y) / rate;
88 above_y = (above_y) / rate;
89
90 slider_constraint->setLinearLowerLimit(btVector3(-left_x, -under_y, 0));
91 slider_constraint->setLinearUpperLimit(btVector3(right_x, above_y, 0));
92}
93
94void
95ephysics_constraint_recalc(EPhysics_Constraint *constraint, double rate)
96{
97 Evas_Coord left_x, under_y, right_x, above_y;
98
99 if (constraint->type == EPHYSICS_CONSTRAINT_P2P)
100 {
101 _ephysics_constraint_p2p_recalc(constraint, rate);
102 return;
103 }
104
105 ephysics_constraint_slider_linear_limit_get(constraint, &left_x, &under_y,
106 &right_x, &above_y);
107 _ephysics_constraint_slider_linear_limit_set(constraint, left_x, under_y,
108 right_x, above_y, rate);
109}
110
22EAPI EPhysics_Constraint * 111EAPI EPhysics_Constraint *
23ephysics_constraint_slider_add(EPhysics_Body *body) 112ephysics_constraint_slider_add(EPhysics_Body *body)
24{ 113{
@@ -62,9 +151,6 @@ ephysics_constraint_slider_add(EPhysics_Body *body)
62EAPI void 151EAPI void
63ephysics_constraint_slider_linear_limit_set(EPhysics_Constraint *constraint, Evas_Coord left_x, Evas_Coord under_y, Evas_Coord right_x, Evas_Coord above_y) 152ephysics_constraint_slider_linear_limit_set(EPhysics_Constraint *constraint, Evas_Coord left_x, Evas_Coord under_y, Evas_Coord right_x, Evas_Coord above_y)
64{ 153{
65 btGeneric6DofConstraint *slider_constraint;
66 int rate;
67
68 if (!constraint) 154 if (!constraint)
69 { 155 {
70 ERR("Can't set constraint's linear limit, constraint is null."); 156 ERR("Can't set constraint's linear limit, constraint is null.");
@@ -77,17 +163,9 @@ ephysics_constraint_slider_linear_limit_set(EPhysics_Constraint *constraint, Eva
77 return; 163 return;
78 } 164 }
79 165
80 slider_constraint = (btGeneric6DofConstraint *)constraint->bt_constraint; 166 _ephysics_constraint_slider_linear_limit_set(
81 rate = ephysics_world_rate_get(constraint->world); 167 constraint, left_x, under_y, right_x, above_y,
82 168 ephysics_world_rate_get(constraint->world));
83 left_x = (left_x) / rate;
84 right_x = (right_x) / rate;
85
86 under_y = (under_y) / rate;
87 above_y = (above_y) / rate;
88
89 slider_constraint->setLinearLowerLimit(btVector3(-left_x, -under_y, 0));
90 slider_constraint->setLinearUpperLimit(btVector3(right_x, above_y, 0));
91} 169}
92 170
93EAPI void 171EAPI void
@@ -184,7 +262,6 @@ EAPI EPhysics_Constraint *
184ephysics_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) 262ephysics_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)
185{ 263{
186 EPhysics_Constraint *constraint; 264 EPhysics_Constraint *constraint;
187 int rate;
188 265
189 if (!body1) 266 if (!body1)
190 { 267 {
@@ -207,30 +284,17 @@ ephysics_constraint_p2p_add(EPhysics_Body *body1, EPhysics_Body *body2, Evas_Coo
207 return NULL; 284 return NULL;
208 } 285 }
209 286
210 rate = ephysics_world_rate_get(ephysics_body_world_get(body1)); 287 constraint->p2p.body1 = body1;
211 288 constraint->p2p.body2 = body2;
212 if (!body2) 289 constraint->p2p.anchor_b1_x = anchor_b1_x;
213 constraint->bt_constraint = new btPoint2PointConstraint( 290 constraint->p2p.anchor_b1_y = anchor_b1_y;
214 *ephysics_body_rigid_body_get(body1), 291 constraint->p2p.anchor_b2_x = anchor_b2_x;
215 btVector3(anchor_b1_x / rate, anchor_b1_y / rate, 0)); 292 constraint->p2p.anchor_b2_y = anchor_b2_y;
216 else 293
217 constraint->bt_constraint = new btPoint2PointConstraint( 294 if (!_ephysics_constraint_p2p_set(
218 *ephysics_body_rigid_body_get(body1), 295 constraint, ephysics_world_rate_get(ephysics_body_world_get(
219 *ephysics_body_rigid_body_get(body2), 296 constraint->p2p.body1))))
220 btVector3(anchor_b1_x / rate, anchor_b1_y / rate, 0), 297 return NULL;
221 btVector3(anchor_b2_x / rate, anchor_b2_y / rate, 0));
222
223 if (!constraint->bt_constraint)
224 {
225 ERR("Failed to create a btConstraint");
226 free(constraint);
227 return NULL;
228 }
229
230 constraint->type = EPHYSICS_CONSTRAINT_P2P;
231 constraint->world = ephysics_body_world_get(body1);
232 ephysics_world_constraint_add(constraint->world, constraint,
233 constraint->bt_constraint);
234 298
235 INF("Constraint added."); 299 INF("Constraint added.");
236 return constraint; 300 return constraint;
diff --git a/legacy/ephysics/src/lib/ephysics_private.h b/legacy/ephysics/src/lib/ephysics_private.h
index b8c3527f82..eb7669fdf2 100644
--- a/legacy/ephysics/src/lib/ephysics_private.h
+++ b/legacy/ephysics/src/lib/ephysics_private.h
@@ -81,6 +81,7 @@ struct _EPhysics_Body {
81 81
82extern int _ephysics_log_dom; 82extern int _ephysics_log_dom;
83 83
84/* World */
84int ephysics_world_init(void); 85int ephysics_world_init(void);
85int ephysics_world_shutdown(void); 86int ephysics_world_shutdown(void);
86Eina_Bool ephysics_world_body_add(EPhysics_World *world, EPhysics_Body *body); 87Eina_Bool ephysics_world_body_add(EPhysics_World *world, EPhysics_Body *body);
@@ -92,8 +93,8 @@ void ephysics_world_boundary_set(EPhysics_World *world, EPhysics_World_Boundary
92EPhysics_Body *ephysics_world_boundary_get(const EPhysics_World *world, EPhysics_World_Boundary boundary); 93EPhysics_Body *ephysics_world_boundary_get(const EPhysics_World *world, EPhysics_World_Boundary boundary);
93Eina_Bool ephysics_world_bodies_outside_autodel_get(const EPhysics_World *world); 94Eina_Bool ephysics_world_bodies_outside_autodel_get(const EPhysics_World *world);
94 95
96/* Body */
95Eina_Bool ephysics_body_filter_collision(EPhysics_Body *body0, EPhysics_Body *body1); 97Eina_Bool ephysics_body_filter_collision(EPhysics_Body *body0, EPhysics_Body *body1);
96
97void ephysics_body_evas_object_update_select(EPhysics_Body *body); 98void ephysics_body_evas_object_update_select(EPhysics_Body *body);
98void ephysics_orphan_body_del(EPhysics_Body *body); 99void ephysics_orphan_body_del(EPhysics_Body *body);
99void ephysics_body_contact_processed(EPhysics_Body *body, EPhysics_Body *contact_body, btVector3 position); 100void ephysics_body_contact_processed(EPhysics_Body *body, EPhysics_Body *contact_body, btVector3 position);
@@ -101,14 +102,19 @@ btRigidBody *ephysics_body_rigid_body_get(const EPhysics_Body *body);
101void ephysics_body_active_set(EPhysics_Body *body, Eina_Bool active); 102void ephysics_body_active_set(EPhysics_Body *body, Eina_Bool active);
102void ephysics_body_recalc(EPhysics_Body *body, double rate); 103void ephysics_body_recalc(EPhysics_Body *body, double rate);
103 104
105/* Camera */
104EPhysics_Camera *ephysics_camera_add(EPhysics_World *world); 106EPhysics_Camera *ephysics_camera_add(EPhysics_World *world);
105void ephysics_camera_del(EPhysics_Camera *camera); 107void ephysics_camera_del(EPhysics_Camera *camera);
106void ephysics_camera_moved_set(EPhysics_Camera *camera, Eina_Bool moved); 108void ephysics_camera_moved_set(EPhysics_Camera *camera, Eina_Bool moved);
107Eina_Bool ephysics_camera_moved_get(const EPhysics_Camera *camera); 109Eina_Bool ephysics_camera_moved_get(const EPhysics_Camera *camera);
108void ephysics_camera_target_moved(EPhysics_Camera *camera, EPhysics_Body *body); 110void ephysics_camera_target_moved(EPhysics_Camera *camera, EPhysics_Body *body);
109 111
112/* Shape */
110const Eina_Inlist *ephysics_shape_points_get(const EPhysics_Shape *shape); 113const Eina_Inlist *ephysics_shape_points_get(const EPhysics_Shape *shape);
111 114
115/* Constraint */
116void ephysics_constraint_recalc(EPhysics_Constraint *constraint, double rate);
117
112#ifdef __cplusplus 118#ifdef __cplusplus
113} 119}
114#endif 120#endif