summaryrefslogtreecommitdiff
path: root/servers/physics_2d/body_2d_sw.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'servers/physics_2d/body_2d_sw.cpp')
-rw-r--r--servers/physics_2d/body_2d_sw.cpp58
1 files changed, 0 insertions, 58 deletions
diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp
index 39e28fd002..12c7a49288 100644
--- a/servers/physics_2d/body_2d_sw.cpp
+++ b/servers/physics_2d/body_2d_sw.cpp
@@ -34,19 +34,15 @@
#include "space_2d_sw.h"
void Body2DSW::_update_inertia() {
-
if (!user_inertia && get_space() && !inertia_update_list.in_list())
get_space()->body_add_to_inertia_update_list(&inertia_update_list);
}
void Body2DSW::update_inertias() {
-
//update shapes and motions
switch (mode) {
-
case PhysicsServer2D::BODY_MODE_RIGID: {
-
if (user_inertia) {
_inv_inertia = inertia > 0 ? (1.0 / inertia) : 0;
break;
@@ -55,14 +51,12 @@ void Body2DSW::update_inertias() {
real_t total_area = 0;
for (int i = 0; i < get_shape_count(); i++) {
-
total_area += get_shape_aabb(i).get_area();
}
inertia = 0;
for (int i = 0; i < get_shape_count(); i++) {
-
if (is_shape_disabled(i)) {
continue;
}
@@ -88,12 +82,10 @@ void Body2DSW::update_inertias() {
} break;
case PhysicsServer2D::BODY_MODE_KINEMATIC:
case PhysicsServer2D::BODY_MODE_STATIC: {
-
_inv_inertia = 0;
_inv_mass = 0;
} break;
case PhysicsServer2D::BODY_MODE_CHARACTER: {
-
_inv_inertia = 0;
_inv_mass = 1.0 / mass;
@@ -105,7 +97,6 @@ void Body2DSW::update_inertias() {
}
void Body2DSW::set_active(bool p_active) {
-
if (active == p_active)
return;
@@ -135,14 +126,11 @@ void Body2DSW::set_active(bool p_active) {
}
void Body2DSW::set_param(PhysicsServer2D::BodyParameter p_param, real_t p_value) {
-
switch (p_param) {
case PhysicsServer2D::BODY_PARAM_BOUNCE: {
-
bounce = p_value;
} break;
case PhysicsServer2D::BODY_PARAM_FRICTION: {
-
friction = p_value;
} break;
case PhysicsServer2D::BODY_PARAM_MASS: {
@@ -165,11 +153,9 @@ void Body2DSW::set_param(PhysicsServer2D::BodyParameter p_param, real_t p_value)
gravity_scale = p_value;
} break;
case PhysicsServer2D::BODY_PARAM_LINEAR_DAMP: {
-
linear_damp = p_value;
} break;
case PhysicsServer2D::BODY_PARAM_ANGULAR_DAMP: {
-
angular_damp = p_value;
} break;
default: {
@@ -178,14 +164,11 @@ void Body2DSW::set_param(PhysicsServer2D::BodyParameter p_param, real_t p_value)
}
real_t Body2DSW::get_param(PhysicsServer2D::BodyParameter p_param) const {
-
switch (p_param) {
case PhysicsServer2D::BODY_PARAM_BOUNCE: {
-
return bounce;
}
case PhysicsServer2D::BODY_PARAM_FRICTION: {
-
return friction;
}
case PhysicsServer2D::BODY_PARAM_MASS: {
@@ -198,11 +181,9 @@ real_t Body2DSW::get_param(PhysicsServer2D::BodyParameter p_param) const {
return gravity_scale;
}
case PhysicsServer2D::BODY_PARAM_LINEAR_DAMP: {
-
return linear_damp;
}
case PhysicsServer2D::BODY_PARAM_ANGULAR_DAMP: {
-
return angular_damp;
}
default: {
@@ -213,7 +194,6 @@ real_t Body2DSW::get_param(PhysicsServer2D::BodyParameter p_param) const {
}
void Body2DSW::set_mode(PhysicsServer2D::BodyMode p_mode) {
-
PhysicsServer2D::BodyMode prev = mode;
mode = p_mode;
@@ -221,7 +201,6 @@ void Body2DSW::set_mode(PhysicsServer2D::BodyMode p_mode) {
//CLEAR UP EVERYTHING IN CASE IT NOT WORKS!
case PhysicsServer2D::BODY_MODE_STATIC:
case PhysicsServer2D::BODY_MODE_KINEMATIC: {
-
_set_inv_transform(get_transform().affine_inverse());
_inv_mass = 0;
_inv_inertia = 0;
@@ -234,7 +213,6 @@ void Body2DSW::set_mode(PhysicsServer2D::BodyMode p_mode) {
}
} break;
case PhysicsServer2D::BODY_MODE_RIGID: {
-
_inv_mass = mass > 0 ? (1.0 / mass) : 0;
_inv_inertia = inertia > 0 ? (1.0 / inertia) : 0;
_set_static(false);
@@ -242,7 +220,6 @@ void Body2DSW::set_mode(PhysicsServer2D::BodyMode p_mode) {
} break;
case PhysicsServer2D::BODY_MODE_CHARACTER: {
-
_inv_mass = mass > 0 ? (1.0 / mass) : 0;
_inv_inertia = 0;
_set_static(false);
@@ -259,23 +236,18 @@ void Body2DSW::set_mode(PhysicsServer2D::BodyMode p_mode) {
*/
}
PhysicsServer2D::BodyMode Body2DSW::get_mode() const {
-
return mode;
}
void Body2DSW::_shapes_changed() {
-
_update_inertia();
wakeup_neighbours();
}
void Body2DSW::set_state(PhysicsServer2D::BodyState p_state, const Variant &p_variant) {
-
switch (p_state) {
case PhysicsServer2D::BODY_STATE_TRANSFORM: {
-
if (mode == PhysicsServer2D::BODY_MODE_KINEMATIC) {
-
new_transform = p_variant;
//wakeup_neighbours();
set_active(true);
@@ -301,7 +273,6 @@ void Body2DSW::set_state(PhysicsServer2D::BodyState p_state, const Variant &p_va
} break;
case PhysicsServer2D::BODY_STATE_LINEAR_VELOCITY: {
-
/*
if (mode==PhysicsServer2D::BODY_MODE_STATIC)
break;
@@ -344,7 +315,6 @@ void Body2DSW::set_state(PhysicsServer2D::BodyState p_state, const Variant &p_va
}
}
Variant Body2DSW::get_state(PhysicsServer2D::BodyState p_state) const {
-
switch (p_state) {
case PhysicsServer2D::BODY_STATE_TRANSFORM: {
return get_transform();
@@ -367,9 +337,7 @@ Variant Body2DSW::get_state(PhysicsServer2D::BodyState p_state) const {
}
void Body2DSW::set_space(Space2DSW *p_space) {
-
if (get_space()) {
-
wakeup_neighbours();
if (inertia_update_list.in_list())
@@ -383,7 +351,6 @@ void Body2DSW::set_space(Space2DSW *p_space) {
_set_space(p_space);
if (get_space()) {
-
_update_inertia();
if (active)
get_space()->body_add_to_active_list(&active_list);
@@ -400,7 +367,6 @@ void Body2DSW::set_space(Space2DSW *p_space) {
}
void Body2DSW::_compute_area_gravity_and_dampenings(const Area2DSW *p_area) {
-
if (p_area->is_gravity_point()) {
if (p_area->get_gravity_distance_scale() > 0) {
Vector2 v = p_area->get_transform().xform(p_area->get_gravity_vector()) - get_transform().get_origin();
@@ -417,7 +383,6 @@ void Body2DSW::_compute_area_gravity_and_dampenings(const Area2DSW *p_area) {
}
void Body2DSW::integrate_forces(real_t p_step) {
-
if (mode == PhysicsServer2D::BODY_MODE_STATIC)
return;
@@ -479,7 +444,6 @@ void Body2DSW::integrate_forces(real_t p_step) {
bool do_motion = false;
if (mode == PhysicsServer2D::BODY_MODE_KINEMATIC) {
-
//compute motion, angular and etc. velocities from prev transform
motion = new_transform.get_origin() - get_transform().get_origin();
linear_velocity = motion / p_step;
@@ -522,7 +486,6 @@ void Body2DSW::integrate_forces(real_t p_step) {
}
if (continuous_cd_mode != PhysicsServer2D::CCD_MODE_DISABLED) {
-
motion = linear_velocity * p_step;
do_motion = true;
}
@@ -544,7 +507,6 @@ void Body2DSW::integrate_forces(real_t p_step) {
}
void Body2DSW::integrate_velocities(real_t p_step) {
-
if (mode == PhysicsServer2D::BODY_MODE_STATIC)
return;
@@ -552,7 +514,6 @@ void Body2DSW::integrate_velocities(real_t p_step) {
get_space()->body_add_to_state_query_list(&direct_state_query_list);
if (mode == PhysicsServer2D::BODY_MODE_KINEMATIC) {
-
_set_transform(new_transform, false);
_set_inv_transform(new_transform.affine_inverse());
if (contacts.size() == 0 && linear_velocity == Vector2() && angular_velocity == 0)
@@ -576,15 +537,12 @@ void Body2DSW::integrate_velocities(real_t p_step) {
}
void Body2DSW::wakeup_neighbours() {
-
for (Map<Constraint2DSW *, int>::Element *E = constraint_map.front(); E; E = E->next()) {
-
const Constraint2DSW *c = E->key();
Body2DSW **n = c->get_body_ptr();
int bc = c->get_body_count();
for (int i = 0; i < bc; i++) {
-
if (i == E->get())
continue;
Body2DSW *b = n[i];
@@ -598,9 +556,7 @@ void Body2DSW::wakeup_neighbours() {
}
void Body2DSW::call_queries() {
-
if (fi_callback) {
-
PhysicsDirectBodyState2DSW *dbs = PhysicsDirectBodyState2DSW::singleton;
dbs->body = this;
@@ -609,12 +565,10 @@ void Body2DSW::call_queries() {
Object *obj = ObjectDB::get_instance(fi_callback->id);
if (!obj) {
-
set_force_integration_callback(ObjectID(), StringName());
} else {
Callable::CallError ce;
if (fi_callback->callback_udata.get_type() != Variant::NIL) {
-
obj->call(fi_callback->method, vp, 2, ce);
} else {
@@ -625,7 +579,6 @@ void Body2DSW::call_queries() {
}
bool Body2DSW::sleep_test(real_t p_step) {
-
if (mode == PhysicsServer2D::BODY_MODE_STATIC || mode == PhysicsServer2D::BODY_MODE_KINEMATIC)
return true; //
else if (mode == PhysicsServer2D::BODY_MODE_CHARACTER)
@@ -634,27 +587,22 @@ bool Body2DSW::sleep_test(real_t p_step) {
return false;
if (Math::abs(angular_velocity) < 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;
return still_time > get_space()->get_body_time_to_sleep();
} else {
-
still_time = 0; //maybe this should be set to 0 on set_active?
return false;
}
}
void Body2DSW::set_force_integration_callback(ObjectID p_id, const StringName &p_method, const Variant &p_udata) {
-
if (fi_callback) {
-
memdelete(fi_callback);
fi_callback = nullptr;
}
if (p_id.is_valid()) {
-
fi_callback = memnew(ForceIntegrationCallback);
fi_callback->id = p_id;
fi_callback->method = p_method;
@@ -667,7 +615,6 @@ Body2DSW::Body2DSW() :
active_list(this),
inertia_update_list(this),
direct_state_query_list(this) {
-
mode = PhysicsServer2D::BODY_MODE_RIGID;
active = true;
angular_velocity = 0;
@@ -701,7 +648,6 @@ Body2DSW::Body2DSW() :
}
Body2DSW::~Body2DSW() {
-
if (fi_callback)
memdelete(fi_callback);
}
@@ -709,23 +655,19 @@ Body2DSW::~Body2DSW() {
PhysicsDirectBodyState2DSW *PhysicsDirectBodyState2DSW::singleton = nullptr;
PhysicsDirectSpaceState2D *PhysicsDirectBodyState2DSW::get_space_state() {
-
return body->get_space()->get_direct_state();
}
Variant PhysicsDirectBodyState2DSW::get_contact_collider_shape_metadata(int p_contact_idx) const {
-
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Variant());
if (!PhysicsServer2DSW::singletonsw->body_owner.owns(body->contacts[p_contact_idx].collider)) {
-
return Variant();
}
Body2DSW *other = PhysicsServer2DSW::singletonsw->body_owner.getornull(body->contacts[p_contact_idx].collider);
int sidx = body->contacts[p_contact_idx].collider_shape;
if (sidx < 0 || sidx >= other->get_shape_count()) {
-
return Variant();
}