From 3627234fb835205f170196adcf56873cb58bf265 Mon Sep 17 00:00:00 2001 From: Bruno Dilly Date: Wed, 22 Aug 2012 20:05:19 +0000 Subject: [PATCH] EPhysics: use vertex reduction utility Convex meshes often have too many vertices. This slows down collision detection a lot, and there is no benefit in the unnecessary details. SVN revision: 75571 --- legacy/ephysics/src/lib/ephysics_body.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp index 18d1caab55..b390108846 100644 --- a/legacy/ephysics/src/lib/ephysics_body.cpp +++ b/legacy/ephysics/src/lib/ephysics_body.cpp @@ -3,6 +3,7 @@ #endif #include +#include #include @@ -888,10 +889,12 @@ ephysics_body_box_add(EPhysics_World *world) EAPI EPhysics_Body * ephysics_body_shape_add(EPhysics_World *world, EPhysics_Shape *shape) { - btConvexHullShape* collision_shape; + btConvexHullShape *full_shape, *simplified_shape; const Eina_Inlist *points; EPhysics_Point *point; + btShapeHull *hull; btVector3 point3d; + btScalar margin; if (!world) { @@ -905,8 +908,8 @@ ephysics_body_shape_add(EPhysics_World *world, EPhysics_Shape *shape) return NULL; } - collision_shape = new btConvexHullShape(); - if (!collision_shape) + full_shape = new btConvexHullShape(); + if (!full_shape) { ERR("Couldn't create a generic convex shape."); return NULL; @@ -917,12 +920,18 @@ ephysics_body_shape_add(EPhysics_World *world, EPhysics_Shape *shape) EINA_INLIST_FOREACH(points, point) { point3d = btVector3(point->x, point->y, 0); - collision_shape->addPoint(point3d); + full_shape->addPoint(point3d); point3d = btVector3(point->x, point->y, 0.5); - collision_shape->addPoint(point3d); + full_shape->addPoint(point3d); } - return _ephysics_body_add(world, (btCollisionShape *)collision_shape, + hull = new btShapeHull(full_shape); + margin = full_shape->getMargin(); + hull->buildHull(margin); + simplified_shape = new btConvexHullShape(&(hull->getVertexPointer()->getX()), + hull->numVertices()); + + return _ephysics_body_add(world, (btCollisionShape *)simplified_shape, "generic"); }