summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-08-22 20:05:19 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-08-22 20:05:19 +0000
commit3627234fb835205f170196adcf56873cb58bf265 (patch)
treed2cbd047f17680c0e2c886a464736932d319f356
parente2534363a67167c9d6398570f30ed5a2d7d05204 (diff)
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
-rw-r--r--legacy/ephysics/src/lib/ephysics_body.cpp21
1 files 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 @@
3#endif 3#endif
4 4
5#include <Evas.h> 5#include <Evas.h>
6#include <BulletCollision/CollisionShapes/btShapeHull.h>
6 7
7#include <math.h> 8#include <math.h>
8 9
@@ -888,10 +889,12 @@ ephysics_body_box_add(EPhysics_World *world)
888EAPI EPhysics_Body * 889EAPI EPhysics_Body *
889ephysics_body_shape_add(EPhysics_World *world, EPhysics_Shape *shape) 890ephysics_body_shape_add(EPhysics_World *world, EPhysics_Shape *shape)
890{ 891{
891 btConvexHullShape* collision_shape; 892 btConvexHullShape *full_shape, *simplified_shape;
892 const Eina_Inlist *points; 893 const Eina_Inlist *points;
893 EPhysics_Point *point; 894 EPhysics_Point *point;
895 btShapeHull *hull;
894 btVector3 point3d; 896 btVector3 point3d;
897 btScalar margin;
895 898
896 if (!world) 899 if (!world)
897 { 900 {
@@ -905,8 +908,8 @@ ephysics_body_shape_add(EPhysics_World *world, EPhysics_Shape *shape)
905 return NULL; 908 return NULL;
906 } 909 }
907 910
908 collision_shape = new btConvexHullShape(); 911 full_shape = new btConvexHullShape();
909 if (!collision_shape) 912 if (!full_shape)
910 { 913 {
911 ERR("Couldn't create a generic convex shape."); 914 ERR("Couldn't create a generic convex shape.");
912 return NULL; 915 return NULL;
@@ -917,12 +920,18 @@ ephysics_body_shape_add(EPhysics_World *world, EPhysics_Shape *shape)
917 EINA_INLIST_FOREACH(points, point) 920 EINA_INLIST_FOREACH(points, point)
918 { 921 {
919 point3d = btVector3(point->x, point->y, 0); 922 point3d = btVector3(point->x, point->y, 0);
920 collision_shape->addPoint(point3d); 923 full_shape->addPoint(point3d);
921 point3d = btVector3(point->x, point->y, 0.5); 924 point3d = btVector3(point->x, point->y, 0.5);
922 collision_shape->addPoint(point3d); 925 full_shape->addPoint(point3d);
923 } 926 }
924 927
925 return _ephysics_body_add(world, (btCollisionShape *)collision_shape, 928 hull = new btShapeHull(full_shape);
929 margin = full_shape->getMargin();
930 hull->buildHull(margin);
931 simplified_shape = new btConvexHullShape(&(hull->getVertexPointer()->getX()),
932 hull->numVertices());
933
934 return _ephysics_body_add(world, (btCollisionShape *)simplified_shape,
926 "generic"); 935 "generic");
927} 936}
928 937