forked from enlightenment/efl
EPhysics: support bodies with generic shapes
Using EPhysics Shape. SVN revision: 75152
This commit is contained in:
parent
6c53875522
commit
031d47d1a9
|
@ -1334,6 +1334,28 @@ EAPI EPhysics_Body *ephysics_body_circle_add(EPhysics_World *world);
|
||||||
*/
|
*/
|
||||||
EAPI EPhysics_Body *ephysics_body_box_add(EPhysics_World *world);
|
EAPI EPhysics_Body *ephysics_body_box_add(EPhysics_World *world);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
* Create a new physics body using a custom shape.
|
||||||
|
*
|
||||||
|
* Its collision shape will be a convex shape that has all the points
|
||||||
|
* added to this @p shape. A shape can be created with
|
||||||
|
* @ref ephysics_shape_new().
|
||||||
|
*
|
||||||
|
* To change it's size @ref ephysics_body_geometry_set() should be used,
|
||||||
|
* so it can be deformed on x and y axises.
|
||||||
|
*
|
||||||
|
* @param world The world this body will belongs to.
|
||||||
|
* @param shape The custom shape to be used.
|
||||||
|
* @return a new body or @c NULL, on errors.
|
||||||
|
*
|
||||||
|
* @see ephysics_body_del().
|
||||||
|
* @see ephysics_body_evas_object_set().
|
||||||
|
*
|
||||||
|
* @ingroup EPhysics_Body
|
||||||
|
*/
|
||||||
|
EAPI EPhysics_Body *ephysics_body_shape_add(EPhysics_World *world, EPhysics_Shape *shape);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
* Create a physic top boundary.
|
* Create a physic top boundary.
|
||||||
|
|
|
@ -491,6 +491,47 @@ ephysics_body_box_add(EPhysics_World *world)
|
||||||
return _ephysics_body_add(world, collision_shape, "box");
|
return _ephysics_body_add(world, collision_shape, "box");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EAPI EPhysics_Body *
|
||||||
|
ephysics_body_shape_add(EPhysics_World *world, EPhysics_Shape *shape)
|
||||||
|
{
|
||||||
|
btConvexHullShape* collision_shape;
|
||||||
|
const Eina_Inlist *points;
|
||||||
|
EPhysics_Point *point;
|
||||||
|
btVector3 point3d;
|
||||||
|
|
||||||
|
if (!world)
|
||||||
|
{
|
||||||
|
ERR("Can't add shape, world is null.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!shape)
|
||||||
|
{
|
||||||
|
ERR("Can't add shape, shape is null.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
collision_shape = new btConvexHullShape();
|
||||||
|
if (!collision_shape)
|
||||||
|
{
|
||||||
|
ERR("Couldn't create a generic convex shape.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
points = ephysics_shape_points_get(shape);
|
||||||
|
|
||||||
|
EINA_INLIST_FOREACH(points, point)
|
||||||
|
{
|
||||||
|
point3d = btVector3(point->x, point->y, 0);
|
||||||
|
collision_shape->addPoint(point3d);
|
||||||
|
point3d = btVector3(point->x, point->y, 0.5);
|
||||||
|
collision_shape->addPoint(point3d);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _ephysics_body_add(world, (btCollisionShape *)collision_shape,
|
||||||
|
"generic");
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ephysics_body_world_boundaries_resize(EPhysics_World *world)
|
ephysics_body_world_boundaries_resize(EPhysics_World *world)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue