diff options
author | Andrea Catania <info@andreacatania.com> | 2019-02-20 15:29:57 +0100 |
---|---|---|
committer | Andrea Catania <info@andreacatania.com> | 2019-02-21 08:41:31 +0100 |
commit | b1934cfd0db97646d044b3c3b7c9d1f9d6aa1d07 (patch) | |
tree | 178a495367dbb4705979e1158a91b25b2fa6e079 /modules | |
parent | 29fd942dd6e6851014da8d3da9a7fcdca2921781 (diff) |
Optimized area check
Diffstat (limited to 'modules')
-rw-r--r-- | modules/bullet/space_bullet.cpp | 67 |
1 files changed, 26 insertions, 41 deletions
diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp index c93220fc17..5a6579a413 100644 --- a/modules/bullet/space_bullet.cpp +++ b/modules/bullet/space_bullet.cpp @@ -650,7 +650,6 @@ void SpaceBullet::check_ghost_overlaps() { /// Algorithm support variables btCollisionShape *other_body_shape; btConvexShape *area_shape; - btGjkPairDetector::ClosestPointInput gjk_input; AreaBullet *area; int x(-1), i(-1), y(-1), z(-1), indexOverlap(-1); @@ -704,10 +703,6 @@ void SpaceBullet::check_ghost_overlaps() { btTransform area_shape_treansform(area->get_bt_shape_transform(y)); area_shape_treansform.getOrigin() *= area_scale; - gjk_input.m_transformA = - area->get_transform__bullet() * - area_shape_treansform; - area_shape = static_cast<btConvexShape *>(area->get_bt_shape(y)); // For each other object shape @@ -721,45 +716,35 @@ void SpaceBullet::check_ghost_overlaps() { btTransform other_shape_transform(otherObject->get_bt_shape_transform(z)); other_shape_transform.getOrigin() *= other_body_scale; - gjk_input.m_transformB = - otherObject->get_transform__bullet() * - other_shape_transform; - - if (other_body_shape->isConvex()) { - - btPointCollector result; - btGjkPairDetector gjk_pair_detector( - area_shape, - static_cast<btConvexShape *>(other_body_shape), - gjk_simplex_solver, - gjk_epa_pen_solver); - gjk_pair_detector.getClosestPoints(gjk_input, result, 0); - - if (0 >= result.m_distance) { - hasOverlap = true; - goto collision_found; - } - - } else { - - btCollisionObjectWrapper obA(NULL, area_shape, area->get_bt_ghost(), gjk_input.m_transformA, -1, y); - btCollisionObjectWrapper obB(NULL, other_body_shape, otherObject->get_bt_collision_object(), gjk_input.m_transformB, -1, z); - - btCollisionAlgorithm *algorithm = dispatcher->findAlgorithm(&obA, &obB, NULL, BT_CONTACT_POINT_ALGORITHMS); - - if (!algorithm) - continue; + btCollisionObjectWrapper obA( + NULL, + area_shape, + area->get_bt_ghost(), + area->get_transform__bullet() * area_shape_treansform, + -1, + y); + btCollisionObjectWrapper obB( + NULL, + other_body_shape, + otherObject->get_bt_collision_object(), + otherObject->get_transform__bullet() * other_shape_transform, + -1, + z); + + btCollisionAlgorithm *algorithm = dispatcher->findAlgorithm(&obA, &obB, NULL, BT_CONTACT_POINT_ALGORITHMS); + + if (!algorithm) + continue; - GodotDeepPenetrationContactResultCallback contactPointResult(&obA, &obB); - algorithm->processCollision(&obA, &obB, dynamicsWorld->getDispatchInfo(), &contactPointResult); + GodotDeepPenetrationContactResultCallback contactPointResult(&obA, &obB); + algorithm->processCollision(&obA, &obB, dynamicsWorld->getDispatchInfo(), &contactPointResult); - algorithm->~btCollisionAlgorithm(); - dispatcher->freeCollisionAlgorithm(algorithm); + algorithm->~btCollisionAlgorithm(); + dispatcher->freeCollisionAlgorithm(algorithm); - if (contactPointResult.hasHit()) { - hasOverlap = true; - goto collision_found; - } + if (contactPointResult.hasHit()) { + hasOverlap = true; + goto collision_found; } } // ~For each other object shape |