ephysics: shrink convex shapes to avoid margin gap

SVN revision: 76563
This commit is contained in:
Bruno Dilly 2012-09-12 21:50:01 +00:00
parent 81786a748a
commit 3f27034dc7
2 changed files with 22 additions and 5 deletions

View File

@ -14,7 +14,7 @@ _world_populate(Test_Data *test_data)
pentagon = elm_image_add(test_data->win);
elm_image_file_set(
pentagon, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "pentagon");
evas_object_move(pentagon, WIDTH / 3, HEIGHT / 2 - 30);
evas_object_move(pentagon, WIDTH / 3, HEIGHT / 2 - 80);
evas_object_resize(pentagon, 70, 68);
evas_object_show(pentagon);
test_data->evas_objs = eina_list_append(test_data->evas_objs, pentagon);
@ -34,7 +34,7 @@ _world_populate(Test_Data *test_data)
hexagon = elm_image_add(test_data->win);
elm_image_file_set(
hexagon, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "hexagon");
evas_object_move(hexagon, WIDTH / 3 + 80, HEIGHT / 2 - 30);
evas_object_move(hexagon, WIDTH / 3 + 100, HEIGHT / 2 - 100);
evas_object_resize(hexagon, 70, 60);
evas_object_show(hexagon);
test_data->evas_objs = eina_list_append(test_data->evas_objs, hexagon);
@ -51,6 +51,7 @@ _world_populate(Test_Data *test_data)
ephysics_body_evas_object_set(hexagon_body, hexagon, EINA_TRUE);
ephysics_body_restitution_set(hexagon_body, 1);
test_data->bodies = eina_list_append(test_data->bodies, hexagon_body);
ephysics_body_torque_apply(hexagon_body, -3);
ephysics_shape_del(pentagon_shape);
ephysics_shape_del(hexagon_shape);

View File

@ -4,6 +4,7 @@
#include <Evas.h>
#include <BulletCollision/CollisionShapes/btShapeHull.h>
#include <LinearMath/btGeometryUtil.h>
#include <math.h>
@ -946,10 +947,12 @@ ephysics_body_box_add(EPhysics_World *world)
EAPI EPhysics_Body *
ephysics_body_shape_add(EPhysics_World *world, EPhysics_Shape *shape)
{
btConvexHullShape *full_shape, *simplified_shape;
double max_x, max_y, min_x, min_y, cm_x, cm_y, range_x, range_y;
btConvexHullShape *full_shape, *simplified_shape;
btAlignedObjectArray<btVector3> vertexes, planes;
const Eina_Inlist *points;
EPhysics_Point *point;
int array_size, i;
btShapeHull *hull;
btVector3 point3d;
btScalar margin;
@ -1010,12 +1013,25 @@ ephysics_body_shape_add(EPhysics_World *world, EPhysics_Shape *shape)
y = - (point->y - cm_y) / range_y;
point3d = btVector3(x, y, -0.5);
full_shape->addPoint(point3d);
vertexes.push_back(point3d);
point3d = btVector3(x, y, 0.5);
full_shape->addPoint(point3d);
vertexes.push_back(point3d);
}
/* Shrink convex shape to consider margin. Otherwise it would have a gap */
btGeometryUtil::getPlaneEquationsFromVertices(vertexes, planes);
array_size = planes.size();
for (i = 0; i < array_size; ++i)
planes[i][3] += full_shape->getMargin();
vertexes.clear();
btGeometryUtil::getVerticesFromPlaneEquations(planes, vertexes);
array_size = vertexes.size();
for (i = 0; i < array_size; ++i)
full_shape->addPoint(vertexes[i]);
hull = new btShapeHull(full_shape);
if (!hull)
{