Merge pull request #20381 from AndreaCatania/phymat_2

Improved Physics material
This commit is contained in:
Juan Linietsky
2018-08-07 15:31:26 -03:00
committed by GitHub
22 changed files with 80 additions and 354 deletions

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);

View File

@@ -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;