forked from enlightenment/efl
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
This commit is contained in:
parent
44aeda07ae
commit
3fe6e1dc40
|
@ -17,8 +17,97 @@ struct _EPhysics_Constraint {
|
||||||
btTypedConstraint *bt_constraint;
|
btTypedConstraint *bt_constraint;
|
||||||
EPhysics_World *world;
|
EPhysics_World *world;
|
||||||
EPhysics_Constraint_Type type;
|
EPhysics_Constraint_Type type;
|
||||||
|
struct {
|
||||||
|
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;
|
||||||
|
} p2p;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* FIXME: it shouldn't be this way.
|
||||||
|
* All constraints should be generic and have all these options
|
||||||
|
* set after add().
|
||||||
|
*/
|
||||||
|
static Eina_Bool
|
||||||
|
_ephysics_constraint_p2p_set(EPhysics_Constraint *constraint, double rate)
|
||||||
|
{
|
||||||
|
if (!constraint->p2p.body2)
|
||||||
|
constraint->bt_constraint = new btPoint2PointConstraint(
|
||||||
|
*ephysics_body_rigid_body_get(constraint->p2p.body1),
|
||||||
|
btVector3(constraint->p2p.anchor_b1_x / rate,
|
||||||
|
constraint->p2p.anchor_b1_y / rate, 0));
|
||||||
|
else
|
||||||
|
constraint->bt_constraint = new btPoint2PointConstraint(
|
||||||
|
*ephysics_body_rigid_body_get(constraint->p2p.body1),
|
||||||
|
*ephysics_body_rigid_body_get(constraint->p2p.body2),
|
||||||
|
btVector3(constraint->p2p.anchor_b1_x / rate,
|
||||||
|
constraint->p2p.anchor_b1_y / rate, 0),
|
||||||
|
btVector3(constraint->p2p.anchor_b2_x / rate,
|
||||||
|
constraint->p2p.anchor_b2_y / rate, 0));
|
||||||
|
|
||||||
|
if (!constraint->bt_constraint)
|
||||||
|
{
|
||||||
|
ERR("Failed to create a btConstraint");
|
||||||
|
free(constraint);
|
||||||
|
return EINA_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
constraint->type = EPHYSICS_CONSTRAINT_P2P;
|
||||||
|
constraint->world = ephysics_body_world_get(constraint->p2p.body1);
|
||||||
|
ephysics_world_constraint_add(constraint->world, constraint,
|
||||||
|
constraint->bt_constraint);
|
||||||
|
|
||||||
|
return EINA_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_ephysics_constraint_p2p_recalc(EPhysics_Constraint *constraint, double rate)
|
||||||
|
{
|
||||||
|
ephysics_world_constraint_del(constraint->world, constraint,
|
||||||
|
constraint->bt_constraint);
|
||||||
|
delete constraint->bt_constraint;
|
||||||
|
|
||||||
|
_ephysics_constraint_p2p_set(constraint, rate);
|
||||||
|
}
|
||||||
|
|
||||||
|
static 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, double rate)
|
||||||
|
{
|
||||||
|
btGeneric6DofConstraint *slider_constraint;
|
||||||
|
|
||||||
|
slider_constraint = (btGeneric6DofConstraint *)constraint->bt_constraint;
|
||||||
|
rate = ephysics_world_rate_get(constraint->world);
|
||||||
|
|
||||||
|
left_x = (left_x) / rate;
|
||||||
|
right_x = (right_x) / rate;
|
||||||
|
|
||||||
|
under_y = (under_y) / rate;
|
||||||
|
above_y = (above_y) / rate;
|
||||||
|
|
||||||
|
slider_constraint->setLinearLowerLimit(btVector3(-left_x, -under_y, 0));
|
||||||
|
slider_constraint->setLinearUpperLimit(btVector3(right_x, above_y, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ephysics_constraint_recalc(EPhysics_Constraint *constraint, double rate)
|
||||||
|
{
|
||||||
|
Evas_Coord left_x, under_y, right_x, above_y;
|
||||||
|
|
||||||
|
if (constraint->type == EPHYSICS_CONSTRAINT_P2P)
|
||||||
|
{
|
||||||
|
_ephysics_constraint_p2p_recalc(constraint, rate);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ephysics_constraint_slider_linear_limit_get(constraint, &left_x, &under_y,
|
||||||
|
&right_x, &above_y);
|
||||||
|
_ephysics_constraint_slider_linear_limit_set(constraint, left_x, under_y,
|
||||||
|
right_x, above_y, rate);
|
||||||
|
}
|
||||||
|
|
||||||
EAPI EPhysics_Constraint *
|
EAPI EPhysics_Constraint *
|
||||||
ephysics_constraint_slider_add(EPhysics_Body *body)
|
ephysics_constraint_slider_add(EPhysics_Body *body)
|
||||||
{
|
{
|
||||||
|
@ -62,9 +151,6 @@ ephysics_constraint_slider_add(EPhysics_Body *body)
|
||||||
EAPI void
|
EAPI 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)
|
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)
|
||||||
{
|
{
|
||||||
btGeneric6DofConstraint *slider_constraint;
|
|
||||||
int rate;
|
|
||||||
|
|
||||||
if (!constraint)
|
if (!constraint)
|
||||||
{
|
{
|
||||||
ERR("Can't set constraint's linear limit, constraint is null.");
|
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
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
slider_constraint = (btGeneric6DofConstraint *)constraint->bt_constraint;
|
_ephysics_constraint_slider_linear_limit_set(
|
||||||
rate = ephysics_world_rate_get(constraint->world);
|
constraint, left_x, under_y, right_x, above_y,
|
||||||
|
ephysics_world_rate_get(constraint->world));
|
||||||
left_x = (left_x) / rate;
|
|
||||||
right_x = (right_x) / rate;
|
|
||||||
|
|
||||||
under_y = (under_y) / rate;
|
|
||||||
above_y = (above_y) / rate;
|
|
||||||
|
|
||||||
slider_constraint->setLinearLowerLimit(btVector3(-left_x, -under_y, 0));
|
|
||||||
slider_constraint->setLinearUpperLimit(btVector3(right_x, above_y, 0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
|
@ -184,7 +262,6 @@ EAPI 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)
|
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)
|
||||||
{
|
{
|
||||||
EPhysics_Constraint *constraint;
|
EPhysics_Constraint *constraint;
|
||||||
int rate;
|
|
||||||
|
|
||||||
if (!body1)
|
if (!body1)
|
||||||
{
|
{
|
||||||
|
@ -207,30 +284,17 @@ ephysics_constraint_p2p_add(EPhysics_Body *body1, EPhysics_Body *body2, Evas_Coo
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
rate = ephysics_world_rate_get(ephysics_body_world_get(body1));
|
constraint->p2p.body1 = body1;
|
||||||
|
constraint->p2p.body2 = body2;
|
||||||
|
constraint->p2p.anchor_b1_x = anchor_b1_x;
|
||||||
|
constraint->p2p.anchor_b1_y = anchor_b1_y;
|
||||||
|
constraint->p2p.anchor_b2_x = anchor_b2_x;
|
||||||
|
constraint->p2p.anchor_b2_y = anchor_b2_y;
|
||||||
|
|
||||||
if (!body2)
|
if (!_ephysics_constraint_p2p_set(
|
||||||
constraint->bt_constraint = new btPoint2PointConstraint(
|
constraint, ephysics_world_rate_get(ephysics_body_world_get(
|
||||||
*ephysics_body_rigid_body_get(body1),
|
constraint->p2p.body1))))
|
||||||
btVector3(anchor_b1_x / rate, anchor_b1_y / rate, 0));
|
return NULL;
|
||||||
else
|
|
||||||
constraint->bt_constraint = new btPoint2PointConstraint(
|
|
||||||
*ephysics_body_rigid_body_get(body1),
|
|
||||||
*ephysics_body_rigid_body_get(body2),
|
|
||||||
btVector3(anchor_b1_x / rate, anchor_b1_y / rate, 0),
|
|
||||||
btVector3(anchor_b2_x / rate, anchor_b2_y / rate, 0));
|
|
||||||
|
|
||||||
if (!constraint->bt_constraint)
|
|
||||||
{
|
|
||||||
ERR("Failed to create a btConstraint");
|
|
||||||
free(constraint);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
constraint->type = EPHYSICS_CONSTRAINT_P2P;
|
|
||||||
constraint->world = ephysics_body_world_get(body1);
|
|
||||||
ephysics_world_constraint_add(constraint->world, constraint,
|
|
||||||
constraint->bt_constraint);
|
|
||||||
|
|
||||||
INF("Constraint added.");
|
INF("Constraint added.");
|
||||||
return constraint;
|
return constraint;
|
||||||
|
|
|
@ -81,6 +81,7 @@ struct _EPhysics_Body {
|
||||||
|
|
||||||
extern int _ephysics_log_dom;
|
extern int _ephysics_log_dom;
|
||||||
|
|
||||||
|
/* World */
|
||||||
int ephysics_world_init(void);
|
int ephysics_world_init(void);
|
||||||
int ephysics_world_shutdown(void);
|
int ephysics_world_shutdown(void);
|
||||||
Eina_Bool ephysics_world_body_add(EPhysics_World *world, EPhysics_Body *body);
|
Eina_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
|
||||||
EPhysics_Body *ephysics_world_boundary_get(const EPhysics_World *world, EPhysics_World_Boundary boundary);
|
EPhysics_Body *ephysics_world_boundary_get(const EPhysics_World *world, EPhysics_World_Boundary boundary);
|
||||||
Eina_Bool ephysics_world_bodies_outside_autodel_get(const EPhysics_World *world);
|
Eina_Bool ephysics_world_bodies_outside_autodel_get(const EPhysics_World *world);
|
||||||
|
|
||||||
|
/* Body */
|
||||||
Eina_Bool ephysics_body_filter_collision(EPhysics_Body *body0, EPhysics_Body *body1);
|
Eina_Bool ephysics_body_filter_collision(EPhysics_Body *body0, EPhysics_Body *body1);
|
||||||
|
|
||||||
void ephysics_body_evas_object_update_select(EPhysics_Body *body);
|
void ephysics_body_evas_object_update_select(EPhysics_Body *body);
|
||||||
void ephysics_orphan_body_del(EPhysics_Body *body);
|
void ephysics_orphan_body_del(EPhysics_Body *body);
|
||||||
void ephysics_body_contact_processed(EPhysics_Body *body, EPhysics_Body *contact_body, btVector3 position);
|
void 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);
|
||||||
void ephysics_body_active_set(EPhysics_Body *body, Eina_Bool active);
|
void ephysics_body_active_set(EPhysics_Body *body, Eina_Bool active);
|
||||||
void ephysics_body_recalc(EPhysics_Body *body, double rate);
|
void ephysics_body_recalc(EPhysics_Body *body, double rate);
|
||||||
|
|
||||||
|
/* Camera */
|
||||||
EPhysics_Camera *ephysics_camera_add(EPhysics_World *world);
|
EPhysics_Camera *ephysics_camera_add(EPhysics_World *world);
|
||||||
void ephysics_camera_del(EPhysics_Camera *camera);
|
void ephysics_camera_del(EPhysics_Camera *camera);
|
||||||
void ephysics_camera_moved_set(EPhysics_Camera *camera, Eina_Bool moved);
|
void ephysics_camera_moved_set(EPhysics_Camera *camera, Eina_Bool moved);
|
||||||
Eina_Bool ephysics_camera_moved_get(const EPhysics_Camera *camera);
|
Eina_Bool ephysics_camera_moved_get(const EPhysics_Camera *camera);
|
||||||
void ephysics_camera_target_moved(EPhysics_Camera *camera, EPhysics_Body *body);
|
void ephysics_camera_target_moved(EPhysics_Camera *camera, EPhysics_Body *body);
|
||||||
|
|
||||||
|
/* Shape */
|
||||||
const Eina_Inlist *ephysics_shape_points_get(const EPhysics_Shape *shape);
|
const Eina_Inlist *ephysics_shape_points_get(const EPhysics_Shape *shape);
|
||||||
|
|
||||||
|
/* Constraint */
|
||||||
|
void ephysics_constraint_recalc(EPhysics_Constraint *constraint, double rate);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue