summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/bullet/bullet_physics_server.cpp14
-rw-r--r--modules/bullet/bullet_physics_server.h3
-rw-r--r--modules/bullet/rigid_body_bullet.cpp18
-rw-r--r--modules/bullet/rigid_body_bullet.h9
-rw-r--r--modules/bullet/space_bullet.cpp34
-rw-r--r--scene/2d/physics_body_2d.cpp30
-rw-r--r--scene/3d/physics_body.cpp31
-rw-r--r--scene/resources/physics_material.cpp76
-rw-r--r--scene/resources/physics_material.h32
-rw-r--r--servers/physics/body_pair_sw.cpp34
-rw-r--r--servers/physics/body_sw.cpp16
-rw-r--r--servers/physics/body_sw.h8
-rw-r--r--servers/physics/physics_server_sw.cpp14
-rw-r--r--servers/physics/physics_server_sw.h4
-rw-r--r--servers/physics_2d/body_2d_sw.cpp16
-rw-r--r--servers/physics_2d/body_2d_sw.h8
-rw-r--r--servers/physics_2d/body_pair_2d_sw.cpp34
-rw-r--r--servers/physics_2d/physics_2d_server_sw.cpp16
-rw-r--r--servers/physics_2d/physics_2d_server_sw.h4
-rw-r--r--servers/physics_2d/physics_2d_server_wrap_mt.h3
-rw-r--r--servers/physics_2d_server.h13
-rw-r--r--servers/physics_server.h13
22 files changed, 78 insertions, 352 deletions
diff --git a/modules/bullet/bullet_physics_server.cpp b/modules/bullet/bullet_physics_server.cpp
index 9263a9ba6d..0857635492 100644
--- a/modules/bullet/bullet_physics_server.cpp
+++ b/modules/bullet/bullet_physics_server.cpp
@@ -644,20 +644,6 @@ float BulletPhysicsServer::body_get_param(RID p_body, BodyParameter p_param) con
return body->get_param(p_param);
}
-void BulletPhysicsServer::body_set_combine_mode(RID p_body, BodyParameter p_param, CombineMode p_mode) {
- RigidBodyBullet *body = rigid_body_owner.get(p_body);
- ERR_FAIL_COND(!body);
-
- body->set_combine_mode(p_param, p_mode);
-}
-
-PhysicsServer::CombineMode BulletPhysicsServer::body_get_combine_mode(RID p_body, BodyParameter p_param) const {
- RigidBodyBullet *body = rigid_body_owner.get(p_body);
- ERR_FAIL_COND_V(!body, COMBINE_MODE_INHERIT);
-
- return body->get_combine_mode(p_param);
-}
-
void BulletPhysicsServer::body_set_kinematic_safe_margin(RID p_body, real_t p_margin) {
RigidBodyBullet *body = rigid_body_owner.get(p_body);
ERR_FAIL_COND(!body);
diff --git a/modules/bullet/bullet_physics_server.h b/modules/bullet/bullet_physics_server.h
index 2c5b7e51cf..0e858ff311 100644
--- a/modules/bullet/bullet_physics_server.h
+++ b/modules/bullet/bullet_physics_server.h
@@ -213,9 +213,6 @@ public:
virtual void body_set_param(RID p_body, BodyParameter p_param, float p_value);
virtual float body_get_param(RID p_body, BodyParameter p_param) const;
- virtual void body_set_combine_mode(RID p_body, BodyParameter p_param, CombineMode p_mode);
- virtual CombineMode body_get_combine_mode(RID p_body, BodyParameter p_param) const;
-
virtual void body_set_kinematic_safe_margin(RID p_body, real_t p_margin);
virtual real_t body_get_kinematic_safe_margin(RID p_body) const;
diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp
index 81a62edba6..9c0e802be5 100644
--- a/modules/bullet/rigid_body_bullet.cpp
+++ b/modules/bullet/rigid_body_bullet.cpp
@@ -265,8 +265,6 @@ RigidBodyBullet::RigidBodyBullet() :
angularDamp(0),
can_sleep(true),
omit_forces_integration(false),
- restitution_combine_mode(PhysicsServer::COMBINE_MODE_INHERIT),
- friction_combine_mode(PhysicsServer::COMBINE_MODE_INHERIT),
force_integration_callback(NULL),
isTransformChanged(false),
previousActiveState(true),
@@ -761,22 +759,6 @@ Vector3 RigidBodyBullet::get_angular_velocity() const {
return gVec;
}
-void RigidBodyBullet::set_combine_mode(const PhysicsServer::BodyParameter p_param, const PhysicsServer::CombineMode p_mode) {
- if (p_param == PhysicsServer::BODY_PARAM_BOUNCE) {
- restitution_combine_mode = p_mode;
- } else {
- friction_combine_mode = p_mode;
- }
-}
-
-PhysicsServer::CombineMode RigidBodyBullet::get_combine_mode(PhysicsServer::BodyParameter p_param) const {
- if (p_param == PhysicsServer::BODY_PARAM_BOUNCE) {
- return restitution_combine_mode;
- } else {
- return friction_combine_mode;
- }
-}
-
void RigidBodyBullet::set_transform__bullet(const btTransform &p_global_transform) {
if (mode == PhysicsServer::BODY_MODE_KINEMATIC) {
// The kinematic use MotionState class
diff --git a/modules/bullet/rigid_body_bullet.h b/modules/bullet/rigid_body_bullet.h
index 35af3b90d8..f03009bce9 100644
--- a/modules/bullet/rigid_body_bullet.h
+++ b/modules/bullet/rigid_body_bullet.h
@@ -203,9 +203,6 @@ private:
bool can_sleep;
bool omit_forces_integration;
- PhysicsServer::CombineMode restitution_combine_mode;
- PhysicsServer::CombineMode friction_combine_mode;
-
Vector<CollisionData> collisions;
// these parameters are used to avoid vector resize
int maxCollisionsDetection;
@@ -301,12 +298,6 @@ public:
void set_angular_velocity(const Vector3 &p_velocity);
Vector3 get_angular_velocity() const;
- void set_combine_mode(const PhysicsServer::BodyParameter p_param, const PhysicsServer::CombineMode p_mode);
- PhysicsServer::CombineMode get_combine_mode(PhysicsServer::BodyParameter p_param) const;
-
- _FORCE_INLINE_ PhysicsServer::CombineMode get_restitution_combine_mode() const { return restitution_combine_mode; }
- _FORCE_INLINE_ PhysicsServer::CombineMode get_friction_combine_mode() const { return friction_combine_mode; }
-
virtual void set_transform__bullet(const btTransform &p_global_transform);
virtual const btTransform &get_transform__bullet() const;
diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp
index 8454bea4eb..97228a972f 100644
--- a/modules/bullet/space_bullet.cpp
+++ b/modules/bullet/space_bullet.cpp
@@ -554,42 +554,12 @@ BulletPhysicsDirectSpaceState *SpaceBullet::get_direct_state() {
btScalar calculateGodotCombinedRestitution(const btCollisionObject *body0, const btCollisionObject *body1) {
- const PhysicsServer::CombineMode cm = static_cast<RigidBodyBullet *>(body0->getUserPointer())->get_restitution_combine_mode();
-
- switch (cm) {
- case PhysicsServer::COMBINE_MODE_INHERIT:
- if (static_cast<RigidBodyBullet *>(body1->getUserPointer())->get_restitution_combine_mode() != PhysicsServer::COMBINE_MODE_INHERIT)
- return calculateGodotCombinedRestitution(body1, body0);
- // else use MAX [This is used when the two bodies doesn't use physical material]
- case PhysicsServer::COMBINE_MODE_MAX:
- return MAX(body0->getRestitution(), body1->getRestitution());
- case PhysicsServer::COMBINE_MODE_MIN:
- return MIN(body0->getRestitution(), body1->getRestitution());
- case PhysicsServer::COMBINE_MODE_MULTIPLY:
- return body0->getRestitution() * body1->getRestitution();
- default: // Is always PhysicsServer::COMBINE_MODE_AVERAGE:
- return (body0->getRestitution() + body1->getRestitution()) / 2;
- }
+ return CLAMP(body0->getRestitution() + body1->getRestitution(), 0, 1);
}
btScalar calculateGodotCombinedFriction(const btCollisionObject *body0, const btCollisionObject *body1) {
- const PhysicsServer::CombineMode cm = static_cast<RigidBodyBullet *>(body0->getUserPointer())->get_friction_combine_mode();
-
- switch (cm) {
- case PhysicsServer::COMBINE_MODE_INHERIT:
- if (static_cast<RigidBodyBullet *>(body1->getUserPointer())->get_friction_combine_mode() != PhysicsServer::COMBINE_MODE_INHERIT)
- return calculateGodotCombinedFriction(body1, body0);
- // else use MULTIPLY [This is used when the two bodies doesn't use physical material]
- case PhysicsServer::COMBINE_MODE_MULTIPLY:
- return body0->getFriction() * body1->getFriction();
- case PhysicsServer::COMBINE_MODE_MAX:
- return MAX(body0->getFriction(), body1->getFriction());
- case PhysicsServer::COMBINE_MODE_MIN:
- return MIN(body0->getFriction(), body1->getFriction());
- default: // Is always PhysicsServer::COMBINE_MODE_AVERAGE:
- return (body0->getFriction() * body1->getFriction()) / 2;
- }
+ return ABS(MIN(body0->getFriction(), body1->getFriction()));
}
void SpaceBullet::create_empty_world(bool p_create_soft_world) {
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index b3ff21457d..85bef4e7f5 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -197,9 +197,9 @@ void StaticBody2D::set_friction(real_t p_friction) {
if (physics_material_override.is_null()) {
physics_material_override.instance();
+ set_physics_material_override(physics_material_override);
}
physics_material_override->set_friction(p_friction);
- _reload_physics_characteristics();
}
real_t StaticBody2D::get_friction() const {
@@ -223,9 +223,9 @@ void StaticBody2D::set_bounce(real_t p_bounce) {
if (physics_material_override.is_null()) {
physics_material_override.instance();
+ set_physics_material_override(physics_material_override);
}
physics_material_override->set_bounce(p_bounce);
- _reload_physics_characteristics();
}
real_t StaticBody2D::get_bounce() const {
@@ -243,7 +243,8 @@ real_t StaticBody2D::get_bounce() const {
void StaticBody2D::set_physics_material_override(const Ref<PhysicsMaterial> &p_physics_material_override) {
if (physics_material_override.is_valid()) {
- physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, this, "_reload_physics_characteristics");
+ if (physics_material_override->is_connected(CoreStringNames::get_singleton()->changed, this, "_reload_physics_characteristics"))
+ physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, this, "_reload_physics_characteristics");
}
physics_material_override = p_physics_material_override;
@@ -300,13 +301,9 @@ void StaticBody2D::_reload_physics_characteristics() {
if (physics_material_override.is_null()) {
Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, 0);
Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, 1);
- Physics2DServer::get_singleton()->body_set_combine_mode(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, Physics2DServer::COMBINE_MODE_INHERIT);
- Physics2DServer::get_singleton()->body_set_combine_mode(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, Physics2DServer::COMBINE_MODE_INHERIT);
} else {
- Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, physics_material_override->get_bounce());
- Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, physics_material_override->get_friction());
- Physics2DServer::get_singleton()->body_set_combine_mode(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, (Physics2DServer::CombineMode)physics_material_override->get_bounce_combine_mode());
- Physics2DServer::get_singleton()->body_set_combine_mode(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, (Physics2DServer::CombineMode)physics_material_override->get_friction_combine_mode());
+ Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, physics_material_override->computed_bounce());
+ Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, physics_material_override->computed_friction());
}
}
@@ -625,9 +622,9 @@ void RigidBody2D::set_friction(real_t p_friction) {
if (physics_material_override.is_null()) {
physics_material_override.instance();
+ set_physics_material_override(physics_material_override);
}
physics_material_override->set_friction(p_friction);
- _reload_physics_characteristics();
}
real_t RigidBody2D::get_friction() const {
@@ -650,9 +647,9 @@ void RigidBody2D::set_bounce(real_t p_bounce) {
if (physics_material_override.is_null()) {
physics_material_override.instance();
+ set_physics_material_override(physics_material_override);
}
physics_material_override->set_bounce(p_bounce);
- _reload_physics_characteristics();
}
real_t RigidBody2D::get_bounce() const {
@@ -669,7 +666,8 @@ real_t RigidBody2D::get_bounce() const {
void RigidBody2D::set_physics_material_override(const Ref<PhysicsMaterial> &p_physics_material_override) {
if (physics_material_override.is_valid()) {
- physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, this, "_reload_physics_characteristics");
+ if (physics_material_override->is_connected(CoreStringNames::get_singleton()->changed, this, "_reload_physics_characteristics"))
+ physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, this, "_reload_physics_characteristics");
}
physics_material_override = p_physics_material_override;
@@ -1116,13 +1114,9 @@ void RigidBody2D::_reload_physics_characteristics() {
if (physics_material_override.is_null()) {
Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, 0);
Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, 1);
- Physics2DServer::get_singleton()->body_set_combine_mode(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, Physics2DServer::COMBINE_MODE_INHERIT);
- Physics2DServer::get_singleton()->body_set_combine_mode(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, Physics2DServer::COMBINE_MODE_INHERIT);
} else {
- Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, physics_material_override->get_bounce());
- Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, physics_material_override->get_friction());
- Physics2DServer::get_singleton()->body_set_combine_mode(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, (Physics2DServer::CombineMode)physics_material_override->get_bounce_combine_mode());
- Physics2DServer::get_singleton()->body_set_combine_mode(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, (Physics2DServer::CombineMode)physics_material_override->get_friction_combine_mode());
+ Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, physics_material_override->computed_bounce());
+ Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, physics_material_override->computed_friction());
}
}
diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp
index 4b3a4add4a..1c9099ec8b 100644
--- a/scene/3d/physics_body.cpp
+++ b/scene/3d/physics_body.cpp
@@ -189,9 +189,10 @@ void StaticBody::set_friction(real_t p_friction) {
if (physics_material_override.is_null()) {
physics_material_override.instance();
+ set_physics_material_override(physics_material_override);
}
+
physics_material_override->set_friction(p_friction);
- _reload_physics_characteristics();
}
real_t StaticBody::get_friction() const {
@@ -215,9 +216,9 @@ void StaticBody::set_bounce(real_t p_bounce) {
if (physics_material_override.is_null()) {
physics_material_override.instance();
+ set_physics_material_override(physics_material_override);
}
physics_material_override->set_bounce(p_bounce);
- _reload_physics_characteristics();
}
real_t StaticBody::get_bounce() const {
@@ -235,7 +236,8 @@ real_t StaticBody::get_bounce() const {
void StaticBody::set_physics_material_override(const Ref<PhysicsMaterial> &p_physics_material_override) {
if (physics_material_override.is_valid()) {
- physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, this, "_reload_physics_characteristics");
+ if (physics_material_override->is_connected(CoreStringNames::get_singleton()->changed, this, "_reload_physics_characteristics"))
+ physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, this, "_reload_physics_characteristics");
}
physics_material_override = p_physics_material_override;
@@ -313,13 +315,9 @@ void StaticBody::_reload_physics_characteristics() {
if (physics_material_override.is_null()) {
PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, 0);
PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, 1);
- PhysicsServer::get_singleton()->body_set_combine_mode(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, PhysicsServer::COMBINE_MODE_INHERIT);
- PhysicsServer::get_singleton()->body_set_combine_mode(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, PhysicsServer::COMBINE_MODE_INHERIT);
} else {
- PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, physics_material_override->get_bounce());
- PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, physics_material_override->get_friction());
- PhysicsServer::get_singleton()->body_set_combine_mode(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, physics_material_override->get_bounce_combine_mode());
- PhysicsServer::get_singleton()->body_set_combine_mode(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, physics_material_override->get_friction_combine_mode());
+ PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, physics_material_override->computed_bounce());
+ PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, physics_material_override->computed_friction());
}
}
@@ -626,9 +624,9 @@ void RigidBody::set_friction(real_t p_friction) {
if (physics_material_override.is_null()) {
physics_material_override.instance();
+ set_physics_material_override(physics_material_override);
}
physics_material_override->set_friction(p_friction);
- _reload_physics_characteristics();
}
real_t RigidBody::get_friction() const {
@@ -648,9 +646,9 @@ void RigidBody::set_bounce(real_t p_bounce) {
if (physics_material_override.is_null()) {
physics_material_override.instance();
+ set_physics_material_override(physics_material_override);
}
physics_material_override->set_bounce(p_bounce);
- _reload_physics_characteristics();
}
real_t RigidBody::get_bounce() const {
ERR_EXPLAIN("The method get_bounce has been deprecated and will be removed in the future, use physical material")
@@ -665,7 +663,8 @@ real_t RigidBody::get_bounce() const {
void RigidBody::set_physics_material_override(const Ref<PhysicsMaterial> &p_physics_material_override) {
if (physics_material_override.is_valid()) {
- physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, this, "_reload_physics_characteristics");
+ if (physics_material_override->is_connected(CoreStringNames::get_singleton()->changed, this, "_reload_physics_characteristics"))
+ physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, this, "_reload_physics_characteristics");
}
physics_material_override = p_physics_material_override;
@@ -1070,13 +1069,9 @@ void RigidBody::_reload_physics_characteristics() {
if (physics_material_override.is_null()) {
PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, 0);
PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, 1);
- PhysicsServer::get_singleton()->body_set_combine_mode(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, PhysicsServer::COMBINE_MODE_INHERIT);
- PhysicsServer::get_singleton()->body_set_combine_mode(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, PhysicsServer::COMBINE_MODE_INHERIT);
} else {
- PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, physics_material_override->get_bounce());
- PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, physics_material_override->get_friction());
- PhysicsServer::get_singleton()->body_set_combine_mode(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, physics_material_override->get_bounce_combine_mode());
- PhysicsServer::get_singleton()->body_set_combine_mode(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, physics_material_override->get_friction_combine_mode());
+ PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, physics_material_override->computed_bounce());
+ PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, physics_material_override->computed_friction());
}
}
diff --git a/scene/resources/physics_material.cpp b/scene/resources/physics_material.cpp
index de3cfd1371..dc5ca1aef6 100644
--- a/scene/resources/physics_material.cpp
+++ b/scene/resources/physics_material.cpp
@@ -29,66 +29,48 @@
/*************************************************************************/
#include "physics_material.h"
-bool PhysicsMaterial::_set(const StringName &p_name, const Variant &p_value) {
- if (p_name == "bounce") {
- set_bounce(p_value);
- } else if (p_name == "bounce_combine_mode") {
- set_bounce_combine_mode(static_cast<PhysicsServer::CombineMode>(int(p_value)));
- } else if (p_name == "friction") {
- set_friction(p_value);
- } else if (p_name == "friction_combine_mode") {
- set_friction_combine_mode(static_cast<PhysicsServer::CombineMode>(int(p_value)));
- } else {
- return false;
- }
+void PhysicsMaterial::_bind_methods() {
- emit_changed();
- return true;
-}
+ ClassDB::bind_method(D_METHOD("set_friction", "friction"), &PhysicsMaterial::set_friction);
+ ClassDB::bind_method(D_METHOD("get_friction"), &PhysicsMaterial::get_friction);
-bool PhysicsMaterial::_get(const StringName &p_name, Variant &r_ret) const {
- if (p_name == "bounce") {
- r_ret = bounce;
- } else if (p_name == "bounce_combine_mode") {
- r_ret = int(bounce_combine_mode);
- } else if (p_name == "friction") {
- r_ret = friction;
- } else if (p_name == "friction_combine_mode") {
- r_ret = int(friction_combine_mode);
- } else {
- return false;
- }
+ ClassDB::bind_method(D_METHOD("set_rough", "rough"), &PhysicsMaterial::set_rough);
+ ClassDB::bind_method(D_METHOD("is_rough"), &PhysicsMaterial::is_rough);
- return true;
-}
+ ClassDB::bind_method(D_METHOD("set_bounce", "bounce"), &PhysicsMaterial::set_bounce);
+ ClassDB::bind_method(D_METHOD("get_bounce"), &PhysicsMaterial::get_bounce);
-void PhysicsMaterial::_get_property_list(List<PropertyInfo> *p_list) const {
- p_list->push_back(PropertyInfo(Variant::REAL, "bounce"));
- p_list->push_back(PropertyInfo(Variant::INT, "bounce_combine_mode", PROPERTY_HINT_ENUM, "Max,Min,Multiply,Average"));
- p_list->push_back(PropertyInfo(Variant::REAL, "friction"));
- p_list->push_back(PropertyInfo(Variant::INT, "friction_combine_mode", PROPERTY_HINT_ENUM, "Max,Min,Multiply,Average"));
-}
+ ClassDB::bind_method(D_METHOD("set_absorbent", "absorbent"), &PhysicsMaterial::set_absorbent);
+ ClassDB::bind_method(D_METHOD("is_absorbent"), &PhysicsMaterial::is_absorbent);
-void PhysicsMaterial::_bind_methods() {}
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "friction"), "set_friction", "get_friction");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "rough"), "set_rough", "is_rough");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "bounce"), "set_bounce", "get_bounce");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "absorbent"), "set_absorbent", "is_absorbent");
+}
-void PhysicsMaterial::set_bounce(real_t p_val) {
- bounce = p_val;
+void PhysicsMaterial::set_friction(real_t p_val) {
+ friction = p_val;
+ emit_changed();
}
-void PhysicsMaterial::set_bounce_combine_mode(PhysicsServer::CombineMode p_val) {
- bounce_combine_mode = p_val;
+void PhysicsMaterial::set_rough(bool p_val) {
+ rough = p_val;
+ emit_changed();
}
-void PhysicsMaterial::set_friction(real_t p_val) {
- friction = p_val;
+void PhysicsMaterial::set_bounce(real_t p_val) {
+ bounce = p_val;
+ emit_changed();
}
-void PhysicsMaterial::set_friction_combine_mode(PhysicsServer::CombineMode p_val) {
- friction_combine_mode = p_val;
+void PhysicsMaterial::set_absorbent(bool p_val) {
+ absorbent = p_val;
+ emit_changed();
}
PhysicsMaterial::PhysicsMaterial() :
+ friction(1),
+ rough(false),
bounce(0),
- bounce_combine_mode(PhysicsServer::COMBINE_MODE_MAX),
- friction(0),
- friction_combine_mode(PhysicsServer::COMBINE_MODE_MULTIPLY) {}
+ absorbent(false) {}
diff --git a/scene/resources/physics_material.h b/scene/resources/physics_material.h
index a6cb8c288e..dfe48d94cf 100644
--- a/scene/resources/physics_material.h
+++ b/scene/resources/physics_material.h
@@ -39,30 +39,34 @@ class PhysicsMaterial : public Resource {
OBJ_SAVE_TYPE(PhysicsMaterial);
RES_BASE_EXTENSION("PhyMat");
- real_t bounce;
- PhysicsServer::CombineMode bounce_combine_mode;
real_t friction;
- PhysicsServer::CombineMode friction_combine_mode;
+ bool rough;
+ real_t bounce;
+ bool absorbent;
protected:
- bool _set(const StringName &p_name, const Variant &p_value);
- bool _get(const StringName &p_name, Variant &r_ret) const;
- void _get_property_list(List<PropertyInfo> *p_list) const;
-
static void _bind_methods();
public:
+ void set_friction(real_t p_val);
+ _FORCE_INLINE_ real_t get_friction() const { return friction; }
+
+ void set_rough(bool p_val);
+ _FORCE_INLINE_ bool is_rough() const { return rough; }
+
+ _FORCE_INLINE_ real_t computed_friction() const {
+ return rough ? -friction : friction;
+ }
+
void set_bounce(real_t p_val);
_FORCE_INLINE_ real_t get_bounce() const { return bounce; }
- void set_bounce_combine_mode(PhysicsServer::CombineMode p_val);
- _FORCE_INLINE_ PhysicsServer::CombineMode get_bounce_combine_mode() const { return bounce_combine_mode; }
-
- void set_friction(real_t p_val);
- _FORCE_INLINE_ real_t get_friction() const { return friction; }
+ void set_absorbent(bool p_val);
+ _FORCE_INLINE_ bool is_absorbent() const { return absorbent; }
- void set_friction_combine_mode(PhysicsServer::CombineMode p_val);
- _FORCE_INLINE_ PhysicsServer::CombineMode get_friction_combine_mode() const { return friction_combine_mode; }
+ _FORCE_INLINE_ real_t computed_bounce() const {
+ return absorbent ? -bounce : bounce;
+ }
PhysicsMaterial();
};
diff --git a/servers/physics/body_pair_sw.cpp b/servers/physics/body_pair_sw.cpp
index 5a41b621eb..0ce38e4486 100644
--- a/servers/physics/body_pair_sw.cpp
+++ b/servers/physics/body_pair_sw.cpp
@@ -212,41 +212,11 @@ bool BodyPairSW::_test_ccd(real_t p_step, BodySW *p_A, int p_shape_A, const Tran
}
real_t combine_bounce(BodySW *A, BodySW *B) {
- const PhysicsServer::CombineMode cm = A->get_bounce_combine_mode();
-
- switch (cm) {
- case PhysicsServer::COMBINE_MODE_INHERIT:
- if (B->get_bounce_combine_mode() != PhysicsServer::COMBINE_MODE_INHERIT)
- return combine_bounce(B, A);
- // else use MAX [This is used when the two bodies doesn't use physical material]
- case PhysicsServer::COMBINE_MODE_MAX:
- return MAX(A->get_bounce(), B->get_bounce());
- case PhysicsServer::COMBINE_MODE_MIN:
- return MIN(A->get_bounce(), B->get_bounce());
- case PhysicsServer::COMBINE_MODE_MULTIPLY:
- return A->get_bounce() * B->get_bounce();
- default: // Is always PhysicsServer::COMBINE_MODE_AVERAGE:
- return (A->get_bounce() + B->get_bounce()) / 2;
- }
+ return CLAMP(A->get_bounce() + B->get_bounce(), 0, 1);
}
real_t combine_friction(BodySW *A, BodySW *B) {
- const PhysicsServer::CombineMode cm = A->get_friction_combine_mode();
-
- switch (cm) {
- case PhysicsServer::COMBINE_MODE_INHERIT:
- if (B->get_friction_combine_mode() != PhysicsServer::COMBINE_MODE_INHERIT)
- return combine_friction(B, A);
- // else use Multiply [This is used when the two bodies doesn't use physical material]
- case PhysicsServer::COMBINE_MODE_MULTIPLY:
- return A->get_friction() * B->get_friction();
- case PhysicsServer::COMBINE_MODE_MAX:
- return MAX(A->get_friction(), B->get_friction());
- case PhysicsServer::COMBINE_MODE_MIN:
- return MIN(A->get_friction(), B->get_friction());
- default: // Is always PhysicsServer::COMBINE_MODE_AVERAGE:
- return (A->get_friction() + B->get_friction()) / 2;
- }
+ return ABS(MIN(A->get_friction(), B->get_friction()));
}
bool BodyPairSW::setup(real_t p_step) {
diff --git a/servers/physics/body_sw.cpp b/servers/physics/body_sw.cpp
index 59f987fc17..cc9681193c 100644
--- a/servers/physics/body_sw.cpp
+++ b/servers/physics/body_sw.cpp
@@ -423,22 +423,6 @@ void BodySW::_compute_area_gravity_and_dampenings(const AreaSW *p_area) {
area_angular_damp += p_area->get_angular_damp();
}
-void BodySW::set_combine_mode(PhysicsServer::BodyParameter p_param, PhysicsServer::CombineMode p_mode) {
- if (p_param == PhysicsServer::BODY_PARAM_BOUNCE) {
- bounce_combine_mode = p_mode;
- } else {
- friction_combine_mode = p_mode;
- }
-}
-
-PhysicsServer::CombineMode BodySW::get_combine_mode(PhysicsServer::BodyParameter p_param) const {
- if (p_param == PhysicsServer::BODY_PARAM_BOUNCE) {
- return bounce_combine_mode;
- } else {
- return friction_combine_mode;
- }
-}
-
void BodySW::set_axis_lock(PhysicsServer::BodyAxis p_axis, bool lock) {
if (lock) {
locked_axis |= p_axis;
diff --git a/servers/physics/body_sw.h b/servers/physics/body_sw.h
index 5df270f679..9d7b147fd6 100644
--- a/servers/physics/body_sw.h
+++ b/servers/physics/body_sw.h
@@ -49,8 +49,6 @@ class BodySW : public CollisionObjectSW {
real_t mass;
real_t bounce;
real_t friction;
- PhysicsServer::CombineMode bounce_combine_mode;
- PhysicsServer::CombineMode friction_combine_mode;
real_t linear_damp;
real_t angular_damp;
@@ -304,12 +302,6 @@ public:
_FORCE_INLINE_ Vector3 get_gravity() const { return gravity; }
_FORCE_INLINE_ real_t get_bounce() const { return bounce; }
- void set_combine_mode(PhysicsServer::BodyParameter p_param, PhysicsServer::CombineMode p_mode);
- PhysicsServer::CombineMode get_combine_mode(PhysicsServer::BodyParameter p_param) const;
-
- _FORCE_INLINE_ PhysicsServer::CombineMode get_bounce_combine_mode() const { return bounce_combine_mode; }
- _FORCE_INLINE_ PhysicsServer::CombineMode get_friction_combine_mode() const { return friction_combine_mode; }
-
void set_axis_lock(PhysicsServer::BodyAxis p_axis, bool lock);
bool is_axis_locked(PhysicsServer::BodyAxis p_axis) const;
diff --git a/servers/physics/physics_server_sw.cpp b/servers/physics/physics_server_sw.cpp
index a06942cb2a..3a32c46a9b 100644
--- a/servers/physics/physics_server_sw.cpp
+++ b/servers/physics/physics_server_sw.cpp
@@ -701,20 +701,6 @@ real_t PhysicsServerSW::body_get_param(RID p_body, BodyParameter p_param) const
return body->get_param(p_param);
};
-void PhysicsServerSW::body_set_combine_mode(RID p_body, BodyParameter p_param, CombineMode p_mode) {
- BodySW *body = body_owner.get(p_body);
- ERR_FAIL_COND(!body);
-
- body->set_combine_mode(p_param, p_mode);
-}
-
-PhysicsServer::CombineMode PhysicsServerSW::body_get_combine_mode(RID p_body, BodyParameter p_param) const {
- BodySW *body = body_owner.get(p_body);
- ERR_FAIL_COND_V(!body, COMBINE_MODE_INHERIT);
-
- return body->get_combine_mode(p_param);
-}
-
void PhysicsServerSW::body_set_kinematic_safe_margin(RID p_body, real_t p_margin) {
BodySW *body = body_owner.get(p_body);
ERR_FAIL_COND(!body);
diff --git a/servers/physics/physics_server_sw.h b/servers/physics/physics_server_sw.h
index 57037fb325..1c5754124d 100644
--- a/servers/physics/physics_server_sw.h
+++ b/servers/physics/physics_server_sw.h
@@ -188,10 +188,6 @@ public:
virtual void body_set_param(RID p_body, BodyParameter p_param, real_t p_value);
virtual real_t body_get_param(RID p_body, BodyParameter p_param) const;
- /// p_param accept only Bounce and Friction
- virtual void body_set_combine_mode(RID p_body, BodyParameter p_param, CombineMode p_mode);
- virtual CombineMode body_get_combine_mode(RID p_body, BodyParameter p_param) const;
-
virtual void body_set_kinematic_safe_margin(RID p_body, real_t p_margin);
virtual real_t body_get_kinematic_safe_margin(RID p_body) const;
diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp
index fcd2a65ee7..aa063d6c1e 100644
--- a/servers/physics_2d/body_2d_sw.cpp
+++ b/servers/physics_2d/body_2d_sw.cpp
@@ -405,22 +405,6 @@ void Body2DSW::_compute_area_gravity_and_dampenings(const Area2DSW *p_area) {
area_angular_damp += p_area->get_angular_damp();
}
-void Body2DSW::set_combine_mode(Physics2DServer::BodyParameter p_param, Physics2DServer::CombineMode p_mode) {
- if (p_param == Physics2DServer::BODY_PARAM_BOUNCE) {
- bounce_combine_mode = p_mode;
- } else {
- friction_combine_mode = p_mode;
- }
-}
-
-Physics2DServer::CombineMode Body2DSW::get_combine_mode(Physics2DServer::BodyParameter p_param) const {
- if (p_param == Physics2DServer::BODY_PARAM_BOUNCE) {
- return bounce_combine_mode;
- } else {
- return friction_combine_mode;
- }
-}
-
void Body2DSW::integrate_forces(real_t p_step) {
if (mode == Physics2DServer::BODY_MODE_STATIC)
diff --git a/servers/physics_2d/body_2d_sw.h b/servers/physics_2d/body_2d_sw.h
index fef233a72b..69184ad484 100644
--- a/servers/physics_2d/body_2d_sw.h
+++ b/servers/physics_2d/body_2d_sw.h
@@ -54,8 +54,6 @@ class Body2DSW : public CollisionObject2DSW {
real_t mass;
real_t bounce;
real_t friction;
- Physics2DServer::CombineMode bounce_combine_mode;
- Physics2DServer::CombineMode friction_combine_mode;
real_t _inv_mass;
real_t _inv_inertia;
@@ -274,12 +272,6 @@ public:
_FORCE_INLINE_ real_t get_linear_damp() const { return linear_damp; }
_FORCE_INLINE_ real_t get_angular_damp() const { return angular_damp; }
- void set_combine_mode(Physics2DServer::BodyParameter p_param, Physics2DServer::CombineMode p_mode);
- Physics2DServer::CombineMode get_combine_mode(Physics2DServer::BodyParameter p_param) const;
-
- _FORCE_INLINE_ Physics2DServer::CombineMode get_bounce_combine_mode() const { return bounce_combine_mode; }
- _FORCE_INLINE_ Physics2DServer::CombineMode get_friction_combine_mode() const { return friction_combine_mode; }
-
void integrate_forces(real_t p_step);
void integrate_velocities(real_t p_step);
diff --git a/servers/physics_2d/body_pair_2d_sw.cpp b/servers/physics_2d/body_pair_2d_sw.cpp
index be8dcf6fa8..2633edf7bb 100644
--- a/servers/physics_2d/body_pair_2d_sw.cpp
+++ b/servers/physics_2d/body_pair_2d_sw.cpp
@@ -220,41 +220,11 @@ bool BodyPair2DSW::_test_ccd(real_t p_step, Body2DSW *p_A, int p_shape_A, const
}
real_t combine_bounce(Body2DSW *A, Body2DSW *B) {
- const Physics2DServer::CombineMode cm = A->get_bounce_combine_mode();
-
- switch (cm) {
- case Physics2DServer::COMBINE_MODE_INHERIT:
- if (B->get_bounce_combine_mode() != Physics2DServer::COMBINE_MODE_INHERIT)
- return combine_bounce(B, A);
- // else use MAX [This is used when the two bodies doesn't use physical material]
- case Physics2DServer::COMBINE_MODE_MAX:
- return MAX(A->get_bounce(), B->get_bounce());
- case Physics2DServer::COMBINE_MODE_MIN:
- return MIN(A->get_bounce(), B->get_bounce());
- case Physics2DServer::COMBINE_MODE_MULTIPLY:
- return A->get_bounce() * B->get_bounce();
- default: // Is always Physics2DServer::COMBINE_MODE_AVERAGE:
- return (A->get_bounce() + B->get_bounce()) / 2;
- }
+ return CLAMP(A->get_bounce() + B->get_bounce(), 0, 1);
}
real_t combine_friction(Body2DSW *A, Body2DSW *B) {
- const Physics2DServer::CombineMode cm = A->get_friction_combine_mode();
-
- switch (cm) {
- case Physics2DServer::COMBINE_MODE_INHERIT:
- if (B->get_friction_combine_mode() != Physics2DServer::COMBINE_MODE_INHERIT)
- return combine_friction(B, A);
- // else use Multiply [This is used when the two bodies doesn't use physical material]
- case Physics2DServer::COMBINE_MODE_MULTIPLY:
- return A->get_friction() * B->get_friction();
- case Physics2DServer::COMBINE_MODE_MAX:
- return MAX(A->get_friction(), B->get_friction());
- case Physics2DServer::COMBINE_MODE_MIN:
- return MIN(A->get_friction(), B->get_friction());
- default: // Is always Physics2DServer::COMBINE_MODE_AVERAGE:
- return (A->get_friction() + B->get_friction()) / 2;
- }
+ return ABS(MIN(A->get_friction(), B->get_friction()));
}
bool BodyPair2DSW::setup(real_t p_step) {
diff --git a/servers/physics_2d/physics_2d_server_sw.cpp b/servers/physics_2d/physics_2d_server_sw.cpp
index ba87969eea..15e80bcd5e 100644
--- a/servers/physics_2d/physics_2d_server_sw.cpp
+++ b/servers/physics_2d/physics_2d_server_sw.cpp
@@ -789,22 +789,6 @@ real_t Physics2DServerSW::body_get_param(RID p_body, BodyParameter p_param) cons
return body->get_param(p_param);
};
-void Physics2DServerSW::body_set_combine_mode(RID p_body, BodyParameter p_param, CombineMode p_mode) {
-
- Body2DSW *body = body_owner.get(p_body);
- ERR_FAIL_COND(!body);
-
- body->set_combine_mode(p_param, p_mode);
-}
-
-Physics2DServer::CombineMode Physics2DServerSW::body_get_combine_mode(RID p_body, BodyParameter p_param) const {
-
- Body2DSW *body = body_owner.get(p_body);
- ERR_FAIL_COND_V(!body, COMBINE_MODE_INHERIT);
-
- return body->get_combine_mode(p_param);
-}
-
void Physics2DServerSW::body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) {
Body2DSW *body = body_owner.get(p_body);
diff --git a/servers/physics_2d/physics_2d_server_sw.h b/servers/physics_2d/physics_2d_server_sw.h
index 0b8d3f2a31..d4fc44b1d7 100644
--- a/servers/physics_2d/physics_2d_server_sw.h
+++ b/servers/physics_2d/physics_2d_server_sw.h
@@ -200,10 +200,6 @@ public:
virtual void body_set_param(RID p_body, BodyParameter p_param, real_t p_value);
virtual real_t body_get_param(RID p_body, BodyParameter p_param) const;
- /// p_param accept only Bounce and Friction
- virtual void body_set_combine_mode(RID p_body, BodyParameter p_param, CombineMode p_mode);
- virtual CombineMode body_get_combine_mode(RID p_body, BodyParameter p_param) const;
-
virtual void body_set_state(RID p_body, BodyState p_state, const Variant &p_variant);
virtual Variant body_get_state(RID p_body, BodyState p_state) const;
diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.h b/servers/physics_2d/physics_2d_server_wrap_mt.h
index b9b0f80805..6b34fb9739 100644
--- a/servers/physics_2d/physics_2d_server_wrap_mt.h
+++ b/servers/physics_2d/physics_2d_server_wrap_mt.h
@@ -211,9 +211,6 @@ public:
FUNC3(body_set_param, RID, BodyParameter, real_t);
FUNC2RC(real_t, body_get_param, RID, BodyParameter);
- FUNC3(body_set_combine_mode, RID, BodyParameter, CombineMode);
- FUNC2RC(CombineMode, body_get_combine_mode, RID, BodyParameter);
-
FUNC3(body_set_state, RID, BodyState, const Variant &);
FUNC2RC(Variant, body_get_state, RID, BodyState);
diff --git a/servers/physics_2d_server.h b/servers/physics_2d_server.h
index 796eec1e8e..f42d9868f0 100644
--- a/servers/physics_2d_server.h
+++ b/servers/physics_2d_server.h
@@ -423,19 +423,6 @@ public:
virtual void body_set_param(RID p_body, BodyParameter p_param, float p_value) = 0;
virtual float body_get_param(RID p_body, BodyParameter p_param) const = 0;
- enum CombineMode {
- COMBINE_MODE_MAX,
- COMBINE_MODE_MIN,
- COMBINE_MODE_MULTIPLY,
- COMBINE_MODE_AVERAGE,
-
- COMBINE_MODE_INHERIT /// Inherit from other body or use COMBINE_MODE_MAX (Restitution) COMBINE_MODE_MULTIPLY (Friction)
- };
-
- /// p_param accept only Bounce and Friction
- virtual void body_set_combine_mode(RID p_body, BodyParameter p_param, CombineMode p_mode) = 0;
- virtual CombineMode body_get_combine_mode(RID p_body, BodyParameter p_param) const = 0;
-
//state
enum BodyState {
BODY_STATE_TRANSFORM,
diff --git a/servers/physics_server.h b/servers/physics_server.h
index 294c6b6674..948aec1a2d 100644
--- a/servers/physics_server.h
+++ b/servers/physics_server.h
@@ -401,19 +401,6 @@ public:
virtual void body_set_param(RID p_body, BodyParameter p_param, float p_value) = 0;
virtual float body_get_param(RID p_body, BodyParameter p_param) const = 0;
- enum CombineMode {
- COMBINE_MODE_MAX,
- COMBINE_MODE_MIN,
- COMBINE_MODE_MULTIPLY,
- COMBINE_MODE_AVERAGE,
-
- COMBINE_MODE_INHERIT /// Inherit from other body or use COMBINE_MODE_MAX (Restitution) COMBINE_MODE_MULTIPLY (Friction)
- };
-
- /// p_param accept only Bounce and Friction
- virtual void body_set_combine_mode(RID p_body, BodyParameter p_param, CombineMode p_mode) = 0;
- virtual CombineMode body_get_combine_mode(RID p_body, BodyParameter p_param) const = 0;
-
virtual void body_set_kinematic_safe_margin(RID p_body, real_t p_margin) = 0;
virtual real_t body_get_kinematic_safe_margin(RID p_body) const = 0;