Style: Enforce braces around if blocks and loops

Using clang-tidy's `readability-braces-around-statements`.
https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
This commit is contained in:
Rémi Verschelde
2021-05-05 12:44:11 +02:00
parent b8d198eeed
commit 140350d767
694 changed files with 23283 additions and 12499 deletions

View File

@ -42,16 +42,20 @@ bool AreaPairSW::setup(real_t p_step) {
if (result != colliding) {
if (result) {
if (area->get_space_override_mode() != PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED)
if (area->get_space_override_mode() != PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED) {
body->add_area(area);
if (area->has_monitor_callback())
}
if (area->has_monitor_callback()) {
area->add_body_to_query(body, body_shape, area_shape);
}
} else {
if (area->get_space_override_mode() != PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED)
if (area->get_space_override_mode() != PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED) {
body->remove_area(area);
if (area->has_monitor_callback())
}
if (area->has_monitor_callback()) {
area->remove_body_from_query(body, body_shape, area_shape);
}
}
colliding = result;
@ -71,16 +75,19 @@ AreaPairSW::AreaPairSW(BodySW *p_body, int p_body_shape, AreaSW *p_area, int p_a
colliding = false;
body->add_constraint(this, 0);
area->add_constraint(this);
if (p_body->get_mode() == PhysicsServer::BODY_MODE_KINEMATIC)
if (p_body->get_mode() == PhysicsServer::BODY_MODE_KINEMATIC) {
p_body->set_active(true);
}
}
AreaPairSW::~AreaPairSW() {
if (colliding) {
if (area->get_space_override_mode() != PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED)
if (area->get_space_override_mode() != PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED) {
body->remove_area(area);
if (area->has_monitor_callback())
}
if (area->has_monitor_callback()) {
area->remove_body_from_query(body, body_shape, area_shape);
}
}
body->remove_constraint(this);
area->remove_constraint(this);
@ -98,18 +105,22 @@ bool Area2PairSW::setup(real_t p_step) {
if (result != colliding) {
if (result) {
if (area_b->has_area_monitor_callback() && area_a->is_monitorable())
if (area_b->has_area_monitor_callback() && area_a->is_monitorable()) {
area_b->add_area_to_query(area_a, shape_a, shape_b);
}
if (area_a->has_area_monitor_callback() && area_b->is_monitorable())
if (area_a->has_area_monitor_callback() && area_b->is_monitorable()) {
area_a->add_area_to_query(area_b, shape_b, shape_a);
}
} else {
if (area_b->has_area_monitor_callback() && area_a->is_monitorable())
if (area_b->has_area_monitor_callback() && area_a->is_monitorable()) {
area_b->remove_area_from_query(area_a, shape_a, shape_b);
}
if (area_a->has_area_monitor_callback() && area_b->is_monitorable())
if (area_a->has_area_monitor_callback() && area_b->is_monitorable()) {
area_a->remove_area_from_query(area_b, shape_b, shape_a);
}
}
colliding = result;
@ -133,11 +144,13 @@ Area2PairSW::Area2PairSW(AreaSW *p_area_a, int p_shape_a, AreaSW *p_area_b, int
Area2PairSW::~Area2PairSW() {
if (colliding) {
if (area_b->has_area_monitor_callback())
if (area_b->has_area_monitor_callback()) {
area_b->remove_area_from_query(area_a, shape_a, shape_b);
}
if (area_a->has_area_monitor_callback())
if (area_a->has_area_monitor_callback()) {
area_a->remove_area_from_query(area_b, shape_b, shape_a);
}
}
area_a->remove_constraint(this);

View File

@ -46,13 +46,15 @@ AreaSW::BodyKey::BodyKey(AreaSW *p_body, uint32_t p_body_shape, uint32_t p_area_
}
void AreaSW::_shapes_changed() {
if (!moved_list.in_list() && get_space())
if (!moved_list.in_list() && get_space()) {
get_space()->area_add_to_moved_list(&moved_list);
}
}
void AreaSW::set_transform(const Transform &p_transform) {
if (!moved_list.in_list() && get_space())
if (!moved_list.in_list() && get_space()) {
get_space()->area_add_to_moved_list(&moved_list);
}
_set_transform(p_transform);
_set_inv_transform(p_transform.affine_inverse());
@ -60,10 +62,12 @@ void AreaSW::set_transform(const Transform &p_transform) {
void AreaSW::set_space(SpaceSW *p_space) {
if (get_space()) {
if (monitor_query_list.in_list())
if (monitor_query_list.in_list()) {
get_space()->area_remove_from_monitor_query_list(&monitor_query_list);
if (moved_list.in_list())
}
if (moved_list.in_list()) {
get_space()->area_remove_from_moved_list(&moved_list);
}
}
monitored_bodies.clear();
@ -88,8 +92,9 @@ void AreaSW::set_monitor_callback(ObjectID p_id, const StringName &p_method) {
_shape_changed();
if (!moved_list.in_list() && get_space())
if (!moved_list.in_list() && get_space()) {
get_space()->area_add_to_moved_list(&moved_list);
}
}
void AreaSW::set_area_monitor_callback(ObjectID p_id, const StringName &p_method) {
@ -108,14 +113,16 @@ void AreaSW::set_area_monitor_callback(ObjectID p_id, const StringName &p_method
_shape_changed();
if (!moved_list.in_list() && get_space())
if (!moved_list.in_list() && get_space()) {
get_space()->area_add_to_moved_list(&moved_list);
}
}
void AreaSW::set_space_override_mode(PhysicsServer::AreaSpaceOverrideMode p_mode) {
bool do_override = p_mode != PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED;
if (do_override == (space_override_mode != PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED))
if (do_override == (space_override_mode != PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED)) {
return;
}
_unregister_shapes();
space_override_mode = p_mode;
_shape_changed();
@ -176,13 +183,15 @@ Variant AreaSW::get_param(PhysicsServer::AreaParameter p_param) const {
void AreaSW::_queue_monitor_update() {
ERR_FAIL_COND(!get_space());
if (!monitor_query_list.in_list())
if (!monitor_query_list.in_list()) {
get_space()->area_add_to_monitor_query_list(&monitor_query_list);
}
}
void AreaSW::set_monitorable(bool p_monitorable) {
if (monitorable == p_monitorable)
if (monitorable == p_monitorable) {
return;
}
monitorable = p_monitorable;
_set_static(!monitorable);
@ -192,8 +201,9 @@ void AreaSW::call_queries() {
if (monitor_callback_id && !monitored_bodies.empty()) {
Variant res[5];
Variant *resptr[5];
for (int i = 0; i < 5; i++)
for (int i = 0; i < 5; i++) {
resptr[i] = &res[i];
}
Object *obj = ObjectDB::get_instance(monitor_callback_id);
if (!obj) {
@ -228,8 +238,9 @@ void AreaSW::call_queries() {
if (area_monitor_callback_id && !monitored_areas.empty()) {
Variant res[5];
Variant *resptr[5];
for (int i = 0; i < 5; i++)
for (int i = 0; i < 5; i++) {
resptr[i] = &res[i];
}
Object *obj = ObjectDB::get_instance(area_monitor_callback_id);
if (!obj) {

View File

@ -71,10 +71,12 @@ class AreaSW : public CollisionObjectSW {
if (rid == p_key.rid) {
if (body_shape == p_key.body_shape) {
return area_shape < p_key.area_shape;
} else
} else {
return body_shape < p_key.body_shape;
} else
}
} else {
return rid < p_key.rid;
}
}
_FORCE_INLINE_ BodyKey() {}
@ -167,27 +169,31 @@ public:
void AreaSW::add_body_to_query(BodySW *p_body, uint32_t p_body_shape, uint32_t p_area_shape) {
BodyKey bk(p_body, p_body_shape, p_area_shape);
monitored_bodies[bk].inc();
if (!monitor_query_list.in_list())
if (!monitor_query_list.in_list()) {
_queue_monitor_update();
}
}
void AreaSW::remove_body_from_query(BodySW *p_body, uint32_t p_body_shape, uint32_t p_area_shape) {
BodyKey bk(p_body, p_body_shape, p_area_shape);
monitored_bodies[bk].dec();
if (!monitor_query_list.in_list())
if (!monitor_query_list.in_list()) {
_queue_monitor_update();
}
}
void AreaSW::add_area_to_query(AreaSW *p_area, uint32_t p_area_shape, uint32_t p_self_shape) {
BodyKey bk(p_area, p_area_shape, p_self_shape);
monitored_areas[bk].inc();
if (!monitor_query_list.in_list())
if (!monitor_query_list.in_list()) {
_queue_monitor_update();
}
}
void AreaSW::remove_area_from_query(AreaSW *p_area, uint32_t p_area_shape, uint32_t p_self_shape) {
BodyKey bk(p_area, p_area_shape, p_self_shape);
monitored_areas[bk].dec();
if (!monitor_query_list.in_list())
if (!monitor_query_list.in_list()) {
_queue_monitor_update();
}
}
#endif // AREA__SW_H

View File

@ -162,8 +162,9 @@ void BodyPairSW::validate_contacts() {
bool BodyPairSW::_test_ccd(real_t p_step, BodySW *p_A, int p_shape_A, const Transform &p_xform_A, BodySW *p_B, int p_shape_B, const Transform &p_xform_B) {
Vector3 motion = p_A->get_linear_velocity() * p_step;
real_t mlen = motion.length();
if (mlen < CMP_EPSILON)
if (mlen < CMP_EPSILON) {
return false;
}
Vector3 mnormal = motion / mlen;
@ -257,12 +258,13 @@ bool BodyPairSW::setup(real_t p_step) {
real_t bias = (real_t)0.3;
if (shape_A_ptr->get_custom_bias() || shape_B_ptr->get_custom_bias()) {
if (shape_A_ptr->get_custom_bias() == 0)
if (shape_A_ptr->get_custom_bias() == 0) {
bias = shape_B_ptr->get_custom_bias();
else if (shape_B_ptr->get_custom_bias() == 0)
} else if (shape_B_ptr->get_custom_bias() == 0) {
bias = shape_A_ptr->get_custom_bias();
else
} else {
bias = (shape_B_ptr->get_custom_bias() + shape_A_ptr->get_custom_bias()) * 0.5;
}
}
real_t inv_dt = 1.0 / p_step;
@ -338,13 +340,15 @@ bool BodyPairSW::setup(real_t p_step) {
}
void BodyPairSW::solve(real_t p_step) {
if (!collided)
if (!collided) {
return;
}
for (int i = 0; i < contact_count; i++) {
Contact &c = contacts[i];
if (!c.active)
if (!c.active) {
continue;
}
c.active = false; //try to deactivate, will activate itself if still needed

View File

@ -33,8 +33,9 @@
#include "space_sw.h"
void BodySW::_update_inertia() {
if (get_space() && !inertia_update_list.in_list())
if (get_space() && !inertia_update_list.in_list()) {
get_space()->body_add_to_inertia_update_list(&inertia_update_list);
}
}
void BodySW::_update_transform_dependant() {
@ -113,10 +114,11 @@ void BodySW::update_inertias() {
principal_inertia_axes_local = inertia_tensor.diagonalize().transposed();
_inv_inertia = inertia_tensor.get_main_diagonal().inverse();
if (mass)
if (mass) {
_inv_mass = 1.0 / mass;
else
} else {
_inv_mass = 0;
}
} break;
@ -138,18 +140,22 @@ void BodySW::update_inertias() {
}
void BodySW::set_active(bool p_active) {
if (active == p_active)
if (active == p_active) {
return;
}
active = p_active;
if (!p_active) {
if (get_space())
if (get_space()) {
get_space()->body_remove_from_active_list(&active_list);
}
} else {
if (mode == PhysicsServer::BODY_MODE_STATIC)
if (mode == PhysicsServer::BODY_MODE_STATIC) {
return; //static bodies can't become active
if (get_space())
}
if (get_space()) {
get_space()->body_add_to_active_list(&active_list);
}
//still_time=0;
}
@ -291,8 +297,9 @@ void BodySW::set_state(PhysicsServer::BodyState p_state, const Variant &p_varian
Transform t = p_variant;
t.orthonormalize();
new_transform = get_transform(); //used as old to compute motion
if (new_transform == t)
if (new_transform == t) {
break;
}
_set_transform(t);
_set_inv_transform(get_transform().inverse());
}
@ -318,8 +325,9 @@ void BodySW::set_state(PhysicsServer::BodyState p_state, const Variant &p_varian
} break;
case PhysicsServer::BODY_STATE_SLEEPING: {
//?
if (mode == PhysicsServer::BODY_MODE_STATIC || mode == PhysicsServer::BODY_MODE_KINEMATIC)
if (mode == PhysicsServer::BODY_MODE_STATIC || mode == PhysicsServer::BODY_MODE_KINEMATIC) {
break;
}
bool do_sleep = p_variant;
if (do_sleep) {
linear_velocity = Vector3();
@ -333,8 +341,9 @@ void BodySW::set_state(PhysicsServer::BodyState p_state, const Variant &p_varian
} break;
case PhysicsServer::BODY_STATE_CAN_SLEEP: {
can_sleep = p_variant;
if (mode == PhysicsServer::BODY_MODE_RIGID && !active && !can_sleep)
if (mode == PhysicsServer::BODY_MODE_RIGID && !active && !can_sleep) {
set_active(true);
}
} break;
}
@ -363,20 +372,24 @@ Variant BodySW::get_state(PhysicsServer::BodyState p_state) const {
void BodySW::set_space(SpaceSW *p_space) {
if (get_space()) {
if (inertia_update_list.in_list())
if (inertia_update_list.in_list()) {
get_space()->body_remove_from_inertia_update_list(&inertia_update_list);
if (active_list.in_list())
}
if (active_list.in_list()) {
get_space()->body_remove_from_active_list(&active_list);
if (direct_state_query_list.in_list())
}
if (direct_state_query_list.in_list()) {
get_space()->body_remove_from_state_query_list(&direct_state_query_list);
}
}
_set_space(p_space);
if (get_space()) {
_update_inertia();
if (active)
if (active) {
get_space()->body_add_to_active_list(&active_list);
}
/*
_update_queries();
if (is_active()) {
@ -418,8 +431,9 @@ bool BodySW::is_axis_locked(PhysicsServer::BodyAxis p_axis) const {
}
void BodySW::integrate_forces(real_t p_step) {
if (mode == PhysicsServer::BODY_MODE_STATIC)
if (mode == PhysicsServer::BODY_MODE_STATIC) {
return;
}
AreaSW *def_area = get_space()->get_default_area();
// AreaSW *damp_area = def_area;
@ -464,15 +478,17 @@ void BodySW::integrate_forces(real_t p_step) {
gravity *= gravity_scale;
// If less than 0, override dampenings with that of the Body
if (angular_damp >= 0)
if (angular_damp >= 0) {
area_angular_damp = angular_damp;
}
/*
else
area_angular_damp=damp_area->get_angular_damp();
*/
if (linear_damp >= 0)
if (linear_damp >= 0) {
area_linear_damp = linear_damp;
}
/*
else
area_linear_damp=damp_area->get_linear_damp();
@ -505,13 +521,15 @@ void BodySW::integrate_forces(real_t p_step) {
real_t damp = 1.0 - p_step * area_linear_damp;
if (damp < 0) // reached zero in the given time
if (damp < 0) { // reached zero in the given time
damp = 0;
}
real_t angular_damp = 1.0 - p_step * area_angular_damp;
if (angular_damp < 0) // reached zero in the given time
if (angular_damp < 0) { // reached zero in the given time
angular_damp = 0;
}
linear_velocity *= damp;
angular_velocity *= angular_damp;
@ -544,11 +562,13 @@ void BodySW::integrate_forces(real_t p_step) {
}
void BodySW::integrate_velocities(real_t p_step) {
if (mode == PhysicsServer::BODY_MODE_STATIC)
if (mode == PhysicsServer::BODY_MODE_STATIC) {
return;
}
if (fi_callback)
if (fi_callback) {
get_space()->body_add_to_state_query_list(&direct_state_query_list);
}
//apply axis lock linear
for (int i = 0; i < 3; i++) {
@ -569,8 +589,9 @@ void BodySW::integrate_velocities(real_t p_step) {
if (mode == PhysicsServer::BODY_MODE_KINEMATIC) {
_set_transform(new_transform, false);
_set_inv_transform(new_transform.affine_inverse());
if (contacts.size() == 0 && linear_velocity == Vector3() && angular_velocity == Vector3())
if (contacts.size() == 0 && linear_velocity == Vector3() && angular_velocity == Vector3()) {
set_active(false); //stopped moving, deactivate
}
return;
}
@ -650,14 +671,17 @@ void BodySW::wakeup_neighbours() {
int bc = c->get_body_count();
for (int i = 0; i < bc; i++) {
if (i == E->get())
if (i == E->get()) {
continue;
}
BodySW *b = n[i];
if (b->mode != PhysicsServer::BODY_MODE_RIGID)
if (b->mode != PhysicsServer::BODY_MODE_RIGID) {
continue;
}
if (!b->is_active())
if (!b->is_active()) {
b->set_active(true);
}
}
}
}
@ -683,12 +707,13 @@ void BodySW::call_queries() {
}
bool BodySW::sleep_test(real_t p_step) {
if (mode == PhysicsServer::BODY_MODE_STATIC || mode == PhysicsServer::BODY_MODE_KINEMATIC)
if (mode == PhysicsServer::BODY_MODE_STATIC || mode == PhysicsServer::BODY_MODE_KINEMATIC) {
return true; //
else if (mode == PhysicsServer::BODY_MODE_CHARACTER)
} else if (mode == PhysicsServer::BODY_MODE_CHARACTER) {
return !active; // characters don't sleep unless asked to sleep
else if (!can_sleep)
} else if (!can_sleep) {
return false;
}
if (Math::abs(angular_velocity.length()) < get_space()->get_body_angular_velocity_sleep_threshold() && Math::abs(linear_velocity.length_squared()) < get_space()->get_body_linear_velocity_sleep_threshold() * get_space()->get_body_linear_velocity_sleep_threshold()) {
still_time += p_step;
@ -756,8 +781,9 @@ BodySW::BodySW() :
}
BodySW::~BodySW() {
if (fi_callback)
if (fi_callback) {
memdelete(fi_callback);
}
}
PhysicsDirectBodyStateSW *PhysicsDirectBodyStateSW::singleton = nullptr;

View File

@ -163,16 +163,18 @@ public:
int index = areas.find(AreaCMP(p_area));
if (index > -1) {
areas.write[index].refCount -= 1;
if (areas[index].refCount < 1)
if (areas[index].refCount < 1) {
areas.remove(index);
}
}
}
_FORCE_INLINE_ void set_max_contacts_reported(int p_size) {
contacts.resize(p_size);
contact_count = 0;
if (mode == PhysicsServer::BODY_MODE_KINEMATIC && p_size)
if (mode == PhysicsServer::BODY_MODE_KINEMATIC && p_size) {
set_active(true);
}
}
_FORCE_INLINE_ int get_max_contacts_reported() const { return contacts.size(); }
@ -259,8 +261,9 @@ public:
_FORCE_INLINE_ bool is_active() const { return active; }
_FORCE_INLINE_ void wakeup() {
if ((!get_space()) || mode == PhysicsServer::BODY_MODE_STATIC || mode == PhysicsServer::BODY_MODE_KINEMATIC)
if ((!get_space()) || mode == PhysicsServer::BODY_MODE_STATIC || mode == PhysicsServer::BODY_MODE_KINEMATIC) {
return;
}
set_active(true);
}
@ -332,8 +335,9 @@ public:
void BodySW::add_contact(const Vector3 &p_local_pos, const Vector3 &p_local_normal, real_t p_depth, int p_local_shape, const Vector3 &p_collider_pos, int p_collider_shape, ObjectID p_collider_instance_id, const RID &p_collider, const Vector3 &p_collider_velocity_at_pos) {
int c_max = contacts.size();
if (c_max == 0)
if (c_max == 0) {
return;
}
Contact *c = contacts.ptrw();
@ -354,8 +358,9 @@ void BodySW::add_contact(const Vector3 &p_local_pos, const Vector3 &p_local_norm
if (least_deep >= 0 && least_depth < p_depth) {
idx = least_deep;
}
if (idx == -1)
if (idx == -1) {
return; //none least deepe than this
}
}
c[idx].local_pos = p_local_pos;

View File

@ -103,8 +103,9 @@ int BroadPhaseBasic::cull_point(const Vector3 &p_point, CollisionObjectSW **p_re
p_results[rc] = E->get().owner;
p_result_indices[rc] = E->get().subindex;
rc++;
if (rc >= p_max_results)
if (rc >= p_max_results) {
break;
}
}
}
@ -120,8 +121,9 @@ int BroadPhaseBasic::cull_segment(const Vector3 &p_from, const Vector3 &p_to, Co
p_results[rc] = E->get().owner;
p_result_indices[rc] = E->get().subindex;
rc++;
if (rc >= p_max_results)
if (rc >= p_max_results) {
break;
}
}
}
@ -136,8 +138,9 @@ int BroadPhaseBasic::cull_aabb(const AABB &p_aabb, CollisionObjectSW **p_results
p_results[rc] = E->get().owner;
p_result_indices[rc] = E->get().subindex;
rc++;
if (rc >= p_max_results)
if (rc >= p_max_results) {
break;
}
}
}
@ -160,8 +163,9 @@ void BroadPhaseBasic::update() {
Element *elem_A = &I->get();
Element *elem_B = &J->get();
if (elem_A->owner == elem_B->owner)
if (elem_A->owner == elem_B->owner) {
continue;
}
bool pair_ok = elem_A->aabb.intersects(elem_B->aabb) && (!elem_A->_static || !elem_B->_static);
@ -170,8 +174,9 @@ void BroadPhaseBasic::update() {
Map<PairKey, void *>::Element *E = pair_map.find(key);
if (!pair_ok && E) {
if (unpair_callback)
if (unpair_callback) {
unpair_callback(elem_A->owner, elem_A->subindex, elem_B->owner, elem_B->subindex, E->get(), unpair_userdata);
}
pair_map.erase(key);
}

View File

@ -75,16 +75,18 @@ int BroadPhaseBVH::cull_aabb(const AABB &p_aabb, CollisionObjectSW **p_results,
void *BroadPhaseBVH::_pair_callback(void *self, uint32_t p_A, CollisionObjectSW *p_object_A, int subindex_A, uint32_t p_B, CollisionObjectSW *p_object_B, int subindex_B) {
BroadPhaseBVH *bpo = (BroadPhaseBVH *)(self);
if (!bpo->pair_callback)
if (!bpo->pair_callback) {
return nullptr;
}
return bpo->pair_callback(p_object_A, subindex_A, p_object_B, subindex_B, bpo->pair_userdata);
}
void BroadPhaseBVH::_unpair_callback(void *self, uint32_t p_A, CollisionObjectSW *p_object_A, int subindex_A, uint32_t p_B, CollisionObjectSW *p_object_B, int subindex_B, void *pairdata) {
BroadPhaseBVH *bpo = (BroadPhaseBVH *)(self);
if (!bpo->unpair_callback)
if (!bpo->unpair_callback) {
return;
}
bpo->unpair_callback(p_object_A, subindex_A, p_object_B, subindex_B, pairdata, bpo->unpair_userdata);
}

View File

@ -74,16 +74,18 @@ int BroadPhaseOctree::cull_aabb(const AABB &p_aabb, CollisionObjectSW **p_result
void *BroadPhaseOctree::_pair_callback(void *self, OctreeElementID p_A, CollisionObjectSW *p_object_A, int subindex_A, OctreeElementID p_B, CollisionObjectSW *p_object_B, int subindex_B) {
BroadPhaseOctree *bpo = (BroadPhaseOctree *)(self);
if (!bpo->pair_callback)
if (!bpo->pair_callback) {
return nullptr;
}
return bpo->pair_callback(p_object_A, subindex_A, p_object_B, subindex_B, bpo->pair_userdata);
}
void BroadPhaseOctree::_unpair_callback(void *self, OctreeElementID p_A, CollisionObjectSW *p_object_A, int subindex_A, OctreeElementID p_B, CollisionObjectSW *p_object_B, int subindex_B, void *pairdata) {
BroadPhaseOctree *bpo = (BroadPhaseOctree *)(self);
if (!bpo->unpair_callback)
if (!bpo->unpair_callback) {
return;
}
bpo->unpair_callback(p_object_A, subindex_A, p_object_B, subindex_B, pairdata, bpo->unpair_userdata);
}

View File

@ -94,8 +94,9 @@ void CollisionObjectSW::remove_shape(int p_index) {
//remove anything from shape to be erased to end, so subindices don't change
ERR_FAIL_INDEX(p_index, shapes.size());
for (int i = p_index; i < shapes.size(); i++) {
if (shapes[i].bpid == 0)
if (shapes[i].bpid == 0) {
continue;
}
//should never get here with a null owner
space->get_broadphase()->remove(shapes[i].bpid);
shapes.write[i].bpid = 0;
@ -111,12 +112,14 @@ void CollisionObjectSW::remove_shape(int p_index) {
}
void CollisionObjectSW::_set_static(bool p_static) {
if (_static == p_static)
if (_static == p_static) {
return;
}
_static = p_static;
if (!space)
if (!space) {
return;
}
for (int i = 0; i < get_shape_count(); i++) {
const Shape &s = shapes[i];
if (s.bpid > 0) {
@ -136,8 +139,9 @@ void CollisionObjectSW::_unregister_shapes() {
}
void CollisionObjectSW::_update_shapes() {
if (!space)
if (!space) {
return;
}
for (int i = 0; i < shapes.size(); i++) {
Shape &s = shapes.write[i];
@ -162,8 +166,9 @@ void CollisionObjectSW::_update_shapes() {
}
void CollisionObjectSW::_update_shapes_with_motion(const Vector3 &p_motion) {
if (!space)
if (!space) {
return;
}
for (int i = 0; i < shapes.size(); i++) {
Shape &s = shapes.write[i];

View File

@ -91,8 +91,9 @@ protected:
#endif
transform = p_transform;
if (p_update_shapes)
if (p_update_shapes) {
_update_shapes();
}
}
_FORCE_INLINE_ void _set_inv_transform(const Transform &p_transform) { inv_transform = p_transform; }
void _set_static(bool p_static);

View File

@ -73,10 +73,11 @@ struct _CollectorCallback {
Vector3 *prev_axis;
_FORCE_INLINE_ void call(const Vector3 &p_point_A, const Vector3 &p_point_B) {
if (swap)
if (swap) {
callback(p_point_B, p_point_A, userdata);
else
} else {
callback(p_point_A, p_point_B, userdata);
}
}
};
@ -158,10 +159,11 @@ static void _generate_contacts_edge_edge(const Vector3 *p_points_A, int p_point_
real_t d = (c.dot(p_points_B[0]) - p_points_A[0].dot(c)) / rel_A.dot(c);
if (d < 0.0)
if (d < 0.0) {
d = 0.0;
else if (d > 1.0)
} else if (d > 1.0) {
d = 1.0;
}
Vector3 closest_A = p_points_A[0] + rel_A * d;
Vector3 closest_B = Geometry::get_closest_point_to_segment_uncapped(closest_A, p_points_B);
@ -347,8 +349,9 @@ static void _generate_contacts_face_face(const Vector3 *p_points_A, int p_point_
Vector3 closest_B = clipbuf_src[i] - plane_B.normal * d;
if (p_callback->normal.dot(clipbuf_src[i]) >= p_callback->normal.dot(closest_B))
if (p_callback->normal.dot(clipbuf_src[i]) >= p_callback->normal.dot(closest_B)) {
continue;
}
p_callback->call(clipbuf_src[i], closest_B);
}
@ -616,10 +619,11 @@ class SeparatorAxisTest {
public:
_FORCE_INLINE_ bool test_previous_axis() {
if (callback && callback->prev_axis && *callback->prev_axis != Vector3())
if (callback && callback->prev_axis && *callback->prev_axis != Vector3()) {
return test_axis(*callback->prev_axis);
else
} else {
return true;
}
}
_FORCE_INLINE_ bool test_axis(const Vector3 &p_axis) {
@ -689,14 +693,16 @@ public:
_FORCE_INLINE_ void generate_contacts() {
// nothing to do, don't generate
if (best_axis == Vector3(0.0, 0.0, 0.0))
if (best_axis == Vector3(0.0, 0.0, 0.0)) {
return;
}
if (!callback->callback) {
//just was checking intersection?
callback->collided = true;
if (callback->prev_axis)
if (callback->prev_axis) {
*callback->prev_axis = best_axis;
}
return;
}
@ -731,8 +737,9 @@ public:
}
callback->normal = best_axis;
if (callback->prev_axis)
if (callback->prev_axis) {
*callback->prev_axis = best_axis;
}
_generate_contacts_from_supports(supports_A, support_count_A, support_type_A, supports_B, support_count_B, support_type_B, callback);
callback->collided = true;
@ -763,11 +770,13 @@ static void _collision_sphere_sphere(const ShapeSW *p_a, const Transform &p_tran
// previous axis
if (!separator.test_previous_axis())
if (!separator.test_previous_axis()) {
return;
}
if (!separator.test_axis((p_transform_a.origin - p_transform_b.origin).normalized()))
if (!separator.test_axis((p_transform_a.origin - p_transform_b.origin).normalized())) {
return;
}
separator.generate_contacts();
}
@ -779,16 +788,18 @@ static void _collision_sphere_box(const ShapeSW *p_a, const Transform &p_transfo
SeparatorAxisTest<SphereShapeSW, BoxShapeSW, withMargin> separator(sphere_A, p_transform_a, box_B, p_transform_b, p_collector, p_margin_a, p_margin_b);
if (!separator.test_previous_axis())
if (!separator.test_previous_axis()) {
return;
}
// test faces
for (int i = 0; i < 3; i++) {
Vector3 axis = p_transform_b.basis.get_axis(i).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
// calculate closest point to sphere
@ -804,16 +815,18 @@ static void _collision_sphere_box(const ShapeSW *p_a, const Transform &p_transfo
// use point to test axis
Vector3 point_axis = (p_transform_a.origin - cpoint).normalized();
if (!separator.test_axis(point_axis))
if (!separator.test_axis(point_axis)) {
return;
}
// test edges
for (int i = 0; i < 3; i++) {
Vector3 axis = point_axis.cross(p_transform_b.basis.get_axis(i)).cross(p_transform_b.basis.get_axis(i)).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
separator.generate_contacts();
@ -826,8 +839,9 @@ static void _collision_sphere_capsule(const ShapeSW *p_a, const Transform &p_tra
SeparatorAxisTest<SphereShapeSW, CapsuleShapeSW, withMargin> separator(sphere_A, p_transform_a, capsule_B, p_transform_b, p_collector, p_margin_a, p_margin_b);
if (!separator.test_previous_axis())
if (!separator.test_previous_axis()) {
return;
}
//capsule sphere 1, sphere
@ -835,15 +849,17 @@ static void _collision_sphere_capsule(const ShapeSW *p_a, const Transform &p_tra
Vector3 capsule_ball_1 = p_transform_b.origin + capsule_axis;
if (!separator.test_axis((capsule_ball_1 - p_transform_a.origin).normalized()))
if (!separator.test_axis((capsule_ball_1 - p_transform_a.origin).normalized())) {
return;
}
//capsule sphere 2, sphere
Vector3 capsule_ball_2 = p_transform_b.origin - capsule_axis;
if (!separator.test_axis((capsule_ball_2 - p_transform_a.origin).normalized()))
if (!separator.test_axis((capsule_ball_2 - p_transform_a.origin).normalized())) {
return;
}
//capsule edge, sphere
@ -851,8 +867,9 @@ static void _collision_sphere_capsule(const ShapeSW *p_a, const Transform &p_tra
Vector3 axis = b2a.cross(capsule_axis).cross(capsule_axis).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
separator.generate_contacts();
}
@ -864,8 +881,9 @@ static void _collision_sphere_cylinder(const ShapeSW *p_a, const Transform &p_tr
SeparatorAxisTest<SphereShapeSW, CylinderShapeSW, withMargin> separator(sphere_A, p_transform_a, cylinder_B, p_transform_b, p_collector, p_margin_a, p_margin_b);
if (!separator.test_previous_axis())
if (!separator.test_previous_axis()) {
return;
}
// Cylinder B end caps.
Vector3 cylinder_B_axis = p_transform_b.basis.get_axis(1).normalized();
@ -922,8 +940,9 @@ static void _collision_sphere_convex_polygon(const ShapeSW *p_a, const Transform
SeparatorAxisTest<SphereShapeSW, ConvexPolygonShapeSW, withMargin> separator(sphere_A, p_transform_a, convex_polygon_B, p_transform_b, p_collector, p_margin_a, p_margin_b);
if (!separator.test_previous_axis())
if (!separator.test_previous_axis()) {
return;
}
const Geometry::MeshData &mesh = convex_polygon_B->get_mesh();
@ -938,8 +957,9 @@ static void _collision_sphere_convex_polygon(const ShapeSW *p_a, const Transform
for (int i = 0; i < face_count; i++) {
Vector3 axis = p_transform_b.xform(faces[i].plane).normal;
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
// edges of B
@ -953,8 +973,9 @@ static void _collision_sphere_convex_polygon(const ShapeSW *p_a, const Transform
Vector3 axis = n1.cross(n2).cross(n1).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
// vertices of B
@ -964,8 +985,9 @@ static void _collision_sphere_convex_polygon(const ShapeSW *p_a, const Transform
Vector3 axis = (v2 - v1).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
separator.generate_contacts();
@ -984,8 +1006,9 @@ static void _collision_sphere_face(const ShapeSW *p_a, const Transform &p_transf
p_transform_b.xform(face_B->vertex[2]),
};
if (!separator.test_axis((vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]).normalized()))
if (!separator.test_axis((vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]).normalized())) {
return;
}
// edges and points of B
for (int i = 0; i < 3; i++) {
@ -1014,16 +1037,18 @@ static void _collision_box_box(const ShapeSW *p_a, const Transform &p_transform_
SeparatorAxisTest<BoxShapeSW, BoxShapeSW, withMargin> separator(box_A, p_transform_a, box_B, p_transform_b, p_collector, p_margin_a, p_margin_b);
if (!separator.test_previous_axis())
if (!separator.test_previous_axis()) {
return;
}
// test faces of A
for (int i = 0; i < 3; i++) {
Vector3 axis = p_transform_a.basis.get_axis(i).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
// test faces of B
@ -1031,8 +1056,9 @@ static void _collision_box_box(const ShapeSW *p_a, const Transform &p_transform_
for (int i = 0; i < 3; i++) {
Vector3 axis = p_transform_b.basis.get_axis(i).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
// test combined edges
@ -1040,8 +1066,9 @@ static void _collision_box_box(const ShapeSW *p_a, const Transform &p_transform_
for (int j = 0; j < 3; j++) {
Vector3 axis = p_transform_a.basis.get_axis(i).cross(p_transform_b.basis.get_axis(j));
if (Math::is_zero_approx(axis.length_squared()))
if (Math::is_zero_approx(axis.length_squared())) {
continue;
}
axis.normalize();
if (!separator.test_axis(axis)) {
@ -1085,14 +1112,16 @@ static void _collision_box_box(const ShapeSW *p_a, const Transform &p_transform_
//a ->b
Vector3 axis_a = p_transform_a.basis.get_axis(i);
if (!separator.test_axis(axis_ab.cross(axis_a).cross(axis_a).normalized()))
if (!separator.test_axis(axis_ab.cross(axis_a).cross(axis_a).normalized())) {
return;
}
//b ->a
Vector3 axis_b = p_transform_b.basis.get_axis(i);
if (!separator.test_axis(axis_ab.cross(axis_b).cross(axis_b).normalized()))
if (!separator.test_axis(axis_ab.cross(axis_b).cross(axis_b).normalized())) {
return;
}
}
}
@ -1106,15 +1135,17 @@ static void _collision_box_capsule(const ShapeSW *p_a, const Transform &p_transf
SeparatorAxisTest<BoxShapeSW, CapsuleShapeSW, withMargin> separator(box_A, p_transform_a, capsule_B, p_transform_b, p_collector, p_margin_a, p_margin_b);
if (!separator.test_previous_axis())
if (!separator.test_previous_axis()) {
return;
}
// faces of A
for (int i = 0; i < 3; i++) {
Vector3 axis = p_transform_a.basis.get_axis(i).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
Vector3 cyl_axis = p_transform_b.basis.get_axis(2).normalized();
@ -1125,11 +1156,13 @@ static void _collision_box_capsule(const ShapeSW *p_a, const Transform &p_transf
// cylinder
Vector3 box_axis = p_transform_a.basis.get_axis(i);
Vector3 axis = box_axis.cross(cyl_axis);
if (Math::is_zero_approx(axis.length_squared()))
if (Math::is_zero_approx(axis.length_squared())) {
continue;
}
if (!separator.test_axis(axis.normalized()))
if (!separator.test_axis(axis.normalized())) {
return;
}
}
// points of A, capsule cylinder
@ -1143,14 +1176,16 @@ static void _collision_box_capsule(const ShapeSW *p_a, const Transform &p_transf
he.y *= (j * 2 - 1);
he.z *= (k * 2 - 1);
Vector3 point = p_transform_a.origin;
for (int l = 0; l < 3; l++)
for (int l = 0; l < 3; l++) {
point += p_transform_a.basis.get_axis(l) * he[l];
}
//Vector3 axis = (point - cyl_axis * cyl_axis.dot(point)).normalized();
Vector3 axis = Plane(cyl_axis, 0).project(point).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
}
}
@ -1173,16 +1208,18 @@ static void _collision_box_capsule(const ShapeSW *p_a, const Transform &p_transf
// use point to test axis
Vector3 point_axis = (sphere_pos - cpoint).normalized();
if (!separator.test_axis(point_axis))
if (!separator.test_axis(point_axis)) {
return;
}
// test edges of A
for (int j = 0; j < 3; j++) {
Vector3 axis = point_axis.cross(p_transform_a.basis.get_axis(j)).cross(p_transform_a.basis.get_axis(j)).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
}
@ -1309,8 +1346,9 @@ static void _collision_box_convex_polygon(const ShapeSW *p_a, const Transform &p
SeparatorAxisTest<BoxShapeSW, ConvexPolygonShapeSW, withMargin> separator(box_A, p_transform_a, convex_polygon_B, p_transform_b, p_collector, p_margin_a, p_margin_b);
if (!separator.test_previous_axis())
if (!separator.test_previous_axis()) {
return;
}
const Geometry::MeshData &mesh = convex_polygon_B->get_mesh();
@ -1325,16 +1363,18 @@ static void _collision_box_convex_polygon(const ShapeSW *p_a, const Transform &p
for (int i = 0; i < 3; i++) {
Vector3 axis = p_transform_a.basis.get_axis(i).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
// faces of B
for (int i = 0; i < face_count; i++) {
Vector3 axis = p_transform_b.xform(faces[i].plane).normal;
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
// A<->B edges
@ -1346,8 +1386,9 @@ static void _collision_box_convex_polygon(const ShapeSW *p_a, const Transform &p
Vector3 axis = e1.cross(e2).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
}
@ -1377,8 +1418,9 @@ static void _collision_box_convex_polygon(const ShapeSW *p_a, const Transform &p
//a ->b
Vector3 axis_a = p_transform_a.basis.get_axis(i);
if (!separator.test_axis(axis_ab.cross(axis_a).cross(axis_a).normalized()))
if (!separator.test_axis(axis_ab.cross(axis_a).cross(axis_a).normalized())) {
return;
}
}
}
@ -1391,16 +1433,18 @@ static void _collision_box_convex_polygon(const ShapeSW *p_a, const Transform &p
he.y *= (j * 2 - 1);
he.z *= (k * 2 - 1);
Vector3 point = p_transform_a.origin;
for (int l = 0; l < 3; l++)
for (int l = 0; l < 3; l++) {
point += p_transform_a.basis.get_axis(l) * he[l];
}
for (int e = 0; e < edge_count; e++) {
Vector3 p1 = p_transform_b.xform(vertices[edges[e].a]);
Vector3 p2 = p_transform_b.xform(vertices[edges[e].b]);
Vector3 n = (p2 - p1);
if (!separator.test_axis((point - p2).cross(n).cross(n).normalized()))
if (!separator.test_axis((point - p2).cross(n).cross(n).normalized())) {
return;
}
}
}
}
@ -1423,15 +1467,17 @@ static void _collision_box_face(const ShapeSW *p_a, const Transform &p_transform
p_transform_b.xform(face_B->vertex[2]),
};
if (!separator.test_axis((vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]).normalized()))
if (!separator.test_axis((vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]).normalized())) {
return;
}
// faces of A
for (int i = 0; i < 3; i++) {
Vector3 axis = p_transform_a.basis.get_axis(i).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
// combined edges
@ -1442,8 +1488,9 @@ static void _collision_box_face(const ShapeSW *p_a, const Transform &p_transform
for (int j = 0; j < 3; j++) {
Vector3 axis = p_transform_a.basis.get_axis(j);
if (!separator.test_axis(e.cross(axis).normalized()))
if (!separator.test_axis(e.cross(axis).normalized())) {
return;
}
}
}
@ -1472,8 +1519,9 @@ static void _collision_box_face(const ShapeSW *p_a, const Transform &p_transform
//a ->b
Vector3 axis_a = p_transform_a.basis.get_axis(i);
if (!separator.test_axis(axis_ab.cross(axis_a).cross(axis_a).normalized()))
if (!separator.test_axis(axis_ab.cross(axis_a).cross(axis_a).normalized())) {
return;
}
}
}
@ -1486,8 +1534,9 @@ static void _collision_box_face(const ShapeSW *p_a, const Transform &p_transform
he.y *= (j * 2 - 1);
he.z *= (k * 2 - 1);
Vector3 point = p_transform_a.origin;
for (int l = 0; l < 3; l++)
for (int l = 0; l < 3; l++) {
point += p_transform_a.basis.get_axis(l) * he[l];
}
for (int e = 0; e < 3; e++) {
Vector3 p1 = vertex[e];
@ -1495,8 +1544,9 @@ static void _collision_box_face(const ShapeSW *p_a, const Transform &p_transform
Vector3 n = (p2 - p1);
if (!separator.test_axis((point - p2).cross(n).cross(n).normalized()))
if (!separator.test_axis((point - p2).cross(n).cross(n).normalized())) {
return;
}
}
}
}
@ -1513,8 +1563,9 @@ static void _collision_capsule_capsule(const ShapeSW *p_a, const Transform &p_tr
SeparatorAxisTest<CapsuleShapeSW, CapsuleShapeSW, withMargin> separator(capsule_A, p_transform_a, capsule_B, p_transform_b, p_collector, p_margin_a, p_margin_b);
if (!separator.test_previous_axis())
if (!separator.test_previous_axis()) {
return;
}
// some values
@ -1528,34 +1579,43 @@ static void _collision_capsule_capsule(const ShapeSW *p_a, const Transform &p_tr
//balls-balls
if (!separator.test_axis((capsule_A_ball_1 - capsule_B_ball_1).normalized()))
if (!separator.test_axis((capsule_A_ball_1 - capsule_B_ball_1).normalized())) {
return;
if (!separator.test_axis((capsule_A_ball_1 - capsule_B_ball_2).normalized()))
}
if (!separator.test_axis((capsule_A_ball_1 - capsule_B_ball_2).normalized())) {
return;
}
if (!separator.test_axis((capsule_A_ball_2 - capsule_B_ball_1).normalized()))
if (!separator.test_axis((capsule_A_ball_2 - capsule_B_ball_1).normalized())) {
return;
if (!separator.test_axis((capsule_A_ball_2 - capsule_B_ball_2).normalized()))
}
if (!separator.test_axis((capsule_A_ball_2 - capsule_B_ball_2).normalized())) {
return;
}
// edges-balls
if (!separator.test_axis((capsule_A_ball_1 - capsule_B_ball_1).cross(capsule_A_axis).cross(capsule_A_axis).normalized()))
if (!separator.test_axis((capsule_A_ball_1 - capsule_B_ball_1).cross(capsule_A_axis).cross(capsule_A_axis).normalized())) {
return;
}
if (!separator.test_axis((capsule_A_ball_1 - capsule_B_ball_2).cross(capsule_A_axis).cross(capsule_A_axis).normalized()))
if (!separator.test_axis((capsule_A_ball_1 - capsule_B_ball_2).cross(capsule_A_axis).cross(capsule_A_axis).normalized())) {
return;
}
if (!separator.test_axis((capsule_B_ball_1 - capsule_A_ball_1).cross(capsule_B_axis).cross(capsule_B_axis).normalized()))
if (!separator.test_axis((capsule_B_ball_1 - capsule_A_ball_1).cross(capsule_B_axis).cross(capsule_B_axis).normalized())) {
return;
}
if (!separator.test_axis((capsule_B_ball_1 - capsule_A_ball_2).cross(capsule_B_axis).cross(capsule_B_axis).normalized()))
if (!separator.test_axis((capsule_B_ball_1 - capsule_A_ball_2).cross(capsule_B_axis).cross(capsule_B_axis).normalized())) {
return;
}
// edges
if (!separator.test_axis(capsule_A_axis.cross(capsule_B_axis).normalized()))
if (!separator.test_axis(capsule_A_axis.cross(capsule_B_axis).normalized())) {
return;
}
separator.generate_contacts();
}
@ -1629,8 +1689,9 @@ static void _collision_capsule_convex_polygon(const ShapeSW *p_a, const Transfor
SeparatorAxisTest<CapsuleShapeSW, ConvexPolygonShapeSW, withMargin> separator(capsule_A, p_transform_a, convex_polygon_B, p_transform_b, p_collector, p_margin_a, p_margin_b);
if (!separator.test_previous_axis())
if (!separator.test_previous_axis()) {
return;
}
const Geometry::MeshData &mesh = convex_polygon_B->get_mesh();
@ -1644,8 +1705,9 @@ static void _collision_capsule_convex_polygon(const ShapeSW *p_a, const Transfor
for (int i = 0; i < face_count; i++) {
Vector3 axis = p_transform_b.xform(faces[i].plane).normal;
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
// edges of B, capsule cylinder
@ -1655,8 +1717,9 @@ static void _collision_capsule_convex_polygon(const ShapeSW *p_a, const Transfor
Vector3 edge_axis = p_transform_b.basis.xform(vertices[edges[i].a]) - p_transform_b.basis.xform(vertices[edges[i].b]);
Vector3 axis = edge_axis.cross(p_transform_a.basis.get_axis(2)).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
// capsule balls, edges of B
@ -1674,8 +1737,9 @@ static void _collision_capsule_convex_polygon(const ShapeSW *p_a, const Transfor
Vector3 axis = n1.cross(n2).cross(n2).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
}
@ -1695,8 +1759,9 @@ static void _collision_capsule_face(const ShapeSW *p_a, const Transform &p_trans
p_transform_b.xform(face_B->vertex[2]),
};
if (!separator.test_axis((vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]).normalized()))
if (!separator.test_axis((vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]).normalized())) {
return;
}
// edges of B, capsule cylinder
@ -1707,11 +1772,13 @@ static void _collision_capsule_face(const ShapeSW *p_a, const Transform &p_trans
Vector3 edge_axis = vertex[i] - vertex[(i + 1) % 3];
Vector3 axis = edge_axis.cross(capsule_axis).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
if (!separator.test_axis((p_transform_a.origin - vertex[i]).cross(capsule_axis).cross(capsule_axis).normalized()))
if (!separator.test_axis((p_transform_a.origin - vertex[i]).cross(capsule_axis).cross(capsule_axis).normalized())) {
return;
}
for (int j = 0; j < 2; j++) {
// point-spheres
@ -1719,15 +1786,17 @@ static void _collision_capsule_face(const ShapeSW *p_a, const Transform &p_trans
Vector3 n1 = sphere_pos - vertex[i];
if (!separator.test_axis(n1.normalized()))
if (!separator.test_axis(n1.normalized())) {
return;
}
Vector3 n2 = edge_axis;
axis = n1.cross(n2).cross(n2);
if (!separator.test_axis(axis.normalized()))
if (!separator.test_axis(axis.normalized())) {
return;
}
}
}
@ -1904,8 +1973,9 @@ static void _collision_convex_polygon_convex_polygon(const ShapeSW *p_a, const T
SeparatorAxisTest<ConvexPolygonShapeSW, ConvexPolygonShapeSW, withMargin> separator(convex_polygon_A, p_transform_a, convex_polygon_B, p_transform_b, p_collector, p_margin_a, p_margin_b);
if (!separator.test_previous_axis())
if (!separator.test_previous_axis()) {
return;
}
const Geometry::MeshData &mesh_A = convex_polygon_A->get_mesh();
@ -1930,8 +2000,9 @@ static void _collision_convex_polygon_convex_polygon(const ShapeSW *p_a, const T
Vector3 axis = p_transform_a.xform(faces_A[i].plane).normal;
//Vector3 axis = p_transform_a.basis.xform( faces_A[i].plane.normal ).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
// faces of B
@ -1939,8 +2010,9 @@ static void _collision_convex_polygon_convex_polygon(const ShapeSW *p_a, const T
Vector3 axis = p_transform_b.xform(faces_B[i].plane).normal;
//Vector3 axis = p_transform_b.basis.xform( faces_B[i].plane.normal ).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
// A<->B edges
@ -1952,8 +2024,9 @@ static void _collision_convex_polygon_convex_polygon(const ShapeSW *p_a, const T
Vector3 axis = e1.cross(e2).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
}
@ -1963,8 +2036,9 @@ static void _collision_convex_polygon_convex_polygon(const ShapeSW *p_a, const T
Vector3 va = p_transform_a.xform(vertices_A[i]);
for (int j = 0; j < vertex_count_B; j++) {
if (!separator.test_axis((va - p_transform_b.xform(vertices_B[j])).normalized()))
if (!separator.test_axis((va - p_transform_b.xform(vertices_B[j])).normalized())) {
return;
}
}
}
//edge-vertex (shell)
@ -1977,8 +2051,9 @@ static void _collision_convex_polygon_convex_polygon(const ShapeSW *p_a, const T
for (int j = 0; j < vertex_count_B; j++) {
Vector3 e3 = p_transform_b.xform(vertices_B[j]);
if (!separator.test_axis((e1 - e3).cross(n).cross(n).normalized()))
if (!separator.test_axis((e1 - e3).cross(n).cross(n).normalized())) {
return;
}
}
}
@ -1990,8 +2065,9 @@ static void _collision_convex_polygon_convex_polygon(const ShapeSW *p_a, const T
for (int j = 0; j < vertex_count_A; j++) {
Vector3 e3 = p_transform_a.xform(vertices_A[j]);
if (!separator.test_axis((e1 - e3).cross(n).cross(n).normalized()))
if (!separator.test_axis((e1 - e3).cross(n).cross(n).normalized())) {
return;
}
}
}
}
@ -2021,16 +2097,18 @@ static void _collision_convex_polygon_face(const ShapeSW *p_a, const Transform &
p_transform_b.xform(face_B->vertex[2]),
};
if (!separator.test_axis((vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]).normalized()))
if (!separator.test_axis((vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]).normalized())) {
return;
}
// faces of A
for (int i = 0; i < face_count; i++) {
//Vector3 axis = p_transform_a.xform( faces[i].plane ).normal;
Vector3 axis = p_transform_a.basis.xform(faces[i].plane.normal).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
// A<->B edges
@ -2042,8 +2120,9 @@ static void _collision_convex_polygon_face(const ShapeSW *p_a, const Transform &
Vector3 axis = e1.cross(e2).normalized();
if (!separator.test_axis(axis))
if (!separator.test_axis(axis)) {
return;
}
}
}
@ -2053,8 +2132,9 @@ static void _collision_convex_polygon_face(const ShapeSW *p_a, const Transform &
Vector3 va = p_transform_a.xform(vertices[i]);
for (int j = 0; j < 3; j++) {
if (!separator.test_axis((va - vertex[j]).normalized()))
if (!separator.test_axis((va - vertex[j]).normalized())) {
return;
}
}
}
//edge-vertex (shell)
@ -2067,8 +2147,9 @@ static void _collision_convex_polygon_face(const ShapeSW *p_a, const Transform &
for (int j = 0; j < 3; j++) {
Vector3 e3 = vertex[j];
if (!separator.test_axis((e1 - e3).cross(n).cross(n).normalized()))
if (!separator.test_axis((e1 - e3).cross(n).cross(n).normalized())) {
return;
}
}
}
@ -2080,8 +2161,9 @@ static void _collision_convex_polygon_face(const ShapeSW *p_a, const Transform &
for (int j = 0; j < vertex_count; j++) {
Vector3 e3 = p_transform_a.xform(vertices[j]);
if (!separator.test_axis((e1 - e3).cross(n).cross(n).normalized()))
if (!separator.test_axis((e1 - e3).cross(n).cross(n).normalized())) {
return;
}
}
}
}

View File

@ -38,8 +38,9 @@
bool CollisionSolverSW::solve_static_plane(const ShapeSW *p_shape_A, const Transform &p_transform_A, const ShapeSW *p_shape_B, const Transform &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result) {
const PlaneShapeSW *plane = static_cast<const PlaneShapeSW *>(p_shape_A);
if (p_shape_B->get_type() == PhysicsServer::SHAPE_PLANE)
if (p_shape_B->get_type() == PhysicsServer::SHAPE_PLANE) {
return false;
}
Plane p = p_transform_A.xform(plane->get_plane());
static const int max_supports = 16;
@ -69,17 +70,19 @@ bool CollisionSolverSW::solve_static_plane(const ShapeSW *p_shape_A, const Trans
for (int i = 0; i < support_count; i++) {
supports[i] = p_transform_B.xform(supports[i]);
if (p.distance_to(supports[i]) >= 0)
if (p.distance_to(supports[i]) >= 0) {
continue;
}
found = true;
Vector3 support_A = p.project(supports[i]);
if (p_result_callback) {
if (p_swap_result)
if (p_swap_result) {
p_result_callback(supports[i], support_A, p_userdata);
else
} else {
p_result_callback(support_A, supports[i], p_userdata);
}
}
}
@ -99,8 +102,9 @@ bool CollisionSolverSW::solve_ray(const ShapeSW *p_shape_A, const Transform &p_t
to = ai.xform(to);
Vector3 p, n;
if (!p_shape_B->intersect_segment(from, to, p, n))
if (!p_shape_B->intersect_segment(from, to, p, n)) {
return false;
}
Vector3 support_B = p_transform_B.xform(p);
if (ray->get_slips_on_slope()) {
@ -109,10 +113,11 @@ bool CollisionSolverSW::solve_ray(const ShapeSW *p_shape_A, const Transform &p_t
}
if (p_result_callback) {
if (p_swap_result)
if (p_swap_result) {
p_result_callback(support_B, support_A, p_userdata);
else
} else {
p_result_callback(support_A, support_B, p_userdata);
}
}
return true;
}
@ -138,8 +143,9 @@ void CollisionSolverSW::concave_callback(void *p_userdata, ShapeSW *p_convex) {
cinfo.aabb_tests++;
bool collided = collision_solver(cinfo.shape_A, *cinfo.transform_A, p_convex, *cinfo.transform_B, cinfo.result_callback, cinfo.userdata, cinfo.swap_result, nullptr, cinfo.margin_A, cinfo.margin_B);
if (!collided)
if (!collided) {
return;
}
cinfo.collided = true;
cinfo.collisions++;
@ -204,8 +210,9 @@ bool CollisionSolverSW::solve_static(const ShapeSW *p_shape_A, const Transform &
}
if (type_A == PhysicsServer::SHAPE_PLANE) {
if (type_B == PhysicsServer::SHAPE_PLANE)
if (type_B == PhysicsServer::SHAPE_PLANE) {
return false;
}
if (type_B == PhysicsServer::SHAPE_RAY) {
return false;
}
@ -217,8 +224,9 @@ bool CollisionSolverSW::solve_static(const ShapeSW *p_shape_A, const Transform &
}
} else if (type_A == PhysicsServer::SHAPE_RAY) {
if (type_B == PhysicsServer::SHAPE_RAY)
if (type_B == PhysicsServer::SHAPE_RAY) {
return false;
}
if (swap) {
return solve_ray(p_shape_B, p_transform_B, p_shape_A, p_transform_A, p_result_callback, p_userdata, true);
@ -227,13 +235,15 @@ bool CollisionSolverSW::solve_static(const ShapeSW *p_shape_A, const Transform &
}
} else if (concave_B) {
if (concave_A)
if (concave_A) {
return false;
}
if (!swap)
if (!swap) {
return solve_concave(p_shape_A, p_transform_A, p_shape_B, p_transform_B, p_result_callback, p_userdata, false, p_margin_A, p_margin_B);
else
} else {
return solve_concave(p_shape_B, p_transform_B, p_shape_A, p_transform_A, p_result_callback, p_userdata, true, p_margin_A, p_margin_B);
}
} else {
return collision_solver(p_shape_A, p_transform_A, p_shape_B, p_transform_B, p_result_callback, p_userdata, false, r_sep_axis, p_margin_A, p_margin_B);
@ -243,14 +253,16 @@ bool CollisionSolverSW::solve_static(const ShapeSW *p_shape_A, const Transform &
void CollisionSolverSW::concave_distance_callback(void *p_userdata, ShapeSW *p_convex) {
_ConcaveCollisionInfo &cinfo = *(_ConcaveCollisionInfo *)(p_userdata);
cinfo.aabb_tests++;
if (cinfo.collided)
if (cinfo.collided) {
return;
}
Vector3 close_A, close_B;
cinfo.collided = !gjk_epa_calculate_distance(cinfo.shape_A, *cinfo.transform_A, p_convex, *cinfo.transform_B, close_A, close_B);
if (cinfo.collided)
if (cinfo.collided) {
return;
}
if (!cinfo.tested || close_A.distance_squared_to(close_B) < cinfo.close_A.distance_squared_to(cinfo.close_B)) {
cinfo.close_A = close_A;
cinfo.close_B = close_B;
@ -262,8 +274,9 @@ void CollisionSolverSW::concave_distance_callback(void *p_userdata, ShapeSW *p_c
bool CollisionSolverSW::solve_distance_plane(const ShapeSW *p_shape_A, const Transform &p_transform_A, const ShapeSW *p_shape_B, const Transform &p_transform_B, Vector3 &r_point_A, Vector3 &r_point_B) {
const PlaneShapeSW *plane = static_cast<const PlaneShapeSW *>(p_shape_A);
if (p_shape_B->get_type() == PhysicsServer::SHAPE_PLANE)
if (p_shape_B->get_type() == PhysicsServer::SHAPE_PLANE) {
return false;
}
Plane p = p_transform_A.xform(plane->get_plane());
static const int max_supports = 16;
@ -299,8 +312,9 @@ bool CollisionSolverSW::solve_distance_plane(const ShapeSW *p_shape_A, const Tra
if (i == 0 || d < closest_d) {
closest = supports[i];
closest_d = d;
if (d <= 0)
if (d <= 0) {
collided = true;
}
}
}
@ -311,8 +325,9 @@ bool CollisionSolverSW::solve_distance_plane(const ShapeSW *p_shape_A, const Tra
}
bool CollisionSolverSW::solve_distance(const ShapeSW *p_shape_A, const Transform &p_transform_A, const ShapeSW *p_shape_B, const Transform &p_transform_B, Vector3 &r_point_A, Vector3 &r_point_B, const AABB &p_concave_hint, Vector3 *r_sep_axis) {
if (p_shape_A->is_concave())
if (p_shape_A->is_concave()) {
return false;
}
if (p_shape_B->get_type() == PhysicsServer::SHAPE_PLANE) {
Vector3 a, b;
@ -322,8 +337,9 @@ bool CollisionSolverSW::solve_distance(const ShapeSW *p_shape_A, const Transform
return !col;
} else if (p_shape_B->is_concave()) {
if (p_shape_A->is_concave())
if (p_shape_A->is_concave()) {
return false;
}
const ConcaveShapeSW *concave_B = static_cast<const ConcaveShapeSW *>(p_shape_B);

View File

@ -316,7 +316,8 @@ struct GJK
m_free[m_nfree++] = cs.c[i];
}
}
if(mask==15) m_status=eStatus::Inside;
if(mask==15) { m_status=eStatus::Inside;
}
}
else
{/* Return old simplex */
@ -345,10 +346,12 @@ struct GJK
Vector3 axis=Vector3(0,0,0);
axis[i]=1;
appendvertice(*m_simplex, axis);
if(EncloseOrigin()) return(true);
if(EncloseOrigin()) { return(true);
}
removevertice(*m_simplex);
appendvertice(*m_simplex,-axis);
if(EncloseOrigin()) return(true);
if(EncloseOrigin()) { return(true);
}
removevertice(*m_simplex);
}
}
@ -364,10 +367,12 @@ struct GJK
if(p.length_squared()>0)
{
appendvertice(*m_simplex, p);
if(EncloseOrigin()) return(true);
if(EncloseOrigin()) { return(true);
}
removevertice(*m_simplex);
appendvertice(*m_simplex,-p);
if(EncloseOrigin()) return(true);
if(EncloseOrigin()) { return(true);
}
removevertice(*m_simplex);
}
}
@ -380,10 +385,12 @@ struct GJK
if(n.length_squared()>0)
{
appendvertice(*m_simplex,n);
if(EncloseOrigin()) return(true);
if(EncloseOrigin()) { return(true);
}
removevertice(*m_simplex);
appendvertice(*m_simplex,-n);
if(EncloseOrigin()) return(true);
if(EncloseOrigin()) { return(true);
}
removevertice(*m_simplex);
}
}
@ -392,8 +399,9 @@ struct GJK
{
if(Math::abs(det( m_simplex->c[0]->w-m_simplex->c[3]->w,
m_simplex->c[1]->w-m_simplex->c[3]->w,
m_simplex->c[2]->w-m_simplex->c[3]->w))>0)
m_simplex->c[2]->w-m_simplex->c[3]->w))>0) {
return(true);
}
}
break;
}
@ -598,15 +606,19 @@ struct GJK
{
face->l[0] = nullptr;
face->l[1] = list.root;
if(list.root) list.root->l[0]=face;
if(list.root) { list.root->l[0]=face;
}
list.root = face;
++list.count;
}
static inline void remove(sList& list,sFace* face)
{
if(face->l[1]) face->l[1]->l[0]=face->l[0];
if(face->l[0]) face->l[0]->l[1]=face->l[1];
if(face==list.root) list.root=face->l[1];
if(face->l[1]) { face->l[1]->l[0]=face->l[0];
}
if(face->l[0]) { face->l[0]->l[1]=face->l[1];
}
if(face==list.root) { list.root=face->l[1];
}
--list.count;
}
@ -716,10 +728,11 @@ struct GJK
m_status = eStatus::FallBack;
m_normal = -guess;
const real_t nl=m_normal.length();
if(nl>0)
if(nl>0) {
m_normal = m_normal/nl;
else
} else {
m_normal = Vector3(1,0,0);
}
m_depth = 0;
m_result.rank=1;
m_result.c[0]=simplex.c[0];
@ -792,8 +805,10 @@ struct GJK
if(forced||(face->d>=-EPA_PLANE_EPS))
{
return(face);
} else m_status=eStatus::NonConvex;
} else m_status=eStatus::Degenerated;
} else { m_status=eStatus::NonConvex;
}
} else { m_status=eStatus::Degenerated;
}
remove(m_hull,face);
append(m_stock,face);
return(nullptr);
@ -832,7 +847,8 @@ struct GJK
if(nf)
{
bind(nf,0,f,e);
if(horizon.cf) bind(horizon.cf,1,nf,2); else horizon.ff=nf;
if(horizon.cf) { bind(horizon.cf,1,nf,2); } else { horizon.ff=nf;
}
horizon.cf=nf;
++horizon.nf;
return(true);
@ -953,7 +969,8 @@ bool Penetration( const ShapeSW* shape0,
results.normal = -epa.m_normal;
results.distance = -epa.m_depth;
return(true);
} else results.status=sResults::EPA_Failed;
} else { results.status=sResults::EPA_Failed;
}
}
break;
case GJK::eStatus::Failed:
@ -1005,10 +1022,11 @@ bool gjk_epa_calculate_penetration(const ShapeSW *p_shape_A, const Transform &p_
if (GjkEpa2::Penetration(p_shape_A, p_transform_A, p_margin_A, p_shape_B, p_transform_B, p_margin_B, p_transform_B.origin - p_transform_A.origin, res)) {
if (p_result_callback) {
if (p_swap)
if (p_swap) {
p_result_callback(res.witnesses[1], res.witnesses[0], p_userdata);
else
} else {
p_result_callback(res.witnesses[0], res.witnesses[1], p_userdata);
}
}
return true;
}

View File

@ -83,8 +83,9 @@ int G6DOFRotationalLimitMotorSW::testLimitValue(real_t test_value) {
real_t G6DOFRotationalLimitMotorSW::solveAngularLimits(
real_t timeStep, Vector3 &axis, real_t jacDiagABInv,
BodySW *body0, BodySW *body1) {
if (!needApplyTorques())
if (!needApplyTorques()) {
return 0.0f;
}
real_t target_velocity = m_targetVelocity;
real_t maxMotorForce = m_maxMotorForce;
@ -138,8 +139,9 @@ real_t G6DOFRotationalLimitMotorSW::solveAngularLimits(
Vector3 motorImp = clippedMotorImpulse * axis;
body0->apply_torque_impulse(motorImp);
if (body1)
if (body1) {
body1->apply_torque_impulse(-motorImp);
}
return clippedMotorImpulse;
}
@ -179,18 +181,16 @@ real_t G6DOFTranslationalLimitMotorSW::solveLinearAxis(
//handle the limits
if (minLimit < maxLimit) {
{
if (depth > maxLimit) {
depth -= maxLimit;
lo = real_t(0.);
if (depth > maxLimit) {
depth -= maxLimit;
lo = real_t(0.);
} else {
if (depth < minLimit) {
depth -= minLimit;
hi = real_t(0.);
} else {
if (depth < minLimit) {
depth -= minLimit;
hi = real_t(0.);
} else {
return 0.0f;
}
return 0.0f;
}
}
}
@ -329,10 +329,11 @@ bool Generic6DOFJointSW::setup(real_t p_timestep) {
//linear part
for (i = 0; i < 3; i++) {
if (m_linearLimits.enable_limit[i] && m_linearLimits.isLimited(i)) {
if (m_useLinearReferenceFrameA)
if (m_useLinearReferenceFrameA) {
normalWorld = m_calculatedTransformA.basis.get_axis(i);
else
} else {
normalWorld = m_calculatedTransformB.basis.get_axis(i);
}
buildLinearJacobian(
m_jacLinear[i], normalWorld,
@ -371,10 +372,11 @@ void Generic6DOFJointSW::solve(real_t p_timestep) {
if (m_linearLimits.enable_limit[i] && m_linearLimits.isLimited(i)) {
jacDiagABInv = real_t(1.) / m_jacLinear[i].getDiagonal();
if (m_useLinearReferenceFrameA)
if (m_useLinearReferenceFrameA) {
linear_axis = m_calculatedTransformA.basis.get_axis(i);
else
} else {
linear_axis = m_calculatedTransformB.basis.get_axis(i);
}
m_linearLimits.solveLinearAxis(
m_timeStep,

View File

@ -113,10 +113,12 @@ void PinJointSW::solve(real_t p_step) {
real_t impulseClamp = m_impulseClamp;
if (impulseClamp > 0) {
if (impulse < -impulseClamp)
if (impulse < -impulseClamp) {
impulse = -impulseClamp;
if (impulse > impulseClamp)
}
if (impulse > impulseClamp) {
impulse = impulseClamp;
}
}
m_appliedImpulse += impulse;

View File

@ -146,10 +146,11 @@ RID PhysicsServerSW::space_create() {
void PhysicsServerSW::space_set_active(RID p_space, bool p_active) {
SpaceSW *space = space_owner.get(p_space);
ERR_FAIL_COND(!space);
if (p_active)
if (p_active) {
active_spaces.insert(space);
else
} else {
active_spaces.erase(space);
}
}
bool PhysicsServerSW::space_is_active(RID p_space) const {
@ -215,8 +216,9 @@ void PhysicsServerSW::area_set_space(RID p_area, RID p_space) {
ERR_FAIL_COND(!space);
}
if (area->get_space() == space)
if (area->get_space() == space) {
return; //pointless
}
area->clear_constraints();
area->set_space(space);
@ -227,8 +229,9 @@ RID PhysicsServerSW::area_get_space(RID p_area) const {
ERR_FAIL_COND_V(!area, RID());
SpaceSW *space = area->get_space();
if (!space)
if (!space) {
return RID();
}
return space->get_self();
};
@ -307,8 +310,9 @@ void PhysicsServerSW::area_clear_shapes(RID p_area) {
AreaSW *area = area_owner.get(p_area);
ERR_FAIL_COND(!area);
while (area->get_shape_count())
while (area->get_shape_count()) {
area->remove_shape(0);
}
}
void PhysicsServerSW::area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) {
@ -426,10 +430,12 @@ void PhysicsServerSW::area_set_area_monitor_callback(RID p_area, Object *p_recei
RID PhysicsServerSW::body_create(BodyMode p_mode, bool p_init_sleeping) {
BodySW *body = memnew(BodySW);
if (p_mode != BODY_MODE_RIGID)
if (p_mode != BODY_MODE_RIGID) {
body->set_mode(p_mode);
if (p_init_sleeping)
}
if (p_init_sleeping) {
body->set_state(BODY_STATE_SLEEPING, p_init_sleeping);
}
RID rid = body_owner.make_rid(body);
body->set_self(rid);
return rid;
@ -445,8 +451,9 @@ void PhysicsServerSW::body_set_space(RID p_body, RID p_space) {
ERR_FAIL_COND(!space);
}
if (body->get_space() == space)
if (body->get_space() == space) {
return; //pointless
}
body->clear_constraint_map();
body->set_space(space);
@ -457,8 +464,9 @@ RID PhysicsServerSW::body_get_space(RID p_body) const {
ERR_FAIL_COND_V(!body, RID());
SpaceSW *space = body->get_space();
if (!space)
if (!space) {
return RID();
}
return space->get_self();
};
@ -546,8 +554,9 @@ void PhysicsServerSW::body_clear_shapes(RID p_body) {
BodySW *body = body_owner.get(p_body);
ERR_FAIL_COND(!body);
while (body->get_shape_count())
while (body->get_shape_count()) {
body->remove_shape(0);
}
}
void PhysicsServerSW::body_set_enable_continuous_collision_detection(RID p_body, bool p_enable) {
@ -1275,8 +1284,9 @@ void PhysicsServerSW::init() {
void PhysicsServerSW::step(real_t p_step) {
#ifndef _3D_DISABLED
if (!active)
if (!active) {
return;
}
_update_shapes();
@ -1298,8 +1308,9 @@ void PhysicsServerSW::step(real_t p_step) {
void PhysicsServerSW::flush_queries() {
#ifndef _3D_DISABLED
if (!active)
if (!active) {
return;
}
flushing_queries = true;
@ -1377,8 +1388,9 @@ void PhysicsServerSW::_update_shapes() {
void PhysicsServerSW::_shape_col_cbk(const Vector3 &p_point_A, const Vector3 &p_point_B, void *p_userdata) {
CollCbkData *cbk = (CollCbkData *)p_userdata;
if (cbk->max == 0)
if (cbk->max == 0) {
return;
}
if (cbk->amount == cbk->max) {
//find least deep
@ -1393,8 +1405,9 @@ void PhysicsServerSW::_shape_col_cbk(const Vector3 &p_point_A, const Vector3 &p_
}
real_t d = p_point_A.distance_squared_to(p_point_B);
if (d < min_depth)
if (d < min_depth) {
return;
}
cbk->ptr[min_depth_idx * 2 + 0] = p_point_A;
cbk->ptr[min_depth_idx * 2 + 1] = p_point_B;

View File

@ -126,8 +126,9 @@ Vector3 PlaneShapeSW::get_support(const Vector3 &p_normal) const {
bool PlaneShapeSW::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const {
bool inters = plane.intersects_segment(p_begin, p_end, &r_result);
if (inters)
if (inters) {
r_normal = plane.normal;
}
return inters;
}
@ -180,10 +181,11 @@ void RayShapeSW::project_range(const Vector3 &p_normal, const Transform &p_trans
}
Vector3 RayShapeSW::get_support(const Vector3 &p_normal) const {
if (p_normal.z > 0)
if (p_normal.z > 0) {
return Vector3(0, 0, length);
else
} else {
return Vector3(0, 0, 0);
}
}
void RayShapeSW::get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const {
@ -285,8 +287,9 @@ bool SphereShapeSW::intersect_point(const Vector3 &p_point) const {
Vector3 SphereShapeSW::get_closest_point_to(const Vector3 &p_point) const {
Vector3 p = p_point;
float l = p.length();
if (l < radius)
if (l < radius) {
return p_point;
}
return (p / l) * radius;
}
@ -446,11 +449,13 @@ Vector3 BoxShapeSW::get_closest_point_to(const Vector3 &p_point) const {
}
}
if (!outside)
if (!outside) {
return p_point; //it's inside, don't do anything else
}
if (outside == 1) //if only above one plane, this plane clearly wins
if (outside == 1) { //if only above one plane, this plane clearly wins
return min_point;
}
//check segments
float min_distance = 1e20;
@ -627,8 +632,9 @@ Vector3 CapsuleShapeSW::get_closest_point_to(const Vector3 &p_point) const {
Vector3 p = Geometry::get_closest_point_to_segment(p_point, s);
if (p.distance_to(p_point) < radius)
if (p.distance_to(p_point) < radius) {
return p_point;
}
return p + (p_point - p).normalized() * radius;
}
@ -851,18 +857,21 @@ CylinderShapeSW::CylinderShapeSW() {
void ConvexPolygonShapeSW::project_range(const Vector3 &p_normal, const Transform &p_transform, real_t &r_min, real_t &r_max) const {
int vertex_count = mesh.vertices.size();
if (vertex_count == 0)
if (vertex_count == 0) {
return;
}
const Vector3 *vrts = &mesh.vertices[0];
for (int i = 0; i < vertex_count; i++) {
real_t d = p_normal.dot(p_transform.xform(vrts[i]));
if (i == 0 || d > r_max)
if (i == 0 || d > r_max) {
r_max = d;
if (i == 0 || d < r_min)
}
if (i == 0 || d < r_min) {
r_min = d;
}
}
}
@ -873,8 +882,9 @@ Vector3 ConvexPolygonShapeSW::get_support(const Vector3 &p_normal) const {
real_t support_max = 0;
int vertex_count = mesh.vertices.size();
if (vertex_count == 0)
if (vertex_count == 0) {
return Vector3();
}
const Vector3 *vrts = &mesh.vertices[0];
@ -929,8 +939,9 @@ void ConvexPolygonShapeSW::get_supports(const Vector3 &p_normal, int p_max, Vect
}
}
if (!valid)
if (!valid) {
continue;
}
int m = MIN(p_max, ic);
for (int j = 0; j < m; j++) {
@ -970,8 +981,9 @@ bool ConvexPolygonShapeSW::intersect_segment(const Vector3 &p_begin, const Vecto
bool col = false;
for (int i = 0; i < fc; i++) {
if (faces[i].plane.normal.dot(n) > 0)
if (faces[i].plane.normal.dot(n) > 0) {
continue; //opposing face
}
int ic = faces[i].indices.size();
const int *ind = faces[i].indices.ptr();
@ -1001,8 +1013,9 @@ bool ConvexPolygonShapeSW::intersect_point(const Vector3 &p_point) const {
int fc = mesh.faces.size();
for (int i = 0; i < fc; i++) {
if (faces[i].plane.distance_to(p_point) >= 0)
if (faces[i].plane.distance_to(p_point) >= 0) {
return false;
}
}
return true;
@ -1015,8 +1028,9 @@ Vector3 ConvexPolygonShapeSW::get_closest_point_to(const Vector3 &p_point) const
bool all_inside = true;
for (int i = 0; i < fc; i++) {
if (!faces[i].plane.is_point_over(p_point))
if (!faces[i].plane.is_point_over(p_point)) {
continue;
}
all_inside = false;
bool is_inside = true;
@ -1083,10 +1097,11 @@ void ConvexPolygonShapeSW::_setup(const Vector<Vector3> &p_vertices) {
AABB _aabb;
for (int i = 0; i < mesh.vertices.size(); i++) {
if (i == 0)
if (i == 0) {
_aabb.position = mesh.vertices[i];
else
} else {
_aabb.expand_to(mesh.vertices[i]);
}
}
configure(_aabb);
@ -1110,11 +1125,13 @@ void FaceShapeSW::project_range(const Vector3 &p_normal, const Transform &p_tran
Vector3 v = p_transform.xform(vertex[i]);
real_t d = p_normal.dot(v);
if (i == 0 || d > r_max)
if (i == 0 || d > r_max) {
r_max = d;
}
if (i == 0 || d < r_min)
if (i == 0 || d < r_min) {
r_min = d;
}
}
}
@ -1165,8 +1182,9 @@ void FaceShapeSW::get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_su
for (int i = 0; i < 3; i++) {
int nx = (i + 1) % 3;
if (i != vert_support_idx && nx != vert_support_idx)
if (i != vert_support_idx && nx != vert_support_idx) {
continue;
}
// check if edge is valid as a support
real_t dot = (vertex[i] - vertex[nx]).normalized().dot(n);
@ -1241,17 +1259,20 @@ void ConcavePolygonShapeSW::project_range(const Vector3 &p_normal, const Transfo
for (int i = 0; i < count; i++) {
real_t d = p_normal.dot(p_transform.xform(vptr[i]));
if (i == 0 || d > r_max)
if (i == 0 || d > r_max) {
r_max = d;
if (i == 0 || d < r_min)
}
if (i == 0 || d < r_min) {
r_min = d;
}
}
}
Vector3 ConcavePolygonShapeSW::get_support(const Vector3 &p_normal) const {
int count = vertices.size();
if (count == 0)
if (count == 0) {
return Vector3();
}
PoolVector<Vector3>::Read r = vertices.read();
const Vector3 *vptr = r.ptr();
@ -1312,16 +1333,19 @@ void ConcavePolygonShapeSW::_cull_segment(int p_idx, _SegmentCullParams *p_param
}
} else {
if (bvh->left >= 0)
if (bvh->left >= 0) {
_cull_segment(bvh->left, p_params);
if (bvh->right >= 0)
}
if (bvh->right >= 0) {
_cull_segment(bvh->right, p_params);
}
}
}
bool ConcavePolygonShapeSW::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const {
if (faces.size() == 0)
if (faces.size() == 0) {
return false;
}
// unlock data
PoolVector<Face>::Read fr = faces.read();
@ -1362,8 +1386,9 @@ Vector3 ConcavePolygonShapeSW::get_closest_point_to(const Vector3 &p_point) cons
void ConcavePolygonShapeSW::_cull(int p_idx, _CullParams *p_params) const {
const BVH *bvh = &p_params->bvh[p_idx];
if (!p_params->aabb.intersects(bvh->aabb))
if (!p_params->aabb.intersects(bvh->aabb)) {
return;
}
if (bvh->face_index >= 0) {
const Face *f = &p_params->faces[bvh->face_index];
@ -1387,8 +1412,9 @@ void ConcavePolygonShapeSW::_cull(int p_idx, _CullParams *p_params) const {
void ConcavePolygonShapeSW::cull(const AABB &p_local_aabb, Callback p_callback, void *p_userdata) const {
// make matrix local to concave
if (faces.size() == 0)
if (faces.size() == 0) {
return;
}
AABB local_aabb = p_local_aabb;
@ -1471,10 +1497,11 @@ _VolumeSW_BVH *_volume_sw_build_bvh(_VolumeSW_BVH_Element *p_elements, int p_siz
AABB aabb;
for (int i = 0; i < p_size; i++) {
if (i == 0)
if (i == 0) {
aabb = p_elements[i].aabb;
else
} else {
aabb.merge_with(p_elements[i].aabb);
}
}
bvh->aabb = aabb;
switch (aabb.get_longest_axis_index()) {
@ -1570,10 +1597,11 @@ void ConcavePolygonShapeSW::_setup(PoolVector<Vector3> p_faces) {
verticesw[i * 3 + 0] = face.vertex[0];
verticesw[i * 3 + 1] = face.vertex[1];
verticesw[i * 3 + 2] = face.vertex[2];
if (i == 0)
if (i == 0) {
_aabb = bvh_arrayw[i].aabb;
else
} else {
_aabb.merge_with(bvh_arrayw[i].aabb);
}
}
w.release();

View File

@ -39,11 +39,13 @@ _FORCE_INLINE_ static bool _can_collide_with(CollisionObjectSW *p_object, uint32
return false;
}
if (p_object->get_type() == CollisionObjectSW::TYPE_AREA && !p_collide_with_areas)
if (p_object->get_type() == CollisionObjectSW::TYPE_AREA && !p_collide_with_areas) {
return false;
}
if (p_object->get_type() == CollisionObjectSW::TYPE_BODY && !p_collide_with_bodies)
if (p_object->get_type() == CollisionObjectSW::TYPE_BODY && !p_collide_with_bodies) {
return false;
}
return true;
}
@ -56,16 +58,19 @@ int PhysicsDirectSpaceStateSW::intersect_point(const Vector3 &p_point, ShapeResu
//Transform ai = p_xform.affine_inverse();
for (int i = 0; i < amount; i++) {
if (cc >= p_result_max)
if (cc >= p_result_max) {
break;
}
if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
}
//area can't be picked by ray (default)
if (p_exclude.has(space->intersection_query_results[i]->get_self()))
if (p_exclude.has(space->intersection_query_results[i]->get_self())) {
continue;
}
const CollisionObjectSW *col_obj = space->intersection_query_results[i];
int shape_idx = space->intersection_query_subindex_results[i];
@ -73,14 +78,16 @@ int PhysicsDirectSpaceStateSW::intersect_point(const Vector3 &p_point, ShapeResu
Transform inv_xform = col_obj->get_transform() * col_obj->get_shape_transform(shape_idx);
inv_xform.affine_invert();
if (!col_obj->get_shape(shape_idx)->intersect_point(inv_xform.xform(p_point)))
if (!col_obj->get_shape(shape_idx)->intersect_point(inv_xform.xform(p_point))) {
continue;
}
r_results[cc].collider_id = col_obj->get_instance_id();
if (r_results[cc].collider_id != 0)
if (r_results[cc].collider_id != 0) {
r_results[cc].collider = ObjectDB::get_instance(r_results[cc].collider_id);
else
} else {
r_results[cc].collider = nullptr;
}
r_results[cc].rid = col_obj->get_self();
r_results[cc].shape = shape_idx;
@ -110,14 +117,17 @@ bool PhysicsDirectSpaceStateSW::intersect_ray(const Vector3 &p_from, const Vecto
real_t min_d = 1e10;
for (int i = 0; i < amount; i++) {
if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
}
if (p_pick_ray && !(space->intersection_query_results[i]->is_ray_pickable()))
if (p_pick_ray && !(space->intersection_query_results[i]->is_ray_pickable())) {
continue;
}
if (p_exclude.has(space->intersection_query_results[i]->get_self()))
if (p_exclude.has(space->intersection_query_results[i]->get_self())) {
continue;
}
const CollisionObjectSW *col_obj = space->intersection_query_results[i];
@ -148,14 +158,16 @@ bool PhysicsDirectSpaceStateSW::intersect_ray(const Vector3 &p_from, const Vecto
}
}
if (!collided)
if (!collided) {
return false;
}
r_result.collider_id = res_obj->get_instance_id();
if (r_result.collider_id != 0)
if (r_result.collider_id != 0) {
r_result.collider = ObjectDB::get_instance(r_result.collider_id);
else
} else {
r_result.collider = nullptr;
}
r_result.normal = res_normal;
r_result.position = res_point;
r_result.rid = res_obj->get_self();
@ -165,8 +177,9 @@ bool PhysicsDirectSpaceStateSW::intersect_ray(const Vector3 &p_from, const Vecto
}
int PhysicsDirectSpaceStateSW::intersect_shape(const RID &p_shape, const Transform &p_xform, real_t p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) {
if (p_result_max <= 0)
if (p_result_max <= 0) {
return 0;
}
ShapeSW *shape = static_cast<PhysicsServerSW *>(PhysicsServer::get_singleton())->shape_owner.get(p_shape);
ERR_FAIL_COND_V(!shape, 0);
@ -180,29 +193,34 @@ int PhysicsDirectSpaceStateSW::intersect_shape(const RID &p_shape, const Transfo
//Transform ai = p_xform.affine_inverse();
for (int i = 0; i < amount; i++) {
if (cc >= p_result_max)
if (cc >= p_result_max) {
break;
}
if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
}
//area can't be picked by ray (default)
if (p_exclude.has(space->intersection_query_results[i]->get_self()))
if (p_exclude.has(space->intersection_query_results[i]->get_self())) {
continue;
}
const CollisionObjectSW *col_obj = space->intersection_query_results[i];
int shape_idx = space->intersection_query_subindex_results[i];
if (!CollisionSolverSW::solve_static(shape, p_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), nullptr, nullptr, nullptr, p_margin, 0))
if (!CollisionSolverSW::solve_static(shape, p_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), nullptr, nullptr, nullptr, p_margin, 0)) {
continue;
}
if (r_results) {
r_results[cc].collider_id = col_obj->get_instance_id();
if (r_results[cc].collider_id != 0)
if (r_results[cc].collider_id != 0) {
r_results[cc].collider = ObjectDB::get_instance(r_results[cc].collider_id);
else
} else {
r_results[cc].collider = nullptr;
}
r_results[cc].rid = col_obj->get_self();
r_results[cc].shape = shape_idx;
}
@ -236,11 +254,13 @@ bool PhysicsDirectSpaceStateSW::cast_motion(const RID &p_shape, const Transform
Vector3 closest_A, closest_B;
for (int i = 0; i < amount; i++) {
if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
}
if (p_exclude.has(space->intersection_query_results[i]->get_self()))
if (p_exclude.has(space->intersection_query_results[i]->get_self())) {
continue; //ignore excluded
}
const CollisionObjectSW *col_obj = space->intersection_query_results[i];
int shape_idx = space->intersection_query_subindex_results[i];
@ -317,8 +337,9 @@ bool PhysicsDirectSpaceStateSW::cast_motion(const RID &p_shape, const Transform
}
bool PhysicsDirectSpaceStateSW::collide_shape(RID p_shape, const Transform &p_shape_xform, real_t p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) {
if (p_result_max <= 0)
if (p_result_max <= 0) {
return false;
}
ShapeSW *shape = static_cast<PhysicsServerSW *>(PhysicsServer::get_singleton())->shape_owner.get(p_shape);
ERR_FAIL_COND_V(!shape, 0);
@ -340,8 +361,9 @@ bool PhysicsDirectSpaceStateSW::collide_shape(RID p_shape, const Transform &p_sh
PhysicsServerSW::CollCbkData *cbkptr = &cbk;
for (int i = 0; i < amount; i++) {
if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
}
const CollisionObjectSW *col_obj = space->intersection_query_results[i];
int shape_idx = space->intersection_query_subindex_results[i];
@ -378,10 +400,12 @@ static void _rest_cbk_result(const Vector3 &p_point_A, const Vector3 &p_point_B,
Vector3 contact_rel = p_point_B - p_point_A;
real_t len = contact_rel.length();
if (len < rd->min_allowed_depth)
if (len < rd->min_allowed_depth) {
return;
if (len <= rd->best_len)
}
if (len <= rd->best_len) {
return;
}
rd->best_len = len;
rd->best_contact = p_point_B;
@ -406,24 +430,28 @@ bool PhysicsDirectSpaceStateSW::rest_info(RID p_shape, const Transform &p_shape_
rcd.min_allowed_depth = space->test_motion_min_contact_depth;
for (int i = 0; i < amount; i++) {
if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
}
const CollisionObjectSW *col_obj = space->intersection_query_results[i];
int shape_idx = space->intersection_query_subindex_results[i];
if (p_exclude.has(col_obj->get_self()))
if (p_exclude.has(col_obj->get_self())) {
continue;
}
rcd.object = col_obj;
rcd.shape = shape_idx;
bool sc = CollisionSolverSW::solve_static(shape, p_shape_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), _rest_cbk_result, &rcd, nullptr, p_margin);
if (!sc)
if (!sc) {
continue;
}
}
if (rcd.best_len == 0 || !rcd.best_object)
if (rcd.best_len == 0 || !rcd.best_object) {
return false;
}
r_info->collider_id = rcd.best_object->get_instance_id();
r_info->shape = rcd.best_shape;
@ -457,8 +485,9 @@ Vector3 PhysicsDirectSpaceStateSW::get_closest_point_to_object_volume(RID p_obje
bool shapes_found = false;
for (int i = 0; i < obj->get_shape_count(); i++) {
if (obj->is_shape_set_as_disabled(i))
if (obj->is_shape_set_as_disabled(i)) {
continue;
}
Transform shape_xform = obj->get_transform() * obj->get_shape_transform(i);
ShapeSW *shape = obj->get_shape(i);
@ -493,16 +522,17 @@ int SpaceSW::_cull_aabb_for_body(BodySW *p_body, const AABB &p_aabb) {
for (int i = 0; i < amount; i++) {
bool keep = true;
if (intersection_query_results[i] == p_body)
if (intersection_query_results[i] == p_body) {
keep = false;
else if (intersection_query_results[i]->get_type() == CollisionObjectSW::TYPE_AREA)
} else if (intersection_query_results[i]->get_type() == CollisionObjectSW::TYPE_AREA) {
keep = false;
else if ((static_cast<BodySW *>(intersection_query_results[i])->test_collision_mask(p_body)) == 0)
} else if ((static_cast<BodySW *>(intersection_query_results[i])->test_collision_mask(p_body)) == 0) {
keep = false;
else if (static_cast<BodySW *>(intersection_query_results[i])->has_exception(p_body->get_self()) || p_body->has_exception(intersection_query_results[i]->get_self()))
} else if (static_cast<BodySW *>(intersection_query_results[i])->has_exception(p_body->get_self()) || p_body->has_exception(intersection_query_results[i]->get_self())) {
keep = false;
else if (static_cast<BodySW *>(intersection_query_results[i])->is_shape_set_as_disabled(intersection_query_subindex_results[i]))
} else if (static_cast<BodySW *>(intersection_query_results[i])->is_shape_set_as_disabled(intersection_query_subindex_results[i])) {
keep = false;
}
if (!keep) {
if (i < amount - 1) {
@ -524,8 +554,9 @@ int SpaceSW::test_body_ray_separation(BodySW *p_body, const Transform &p_transfo
bool shapes_found = false;
for (int i = 0; i < p_body->get_shape_count(); i++) {
if (p_body->is_shape_set_as_disabled(i))
if (p_body->is_shape_set_as_disabled(i)) {
continue;
}
if (!shapes_found) {
body_aabb = p_body->get_shape_aabb(i);
@ -570,13 +601,15 @@ int SpaceSW::test_body_ray_separation(BodySW *p_body, const Transform &p_transfo
int amount = _cull_aabb_for_body(p_body, body_aabb);
for (int j = 0; j < p_body->get_shape_count(); j++) {
if (p_body->is_shape_set_as_disabled(j))
if (p_body->is_shape_set_as_disabled(j)) {
continue;
}
ShapeSW *body_shape = p_body->get_shape(j);
if (body_shape->get_type() != PhysicsServer::SHAPE_RAY)
if (body_shape->get_type() != PhysicsServer::SHAPE_RAY) {
continue;
}
Transform body_shape_xform = body_transform * p_body->get_shape_transform(j);
@ -683,8 +716,9 @@ bool SpaceSW::test_body_motion(BodySW *p_body, const Transform &p_from, const Ve
bool shapes_found = false;
for (int i = 0; i < p_body->get_shape_count(); i++) {
if (p_body->is_shape_set_as_disabled(i))
if (p_body->is_shape_set_as_disabled(i)) {
continue;
}
if (!shapes_found) {
body_aabb = p_body->get_shape_aabb(i);
@ -735,8 +769,9 @@ bool SpaceSW::test_body_motion(BodySW *p_body, const Transform &p_from, const Ve
int amount = _cull_aabb_for_body(p_body, body_aabb);
for (int j = 0; j < p_body->get_shape_count(); j++) {
if (p_body->is_shape_set_as_disabled(j))
if (p_body->is_shape_set_as_disabled(j)) {
continue;
}
Transform body_shape_xform = body_transform * p_body->get_shape_transform(j);
ShapeSW *body_shape = p_body->get_shape(j);
@ -805,8 +840,9 @@ bool SpaceSW::test_body_motion(BodySW *p_body, const Transform &p_from, const Ve
int amount = _cull_aabb_for_body(p_body, motion_aabb);
for (int j = 0; j < p_body->get_shape_count(); j++) {
if (p_body->is_shape_set_as_disabled(j))
if (p_body->is_shape_set_as_disabled(j)) {
continue;
}
Transform body_shape_xform = body_transform * p_body->get_shape_transform(j);
ShapeSW *body_shape = p_body->get_shape(j);
@ -916,8 +952,9 @@ bool SpaceSW::test_body_motion(BodySW *p_body, const Transform &p_from, const Ve
int to_shape = best_shape != -1 ? best_shape + 1 : p_body->get_shape_count();
for (int j = from_shape; j < to_shape; j++) {
if (p_body->is_shape_set_as_disabled(j))
if (p_body->is_shape_set_as_disabled(j)) {
continue;
}
Transform body_shape_xform = ugt * p_body->get_shape_transform(j);
ShapeSW *body_shape = p_body->get_shape(j);
@ -938,8 +975,9 @@ bool SpaceSW::test_body_motion(BodySW *p_body, const Transform &p_from, const Ve
rcd.shape = shape_idx;
rcd.local_shape = j;
bool sc = CollisionSolverSW::solve_static(body_shape, body_shape_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), _rest_cbk_result, &rcd, nullptr, p_margin);
if (!sc)
if (!sc) {
continue;
}
}
}
@ -1210,8 +1248,9 @@ SpaceSW::SpaceSW() {
direct_access = memnew(PhysicsDirectSpaceStateSW);
direct_access->space = this;
for (int i = 0; i < ELAPSED_TIME_MAX; i++)
for (int i = 0; i < ELAPSED_TIME_MAX; i++) {
elapsed_time[i] = 0;
}
}
SpaceSW::~SpaceSW() {

View File

@ -185,8 +185,9 @@ public:
void set_debug_contacts(int p_amount) { contact_debug.resize(p_amount); }
_FORCE_INLINE_ bool is_debugging_contacts() const { return !contact_debug.empty(); }
_FORCE_INLINE_ void add_debug_contact(const Vector3 &p_contact) {
if (contact_debug_count < contact_debug.size())
if (contact_debug_count < contact_debug.size()) {
contact_debug.write[contact_debug_count++] = p_contact;
}
}
_FORCE_INLINE_ Vector<Vector3> get_debug_contacts() { return contact_debug; }
_FORCE_INLINE_ int get_debug_contact_count() { return contact_debug_count; }

View File

@ -40,18 +40,21 @@ void StepSW::_populate_island(BodySW *p_body, BodySW **p_island, ConstraintSW **
for (Map<ConstraintSW *, int>::Element *E = p_body->get_constraint_map().front(); E; E = E->next()) {
ConstraintSW *c = (ConstraintSW *)E->key();
if (c->get_island_step() == _step)
if (c->get_island_step() == _step) {
continue; //already processed
}
c->set_island_step(_step);
c->set_island_next(*p_constraint_island);
*p_constraint_island = c;
for (int i = 0; i < c->get_body_count(); i++) {
if (i == E->get())
if (i == E->get()) {
continue;
}
BodySW *b = c->get_body_ptr()[i];
if (b->get_island_step() == _step || b->get_mode() == PhysicsServer::BODY_MODE_STATIC || b->get_mode() == PhysicsServer::BODY_MODE_KINEMATIC)
if (b->get_island_step() == _step || b->get_mode() == PhysicsServer::BODY_MODE_STATIC || b->get_mode() == PhysicsServer::BODY_MODE_KINEMATIC) {
continue; //no go
}
_populate_island(c->get_body_ptr()[i], p_island, p_constraint_island);
}
}
@ -110,8 +113,9 @@ void StepSW::_check_suspend(BodySW *p_island, real_t p_delta) {
continue; //ignore for static
}
if (!b->sleep_test(p_delta))
if (!b->sleep_test(p_delta)) {
can_sleep = false;
}
b = b->get_island_next();
}
@ -127,8 +131,9 @@ void StepSW::_check_suspend(BodySW *p_island, real_t p_delta) {
bool active = b->is_active();
if (active == can_sleep)
if (active == can_sleep) {
b->set_active(!can_sleep);
}
b = b->get_island_next();
}
@ -198,8 +203,9 @@ void StepSW::step(SpaceSW *p_space, real_t p_delta, int p_iterations) {
while (aml.first()) {
for (const Set<ConstraintSW *>::Element *E = aml.first()->self()->get_constraints().front(); E; E = E->next()) {
ConstraintSW *c = E->get();
if (c->get_island_step() == _step)
if (c->get_island_step() == _step) {
continue;
}
c->set_island_step(_step);
c->set_island_next(nullptr);
c->set_island_list_next(constraint_island_list);