Add shape data to area overlap data.

This commit is contained in:
Marcel Admiraal 2020-10-10 16:35:40 +01:00
parent dd3acd74bb
commit 216fb38da1
4 changed files with 176 additions and 203 deletions

View File

@ -70,8 +70,8 @@ AreaBullet::AreaBullet() :
AreaBullet::~AreaBullet() { AreaBullet::~AreaBullet() {
// signal are handled by godot, so just clear without notify // signal are handled by godot, so just clear without notify
for (int i = overlappingObjects.size() - 1; 0 <= i; --i) { for (int i = 0; i < overlapping_shapes.size(); i++) {
overlappingObjects[i].object->on_exit_area(this); overlapping_shapes[i].other_object->on_exit_area(this);
} }
} }
@ -81,24 +81,30 @@ void AreaBullet::dispatch_callbacks() {
} }
isScratched = false; isScratched = false;
// Reverse order because I've to remove EXIT objects // Reverse order so items can be removed.
for (int i = overlappingObjects.size() - 1; 0 <= i; --i) { for (int i = overlapping_shapes.size() - 1; i >= 0; i--) {
OverlappingObjectData &otherObj = overlappingObjects.write[i]; OverlappingShapeData &overlapping_shape = overlapping_shapes.write[i];
switch (otherObj.state) { switch (overlapping_shape.state) {
case OVERLAP_STATE_ENTER: case OVERLAP_STATE_ENTER:
otherObj.state = OVERLAP_STATE_INSIDE; overlapping_shape.state = OVERLAP_STATE_INSIDE;
call_event(otherObj.object, PhysicsServer::AREA_BODY_ADDED); call_event(overlapping_shape, PhysicsServer::AREA_BODY_ADDED);
otherObj.object->on_enter_area(this); if (_overlapping_shape_count(overlapping_shape.other_object) == 1) {
// This object's first shape being added.
overlapping_shape.other_object->on_enter_area(this);
}
break; break;
case OVERLAP_STATE_EXIT: case OVERLAP_STATE_EXIT:
call_event(otherObj.object, PhysicsServer::AREA_BODY_REMOVED); call_event(overlapping_shape, PhysicsServer::AREA_BODY_REMOVED);
otherObj.object->on_exit_area(this); if (_overlapping_shape_count(overlapping_shape.other_object) == 1) {
overlappingObjects.remove(i); // Remove after callback // This object's last shape being removed.
overlapping_shape.other_object->on_exit_area(this);
}
overlapping_shapes.remove(i); // Remove after callback
break; break;
case OVERLAP_STATE_INSIDE: { case OVERLAP_STATE_INSIDE: {
if (otherObj.object->getType() == TYPE_RIGID_BODY) { if (overlapping_shape.other_object->getType() == TYPE_RIGID_BODY) {
RigidBodyBullet *body = static_cast<RigidBodyBullet *>(otherObj.object); RigidBodyBullet *body = static_cast<RigidBodyBullet *>(overlapping_shape.other_object);
body->scratch_space_override_modificator(); body->scratch_space_override_modificator();
} }
break; break;
@ -109,8 +115,8 @@ void AreaBullet::dispatch_callbacks() {
} }
} }
void AreaBullet::call_event(CollisionObjectBullet *p_otherObject, PhysicsServer::AreaBodyStatus p_status) { void AreaBullet::call_event(const OverlappingShapeData &p_overlapping_shape, PhysicsServer::AreaBodyStatus p_status) {
InOutEventCallback &event = eventsCallbacks[static_cast<int>(p_otherObject->getType())]; InOutEventCallback &event = eventsCallbacks[static_cast<int>(p_overlapping_shape.other_object->getType())];
Object *areaGodoObject = ObjectDB::get_instance(event.event_callback_id); Object *areaGodoObject = ObjectDB::get_instance(event.event_callback_id);
if (!areaGodoObject) { if (!areaGodoObject) {
@ -119,55 +125,93 @@ void AreaBullet::call_event(CollisionObjectBullet *p_otherObject, PhysicsServer:
} }
call_event_res[0] = p_status; call_event_res[0] = p_status;
call_event_res[1] = p_otherObject->get_self(); // Other body call_event_res[1] = p_overlapping_shape.other_object->get_self(); // RID
call_event_res[2] = p_otherObject->get_instance_id(); // instance ID call_event_res[2] = p_overlapping_shape.other_object->get_instance_id(); // Object ID
call_event_res[3] = 0; // other_body_shape ID call_event_res[3] = p_overlapping_shape.other_shape_id; // Other object's shape ID
call_event_res[4] = 0; // self_shape ID call_event_res[4] = p_overlapping_shape.our_shape_id; // This area's shape ID
Variant::CallError outResp; Variant::CallError outResp;
areaGodoObject->call(event.event_callback_method, (const Variant **)call_event_res_ptr, 5, outResp); areaGodoObject->call(event.event_callback_method, (const Variant **)call_event_res_ptr, 5, outResp);
} }
void AreaBullet::scratch() { int AreaBullet::_overlapping_shape_count(CollisionObjectBullet *p_other_object) {
if (isScratched) { int count = 0;
return; for (int i = 0; i < overlapping_shapes.size(); i++) {
} if (overlapping_shapes[i].other_object == p_other_object) {
isScratched = true; count++;
}
void AreaBullet::clear_overlaps(bool p_notify) {
for (int i = overlappingObjects.size() - 1; 0 <= i; --i) {
if (p_notify) {
call_event(overlappingObjects[i].object, PhysicsServer::AREA_BODY_REMOVED);
}
overlappingObjects[i].object->on_exit_area(this);
}
overlappingObjects.clear();
}
void AreaBullet::remove_overlap(CollisionObjectBullet *p_object, bool p_notify) {
for (int i = overlappingObjects.size() - 1; 0 <= i; --i) {
if (overlappingObjects[i].object == p_object) {
if (p_notify) {
call_event(overlappingObjects[i].object, PhysicsServer::AREA_BODY_REMOVED);
}
overlappingObjects[i].object->on_exit_area(this);
overlappingObjects.remove(i);
break;
} }
} }
return count;
} }
int AreaBullet::find_overlapping_object(CollisionObjectBullet *p_colObj) { int AreaBullet::_find_overlapping_shape(CollisionObjectBullet *p_other_object, uint32_t p_other_shape_id, uint32_t p_our_shape_id) {
const int size = overlappingObjects.size(); for (int i = 0; i < overlapping_shapes.size(); i++) {
for (int i = 0; i < size; ++i) { const OverlappingShapeData &overlapping_shape = overlapping_shapes[i];
if (overlappingObjects[i].object == p_colObj) { if (overlapping_shape.other_object == p_other_object && overlapping_shape.other_shape_id == p_other_shape_id && overlapping_shape.our_shape_id == p_our_shape_id) {
return i; return i;
} }
} }
return -1; return -1;
} }
void AreaBullet::mark_all_overlaps_dirty() {
OverlappingShapeData *overlapping_shapes_w = overlapping_shapes.ptrw();
for (int i = 0; i < overlapping_shapes.size(); i++) {
// Don't overwrite OVERLAP_STATE_ENTER state.
if (overlapping_shapes_w[i].state != OVERLAP_STATE_ENTER) {
overlapping_shapes_w[i].state = OVERLAP_STATE_DIRTY;
}
}
}
void AreaBullet::mark_object_overlaps_inside(CollisionObjectBullet *p_other_object) {
OverlappingShapeData *overlapping_shapes_w = overlapping_shapes.ptrw();
for (int i = 0; i < overlapping_shapes.size(); i++) {
if (overlapping_shapes_w[i].other_object == p_other_object && overlapping_shapes_w[i].state == OVERLAP_STATE_DIRTY) {
overlapping_shapes_w[i].state = OVERLAP_STATE_INSIDE;
}
}
}
void AreaBullet::set_overlap(CollisionObjectBullet *p_other_object, uint32_t p_other_shape_id, uint32_t p_our_shape_id) {
int i = _find_overlapping_shape(p_other_object, p_other_shape_id, p_our_shape_id);
if (i == -1) { // Not found, create new one.
OverlappingShapeData overlapping_shape(p_other_object, OVERLAP_STATE_ENTER, p_other_shape_id, p_our_shape_id);
overlapping_shapes.push_back(overlapping_shape);
p_other_object->notify_new_overlap(this);
isScratched = true;
} else {
overlapping_shapes.ptrw()[i].state = OVERLAP_STATE_INSIDE;
}
}
void AreaBullet::mark_all_dirty_overlaps_as_exit() {
OverlappingShapeData *overlapping_shapes_w = overlapping_shapes.ptrw();
for (int i = 0; i < overlapping_shapes.size(); i++) {
if (overlapping_shapes[i].state == OVERLAP_STATE_DIRTY) {
overlapping_shapes_w[i].state = OVERLAP_STATE_EXIT;
isScratched = true;
}
}
}
void AreaBullet::remove_object_overlaps(CollisionObjectBullet *p_object) {
// Reverse order so items can be removed.
for (int i = overlapping_shapes.size() - 1; i >= 0; i--) {
if (overlapping_shapes[i].other_object == p_object) {
overlapping_shapes.remove(i);
}
}
}
void AreaBullet::clear_overlaps() {
for (int i = 0; i < overlapping_shapes.size(); i++) {
call_event(overlapping_shapes[i], PhysicsServer::AREA_BODY_REMOVED);
overlapping_shapes[i].other_object->on_exit_area(this);
}
overlapping_shapes.clear();
}
void AreaBullet::set_monitorable(bool p_monitorable) { void AreaBullet::set_monitorable(bool p_monitorable) {
monitorable = p_monitorable; monitorable = p_monitorable;
updated = true; updated = true;
@ -193,7 +237,7 @@ void AreaBullet::reload_body() {
void AreaBullet::set_space(SpaceBullet *p_space) { void AreaBullet::set_space(SpaceBullet *p_space) {
// Clear the old space if there is one // Clear the old space if there is one
if (space) { if (space) {
clear_overlaps(false); clear_overlaps();
isScratched = false; isScratched = false;
// Remove this object form the physics world // Remove this object form the physics world
@ -214,24 +258,6 @@ void AreaBullet::on_collision_filters_change() {
updated = true; updated = true;
} }
void AreaBullet::add_overlap(CollisionObjectBullet *p_otherObject) {
scratch();
overlappingObjects.push_back(OverlappingObjectData(p_otherObject, OVERLAP_STATE_ENTER));
p_otherObject->notify_new_overlap(this);
}
void AreaBullet::put_overlap_as_exit(int p_index) {
scratch();
overlappingObjects.write[p_index].state = OVERLAP_STATE_EXIT;
}
void AreaBullet::put_overlap_as_inside(int p_index) {
// This check is required to be sure this body was inside
if (OVERLAP_STATE_DIRTY == overlappingObjects[p_index].state) {
overlappingObjects.write[p_index].state = OVERLAP_STATE_INSIDE;
}
}
void AreaBullet::set_param(PhysicsServer::AreaParameter p_param, const Variant &p_value) { void AreaBullet::set_param(PhysicsServer::AreaParameter p_param, const Variant &p_value) {
switch (p_param) { switch (p_param) {
case PhysicsServer::AREA_PARAM_GRAVITY: case PhysicsServer::AREA_PARAM_GRAVITY:
@ -261,7 +287,7 @@ void AreaBullet::set_param(PhysicsServer::AreaParameter p_param, const Variant &
default: default:
WARN_PRINT("Area doesn't support this parameter in the Bullet backend: " + itos(p_param)); WARN_PRINT("Area doesn't support this parameter in the Bullet backend: " + itos(p_param));
} }
scratch(); isScratched = true;
} }
Variant AreaBullet::get_param(PhysicsServer::AreaParameter p_param) const { Variant AreaBullet::get_param(PhysicsServer::AreaParameter p_param) const {
@ -298,7 +324,7 @@ void AreaBullet::set_event_callback(Type p_callbackObjectType, ObjectID p_id, co
set_godot_object_flags(get_godot_object_flags() | GOF_IS_MONITORING_AREA); set_godot_object_flags(get_godot_object_flags() | GOF_IS_MONITORING_AREA);
} else { } else {
set_godot_object_flags(get_godot_object_flags() & (~GOF_IS_MONITORING_AREA)); set_godot_object_flags(get_godot_object_flags() & (~GOF_IS_MONITORING_AREA));
clear_overlaps(true); clear_overlaps();
} }
} }

View File

@ -43,8 +43,6 @@
class btGhostObject; class btGhostObject;
class AreaBullet : public RigidCollisionObjectBullet { class AreaBullet : public RigidCollisionObjectBullet {
friend void SpaceBullet::check_ghost_overlaps();
public: public:
struct InOutEventCallback { struct InOutEventCallback {
ObjectID event_callback_id; ObjectID event_callback_id;
@ -61,23 +59,19 @@ public:
OVERLAP_STATE_EXIT // Mark ended overlaps OVERLAP_STATE_EXIT // Mark ended overlaps
}; };
struct OverlappingObjectData { struct OverlappingShapeData {
CollisionObjectBullet *object; CollisionObjectBullet *other_object = nullptr;
OverlapState state; OverlapState state = OVERLAP_STATE_DIRTY;
uint32_t other_shape_id = 0;
uint32_t our_shape_id = 0;
OverlappingObjectData() : OverlappingShapeData() {}
object(nullptr),
state(OVERLAP_STATE_ENTER) {} OverlappingShapeData(CollisionObjectBullet *p_other_object, OverlapState p_state, uint32_t p_other_shape_id, uint32_t p_our_shape_id) :
OverlappingObjectData(CollisionObjectBullet *p_object, OverlapState p_state) : other_object(p_other_object),
object(p_object), state(p_state),
state(p_state) {} other_shape_id(p_other_shape_id),
OverlappingObjectData(const OverlappingObjectData &other) { our_shape_id(p_our_shape_id) {}
operator=(other);
}
void operator=(const OverlappingObjectData &other) {
object = other.object;
state = other.state;
}
}; };
private: private:
@ -86,7 +80,9 @@ private:
Variant *call_event_res_ptr[5]; Variant *call_event_res_ptr[5];
btGhostObject *btGhost; btGhostObject *btGhost;
Vector<OverlappingObjectData> overlappingObjects; Vector<OverlappingShapeData> overlapping_shapes;
int _overlapping_shape_count(CollisionObjectBullet *p_other_object);
int _find_overlapping_shape(CollisionObjectBullet *p_other_object, uint32_t p_other_shape_id, uint32_t p_our_shape_id);
bool monitorable; bool monitorable;
PhysicsServer::AreaSpaceOverrideMode spOv_mode; PhysicsServer::AreaSpaceOverrideMode spOv_mode;
@ -108,7 +104,6 @@ public:
~AreaBullet(); ~AreaBullet();
_FORCE_INLINE_ btGhostObject *get_bt_ghost() const { return btGhost; } _FORCE_INLINE_ btGhostObject *get_bt_ghost() const { return btGhost; }
int find_overlapping_object(CollisionObjectBullet *p_colObj);
void set_monitorable(bool p_monitorable); void set_monitorable(bool p_monitorable);
_FORCE_INLINE_ bool is_monitorable() const { return monitorable; } _FORCE_INLINE_ bool is_monitorable() const { return monitorable; }
@ -147,20 +142,18 @@ public:
virtual void set_space(SpaceBullet *p_space); virtual void set_space(SpaceBullet *p_space);
virtual void dispatch_callbacks(); virtual void dispatch_callbacks();
void call_event(CollisionObjectBullet *p_otherObject, PhysicsServer::AreaBodyStatus p_status); void call_event(const OverlappingShapeData &p_overlapping_shape, PhysicsServer::AreaBodyStatus p_status);
void scratch();
void clear_overlaps(bool p_notify);
// Dispatch the callbacks and removes from overlapping list
void remove_overlap(CollisionObjectBullet *p_object, bool p_notify);
virtual void on_collision_filters_change(); virtual void on_collision_filters_change();
virtual void on_collision_checker_start() {} virtual void on_collision_checker_start() {}
virtual void on_collision_checker_end() { updated = false; } virtual void on_collision_checker_end() { updated = false; }
void add_overlap(CollisionObjectBullet *p_otherObject); void mark_all_overlaps_dirty();
void put_overlap_as_exit(int p_index); void mark_object_overlaps_inside(CollisionObjectBullet *p_other_object);
void put_overlap_as_inside(int p_index); void set_overlap(CollisionObjectBullet *p_other_object, uint32_t p_other_shape_id, uint32_t p_our_shape_id);
void mark_all_dirty_overlaps_as_exit();
void remove_object_overlaps(CollisionObjectBullet *p_object);
void clear_overlaps();
void set_param(PhysicsServer::AreaParameter p_param, const Variant &p_value); void set_param(PhysicsServer::AreaParameter p_param, const Variant &p_value);
Variant get_param(PhysicsServer::AreaParameter p_param) const; Variant get_param(PhysicsServer::AreaParameter p_param) const;

View File

@ -103,11 +103,9 @@ CollisionObjectBullet::CollisionObjectBullet(Type p_type) :
space(nullptr) {} space(nullptr) {}
CollisionObjectBullet::~CollisionObjectBullet() { CollisionObjectBullet::~CollisionObjectBullet() {
// Remove all overlapping, notify is not required since godot take care of it for (int i = 0; i < areasOverlapped.size(); i++) {
for (int i = areasOverlapped.size() - 1; 0 <= i; --i) { areasOverlapped[i]->remove_object_overlaps(this);
areasOverlapped[i]->remove_overlap(this, /*Notify*/ false);
} }
destroyBulletCollisionObject(); destroyBulletCollisionObject();
} }
@ -188,7 +186,9 @@ bool CollisionObjectBullet::is_collisions_response_enabled() {
} }
void CollisionObjectBullet::notify_new_overlap(AreaBullet *p_area) { void CollisionObjectBullet::notify_new_overlap(AreaBullet *p_area) {
areasOverlapped.push_back(p_area); if (areasOverlapped.find(p_area) == -1) {
areasOverlapped.push_back(p_area);
}
} }
void CollisionObjectBullet::on_exit_area(AreaBullet *p_area) { void CollisionObjectBullet::on_exit_area(AreaBullet *p_area) {

View File

@ -682,102 +682,78 @@ void SpaceBullet::destroy_world() {
} }
void SpaceBullet::check_ghost_overlaps() { void SpaceBullet::check_ghost_overlaps() {
/// Algorithm support variables // For each area
btCollisionShape *other_body_shape; for (int area_idx = 0; area_idx < areas.size(); area_idx++) {
btConvexShape *area_shape; AreaBullet *area = areas[area_idx];
btGjkPairDetector::ClosestPointInput gjk_input;
AreaBullet *area;
int x(-1), i(-1), y(-1), z(-1), indexOverlap(-1);
/// For each areas
for (x = areas.size() - 1; 0 <= x; --x) {
area = areas[x];
btVector3 area_scale(area->get_bt_body_scale());
if (!area->is_monitoring()) { if (!area->is_monitoring()) {
continue; continue;
} }
/// 1. Reset all states btGhostObject *bt_ghost = area->get_bt_ghost();
for (i = area->overlappingObjects.size() - 1; 0 <= i; --i) { const btTransform &area_transform = area->get_transform__bullet();
AreaBullet::OverlappingObjectData &otherObj = area->overlappingObjects.write[i]; const btVector3 &area_scale(area->get_bt_body_scale());
// This check prevent the overwrite of ENTER state
// if this function is called more times before dispatchCallbacks
if (otherObj.state != AreaBullet::OVERLAP_STATE_ENTER) {
otherObj.state = AreaBullet::OVERLAP_STATE_DIRTY;
}
}
/// 2. Check all overlapping objects using GJK // Mark all current overlapping shapes dirty.
area->mark_all_overlaps_dirty();
const btAlignedObjectArray<btCollisionObject *> ghostOverlaps = area->get_bt_ghost()->getOverlappingPairs(); // Broadphase
const btAlignedObjectArray<btCollisionObject *> overlapping_pairs = bt_ghost->getOverlappingPairs();
// Narrowphase
for (int pair_idx = 0; pair_idx < overlapping_pairs.size(); pair_idx++) {
btCollisionObject *other_bt_collision_object = overlapping_pairs[pair_idx];
RigidCollisionObjectBullet *other_object = static_cast<RigidCollisionObjectBullet *>(other_bt_collision_object->getUserPointer());
const btTransform &other_transform = other_object->get_transform__bullet();
const btVector3 &other_scale(other_object->get_bt_body_scale());
// For each overlapping if (!area->is_updated() && !other_object->is_updated()) {
for (i = ghostOverlaps.size() - 1; 0 <= i; --i) { area->mark_object_overlaps_inside(other_object);
bool hasOverlap = false; continue;
btCollisionObject *overlapped_bt_co = ghostOverlaps[i];
RigidCollisionObjectBullet *otherObject = static_cast<RigidCollisionObjectBullet *>(overlapped_bt_co->getUserPointer());
btVector3 other_body_scale(otherObject->get_bt_body_scale());
if (!area->is_updated() && !otherObject->is_updated()) {
hasOverlap = -1 != area->find_overlapping_object(otherObject);
goto collision_found;
} }
if (overlapped_bt_co->getUserIndex() == CollisionObjectBullet::TYPE_AREA) { if (other_bt_collision_object->getUserIndex() == CollisionObjectBullet::TYPE_AREA) {
if (!static_cast<AreaBullet *>(overlapped_bt_co->getUserPointer())->is_monitorable()) { if (!static_cast<AreaBullet *>(other_bt_collision_object->getUserPointer())->is_monitorable()) {
continue; continue;
} }
} else if (overlapped_bt_co->getUserIndex() != CollisionObjectBullet::TYPE_RIGID_BODY) { } else if (other_bt_collision_object->getUserIndex() != CollisionObjectBullet::TYPE_RIGID_BODY) {
continue; continue;
} }
// For each area shape // For each area shape
for (y = area->get_shape_count() - 1; 0 <= y; --y) { for (int our_shape_id = 0; our_shape_id < area->get_shape_count(); our_shape_id++) {
if (!area->get_bt_shape(y)->isConvex()) { btCollisionShape *area_shape = area->get_bt_shape(our_shape_id);
if (!area_shape->isConvex()) {
continue; continue;
} }
btConvexShape *area_convex_shape = static_cast<btConvexShape *>(area_shape);
btTransform area_shape_treansform(area->get_bt_shape_transform(y)); btTransform area_shape_transform(area->get_bt_shape_transform(our_shape_id));
area_shape_treansform.getOrigin() *= area_scale; area_shape_transform.getOrigin() *= area_scale;
btGjkPairDetector::ClosestPointInput gjk_input;
gjk_input.m_transformA = gjk_input.m_transformA = area_transform * area_shape_transform;
area->get_transform__bullet() *
area_shape_treansform;
area_shape = static_cast<btConvexShape *>(area->get_bt_shape(y));
// For each other object shape // For each other object shape
for (z = otherObject->get_shape_count() - 1; 0 <= z; --z) { for (int other_shape_id = 0; other_shape_id < other_object->get_shape_count(); other_shape_id++) {
other_body_shape = static_cast<btCollisionShape *>(otherObject->get_bt_shape(z)); btCollisionShape *other_shape = other_object->get_bt_shape(other_shape_id);
btTransform other_shape_transform(other_object->get_bt_shape_transform(other_shape_id));
other_shape_transform.getOrigin() *= other_scale;
gjk_input.m_transformB = other_transform * other_shape_transform;
btTransform other_shape_transform(otherObject->get_bt_shape_transform(z)); if (other_shape->isConvex()) {
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; btPointCollector result;
btGjkPairDetector gjk_pair_detector( btGjkPairDetector gjk_pair_detector(
area_shape, area_convex_shape,
static_cast<btConvexShape *>(other_body_shape), static_cast<btConvexShape *>(other_shape),
gjk_simplex_solver, gjk_simplex_solver,
gjk_epa_pen_solver); gjk_epa_pen_solver);
gjk_pair_detector.getClosestPoints(gjk_input, result, nullptr);
if (0 >= result.m_distance) { gjk_pair_detector.getClosestPoints(gjk_input, result, 0);
hasOverlap = true; if (result.m_distance <= 0) {
goto collision_found; area->set_overlap(other_object, other_shape_id, our_shape_id);
} }
} else { // Other shape is not convex.
} else { btCollisionObjectWrapper obA(NULL, area_convex_shape, bt_ghost, gjk_input.m_transformA, -1, our_shape_id);
btCollisionObjectWrapper obA(nullptr, area_shape, area->get_bt_ghost(), gjk_input.m_transformA, -1, y); btCollisionObjectWrapper obB(NULL, other_shape, other_bt_collision_object, gjk_input.m_transformB, -1, other_shape_id);
btCollisionObjectWrapper obB(nullptr, 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);
btCollisionAlgorithm *algorithm = dispatcher->findAlgorithm(&obA, &obB, nullptr, BT_CONTACT_POINT_ALGORITHMS);
if (!algorithm) { if (!algorithm) {
continue; continue;
@ -785,42 +761,20 @@ void SpaceBullet::check_ghost_overlaps() {
GodotDeepPenetrationContactResultCallback contactPointResult(&obA, &obB); GodotDeepPenetrationContactResultCallback contactPointResult(&obA, &obB);
algorithm->processCollision(&obA, &obB, dynamicsWorld->getDispatchInfo(), &contactPointResult); algorithm->processCollision(&obA, &obB, dynamicsWorld->getDispatchInfo(), &contactPointResult);
algorithm->~btCollisionAlgorithm(); algorithm->~btCollisionAlgorithm();
dispatcher->freeCollisionAlgorithm(algorithm); dispatcher->freeCollisionAlgorithm(algorithm);
if (contactPointResult.hasHit()) { if (contactPointResult.hasHit()) {
hasOverlap = true; area->set_overlap(other_object, our_shape_id, other_shape_id);
goto collision_found;
} }
} }
} // End for each other object shape
} // End for each area shape
} // End for each overlapping pair
} // ~For each other object shape // All overlapping shapes still marked dirty must have exited.
} // ~For each area shape area->mark_all_dirty_overlaps_as_exit();
} // End for each area
collision_found:
if (!hasOverlap) {
continue;
}
indexOverlap = area->find_overlapping_object(otherObject);
if (-1 == indexOverlap) {
// Not found
area->add_overlap(otherObject);
} else {
// Found
area->put_overlap_as_inside(indexOverlap);
}
}
/// 3. Remove not overlapping
for (i = area->overlappingObjects.size() - 1; 0 <= i; --i) {
// If the overlap has DIRTY state it means that it's no more overlapping
if (area->overlappingObjects[i].state == AreaBullet::OVERLAP_STATE_DIRTY) {
area->put_overlap_as_exit(i);
}
}
}
} }
void SpaceBullet::check_body_collision() { void SpaceBullet::check_body_collision() {