forked from enlightenment/efl
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
This commit is contained in:
parent
e2534363a6
commit
3627234fb8
|
@ -3,6 +3,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <Evas.h>
|
#include <Evas.h>
|
||||||
|
#include <BulletCollision/CollisionShapes/btShapeHull.h>
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
@ -888,10 +889,12 @@ ephysics_body_box_add(EPhysics_World *world)
|
||||||
EAPI EPhysics_Body *
|
EAPI EPhysics_Body *
|
||||||
ephysics_body_shape_add(EPhysics_World *world, EPhysics_Shape *shape)
|
ephysics_body_shape_add(EPhysics_World *world, EPhysics_Shape *shape)
|
||||||
{
|
{
|
||||||
btConvexHullShape* collision_shape;
|
btConvexHullShape *full_shape, *simplified_shape;
|
||||||
const Eina_Inlist *points;
|
const Eina_Inlist *points;
|
||||||
EPhysics_Point *point;
|
EPhysics_Point *point;
|
||||||
|
btShapeHull *hull;
|
||||||
btVector3 point3d;
|
btVector3 point3d;
|
||||||
|
btScalar margin;
|
||||||
|
|
||||||
if (!world)
|
if (!world)
|
||||||
{
|
{
|
||||||
|
@ -905,8 +908,8 @@ ephysics_body_shape_add(EPhysics_World *world, EPhysics_Shape *shape)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
collision_shape = new btConvexHullShape();
|
full_shape = new btConvexHullShape();
|
||||||
if (!collision_shape)
|
if (!full_shape)
|
||||||
{
|
{
|
||||||
ERR("Couldn't create a generic convex shape.");
|
ERR("Couldn't create a generic convex shape.");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -917,12 +920,18 @@ ephysics_body_shape_add(EPhysics_World *world, EPhysics_Shape *shape)
|
||||||
EINA_INLIST_FOREACH(points, point)
|
EINA_INLIST_FOREACH(points, point)
|
||||||
{
|
{
|
||||||
point3d = btVector3(point->x, point->y, 0);
|
point3d = btVector3(point->x, point->y, 0);
|
||||||
collision_shape->addPoint(point3d);
|
full_shape->addPoint(point3d);
|
||||||
point3d = btVector3(point->x, point->y, 0.5);
|
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");
|
"generic");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue