summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
authorMariano Javier Suligoy <marianognu.easyrpg@gmail.com>2015-08-30 19:39:36 -0300
committerMariano Javier Suligoy <marianognu.easyrpg@gmail.com>2015-08-30 19:39:36 -0300
commit553edf1f250f34ca0ef0703b13b4d601f609e491 (patch)
tree54e7cbf1ed368a872441ef6efc2fa2c027c45c89 /servers
parent680402cebf63066abcc93e7e8035e457c6305874 (diff)
parent2d8866574dd2c06ac03e7055642b917a0a3c6dac (diff)
Merge branch 'master' of https://github.com/okamstudio/godot
# Solved Conflicts: # scene/gui/spin_box.cpp # scene/gui/tree.cpp
Diffstat (limited to 'servers')
-rw-r--r--servers/physics/area_sw.cpp9
-rw-r--r--servers/physics/area_sw.h10
-rw-r--r--servers/physics/body_sw.cpp53
-rw-r--r--servers/physics/body_sw.h15
-rw-r--r--servers/physics_2d/body_2d_sw.h6
-rw-r--r--servers/physics_server.cpp24
-rw-r--r--servers/physics_server.h13
7 files changed, 100 insertions, 30 deletions
diff --git a/servers/physics/area_sw.cpp b/servers/physics/area_sw.cpp
index 83be80f816..01dfdd633f 100644
--- a/servers/physics/area_sw.cpp
+++ b/servers/physics/area_sw.cpp
@@ -123,7 +123,8 @@ void AreaSW::set_param(PhysicsServer::AreaParameter p_param, const Variant& p_va
case PhysicsServer::AREA_PARAM_GRAVITY_IS_POINT: gravity_is_point=p_value; ; break;
case PhysicsServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE: gravity_distance_scale=p_value; ; break;
case PhysicsServer::AREA_PARAM_GRAVITY_POINT_ATTENUATION: point_attenuation=p_value; ; break;
- case PhysicsServer::AREA_PARAM_DENSITY: density=p_value; ; break;
+ case PhysicsServer::AREA_PARAM_LINEAR_DAMP: linear_damp=p_value; ; break;
+ case PhysicsServer::AREA_PARAM_ANGULAR_DAMP: angular_damp=p_value; ; break;
case PhysicsServer::AREA_PARAM_PRIORITY: priority=p_value; ; break;
}
@@ -139,7 +140,8 @@ Variant AreaSW::get_param(PhysicsServer::AreaParameter p_param) const {
case PhysicsServer::AREA_PARAM_GRAVITY_IS_POINT: return gravity_is_point;
case PhysicsServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE: return gravity_distance_scale;
case PhysicsServer::AREA_PARAM_GRAVITY_POINT_ATTENUATION: return point_attenuation;
- case PhysicsServer::AREA_PARAM_DENSITY: return density;
+ case PhysicsServer::AREA_PARAM_LINEAR_DAMP: return linear_damp;
+ case PhysicsServer::AREA_PARAM_ANGULAR_DAMP: return angular_damp;
case PhysicsServer::AREA_PARAM_PRIORITY: return priority;
}
@@ -248,7 +250,8 @@ AreaSW::AreaSW() : CollisionObjectSW(TYPE_AREA), monitor_query_list(this), move
gravity_is_point=false;
gravity_distance_scale=0;
point_attenuation=1;
- density=0.1;
+ angular_damp=1.0;
+ linear_damp=0.1;
priority=0;
set_ray_pickable(false);
monitor_callback_id=0;
diff --git a/servers/physics/area_sw.h b/servers/physics/area_sw.h
index 26d6a177db..0c5295d42a 100644
--- a/servers/physics/area_sw.h
+++ b/servers/physics/area_sw.h
@@ -47,7 +47,8 @@ class AreaSW : public CollisionObjectSW{
bool gravity_is_point;
float gravity_distance_scale;
float point_attenuation;
- float density;
+ float linear_damp;
+ float angular_damp;
int priority;
bool monitorable;
@@ -145,8 +146,11 @@ public:
_FORCE_INLINE_ void set_point_attenuation(float p_point_attenuation) { point_attenuation=p_point_attenuation; }
_FORCE_INLINE_ float get_point_attenuation() const { return point_attenuation; }
- _FORCE_INLINE_ void set_density(float p_density) { density=p_density; }
- _FORCE_INLINE_ float get_density() const { return density; }
+ _FORCE_INLINE_ void set_linear_damp(float p_linear_damp) { linear_damp=p_linear_damp; }
+ _FORCE_INLINE_ float get_linear_damp() const { return linear_damp; }
+
+ _FORCE_INLINE_ void set_angular_damp(float p_angular_damp) { angular_damp=p_angular_damp; }
+ _FORCE_INLINE_ float get_angular_damp() const { return angular_damp; }
_FORCE_INLINE_ void set_priority(int p_priority) { priority=p_priority; }
_FORCE_INLINE_ int get_priority() const { return priority; }
diff --git a/servers/physics/body_sw.cpp b/servers/physics/body_sw.cpp
index 5a528ecf94..8edbaf0b89 100644
--- a/servers/physics/body_sw.cpp
+++ b/servers/physics/body_sw.cpp
@@ -159,6 +159,17 @@ void BodySW::set_param(PhysicsServer::BodyParameter p_param, float p_value) {
_update_inertia();
} break;
+ case PhysicsServer::BODY_PARAM_GRAVITY_SCALE: {
+ gravity_scale=p_value;
+ } break;
+ case PhysicsServer::BODY_PARAM_LINEAR_DAMP: {
+
+ linear_damp=p_value;
+ } break;
+ case PhysicsServer::BODY_PARAM_ANGULAR_DAMP: {
+
+ angular_damp=p_value;
+ } break;
default:{}
}
}
@@ -177,6 +188,18 @@ float BodySW::get_param(PhysicsServer::BodyParameter p_param) const {
case PhysicsServer::BODY_PARAM_MASS: {
return mass;
} break;
+ case PhysicsServer::BODY_PARAM_GRAVITY_SCALE: {
+ return gravity_scale;
+ } break;
+ case PhysicsServer::BODY_PARAM_LINEAR_DAMP: {
+
+ return linear_damp;
+ } break;
+ case PhysicsServer::BODY_PARAM_ANGULAR_DAMP: {
+
+ return angular_damp;
+ } break;
+
default:{}
}
@@ -380,6 +403,8 @@ void BodySW::integrate_forces(real_t p_step) {
return;
AreaSW *def_area = get_space()->get_default_area();
+ AreaSW *damp_area = def_area;
+
ERR_FAIL_COND(!def_area);
int ac = areas.size();
@@ -388,7 +413,7 @@ void BodySW::integrate_forces(real_t p_step) {
if (ac) {
areas.sort();
const AreaCMP *aa = &areas[0];
- density = aa[ac-1].area->get_density();
+ damp_area = aa[ac-1].area;
for(int i=ac-1;i>=0;i--) {
_compute_area_gravity(aa[i].area);
if (aa[i].area->get_space_override_mode() == PhysicsServer::AREA_SPACE_OVERRIDE_REPLACE) {
@@ -396,13 +421,25 @@ void BodySW::integrate_forces(real_t p_step) {
break;
}
}
- } else {
- density=def_area->get_density();
}
+
if( !replace ) {
_compute_area_gravity(def_area);
}
+ gravity*=gravity_scale;
+
+ if (angular_damp>=0)
+ area_angular_damp=angular_damp;
+ else
+ area_angular_damp=damp_area->get_angular_damp();
+
+ if (linear_damp>=0)
+ area_linear_damp=linear_damp;
+ else
+ area_linear_damp=damp_area->get_linear_damp();
+
+
Vector3 motion;
bool do_motion=false;
@@ -431,12 +468,12 @@ void BodySW::integrate_forces(real_t p_step) {
force+=applied_force;
Vector3 torque=applied_torque;
- real_t damp = 1.0 - p_step * density;
+ real_t damp = 1.0 - p_step * area_linear_damp;
if (damp<0) // reached zero in the given time
damp=0;
- real_t angular_damp = 1.0 - p_step * density * get_space()->get_body_angular_velocity_damp_ratio();
+ real_t angular_damp = 1.0 - p_step * area_angular_damp;
if (angular_damp<0) // reached zero in the given time
angular_damp=0;
@@ -695,8 +732,12 @@ BodySW::BodySW() : CollisionObjectSW(TYPE_BODY), active_list(this), inertia_upda
island_list_next=NULL;
first_time_kinematic=false;
_set_static(false);
- density=0;
+
contact_count=0;
+ gravity_scale=1.0;
+
+ area_angular_damp=0;
+ area_linear_damp=0;
still_time=0;
continuous_cd=false;
diff --git a/servers/physics/body_sw.h b/servers/physics/body_sw.h
index 6491ba8f18..66d814bfd1 100644
--- a/servers/physics/body_sw.h
+++ b/servers/physics/body_sw.h
@@ -50,6 +50,10 @@ class BodySW : public CollisionObjectSW {
real_t bounce;
real_t friction;
+ real_t linear_damp;
+ real_t angular_damp;
+ real_t gravity_scale;
+
PhysicsServer::BodyAxisLock axis_lock;
real_t _inv_mass;
@@ -57,13 +61,16 @@ class BodySW : public CollisionObjectSW {
Matrix3 _inv_inertia_tensor;
Vector3 gravity;
- real_t density;
real_t still_time;
Vector3 applied_force;
Vector3 applied_torque;
+ float area_angular_damp;
+ float area_linear_damp;
+
+
SelfList<BodySW> active_list;
SelfList<BodySW> inertia_update_list;
SelfList<BodySW> direct_state_query_list;
@@ -233,7 +240,6 @@ public:
_FORCE_INLINE_ Matrix3 get_inv_inertia_tensor() const { return _inv_inertia_tensor; }
_FORCE_INLINE_ real_t get_friction() const { return friction; }
_FORCE_INLINE_ Vector3 get_gravity() const { return gravity; }
- _FORCE_INLINE_ real_t get_density() const { return density; }
_FORCE_INLINE_ real_t get_bounce() const { return bounce; }
_FORCE_INLINE_ void set_axis_lock(PhysicsServer::BodyAxisLock p_lock) { axis_lock=p_lock; }
@@ -335,8 +341,9 @@ public:
BodySW *body;
real_t step;
- virtual Vector3 get_total_gravity() const { return body->get_gravity(); } // get gravity vector working on this body space/area
- virtual float get_total_density() const { return body->get_density(); } // get density of this body space/area
+ virtual Vector3 get_total_gravity() const { return body->gravity; } // get gravity vector working on this body space/area
+ virtual float get_total_angular_damp() const { return body->area_angular_damp; } // get density of this body space/area
+ virtual float get_total_linear_damp() const { return body->area_linear_damp; } // get density of this body space/area
virtual float get_inverse_mass() const { return body->get_inv_mass(); } // get the mass
virtual Vector3 get_inverse_inertia() const { return body->get_inv_inertia(); } // get density of this body space
diff --git a/servers/physics_2d/body_2d_sw.h b/servers/physics_2d/body_2d_sw.h
index c86bb51f1d..2fbfcaca60 100644
--- a/servers/physics_2d/body_2d_sw.h
+++ b/servers/physics_2d/body_2d_sw.h
@@ -337,9 +337,9 @@ public:
Body2DSW *body;
real_t step;
- virtual Vector2 get_total_gravity() const { return body->get_gravity(); } // get gravity vector working on this body space/area
- virtual float get_total_angular_damp() const { return body->get_angular_damp(); } // get density of this body space/area
- virtual float get_total_linear_damp() const { return body->get_linear_damp(); } // get density of this body space/area
+ virtual Vector2 get_total_gravity() const { return body->gravity; } // get gravity vector working on this body space/area
+ virtual float get_total_angular_damp() const { return body->area_angular_damp; } // get density of this body space/area
+ virtual float get_total_linear_damp() const { return body->area_linear_damp; } // get density of this body space/area
virtual float get_inverse_mass() const { return body->get_inv_mass(); } // get the mass
virtual real_t get_inverse_inertia() const { return body->get_inv_inertia(); } // get density of this body space
diff --git a/servers/physics_server.cpp b/servers/physics_server.cpp
index e02601af41..53409acdfb 100644
--- a/servers/physics_server.cpp
+++ b/servers/physics_server.cpp
@@ -39,13 +39,18 @@ void PhysicsDirectBodyState::integrate_forces() {
Vector3 av = get_angular_velocity();
- float damp = 1.0 - step * get_total_density();
+ float linear_damp = 1.0 - step * get_total_linear_damp();
- if (damp<0) // reached zero in the given time
- damp=0;
+ if (linear_damp<0) // reached zero in the given time
+ linear_damp=0;
- lv*=damp;
- av*=damp;
+ float angular_damp = 1.0 - step * get_total_angular_damp();
+
+ if (angular_damp<0) // reached zero in the given time
+ angular_damp=0;
+
+ lv*=linear_damp;
+ av*=angular_damp;
set_linear_velocity(lv);
set_angular_velocity(av);
@@ -70,7 +75,8 @@ PhysicsServer * PhysicsServer::get_singleton() {
void PhysicsDirectBodyState::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_total_gravity"),&PhysicsDirectBodyState::get_total_gravity);
- ObjectTypeDB::bind_method(_MD("get_total_density"),&PhysicsDirectBodyState::get_total_density);
+ ObjectTypeDB::bind_method(_MD("get_total_linear_damp"),&PhysicsDirectBodyState::get_total_linear_damp);
+ ObjectTypeDB::bind_method(_MD("get_total_angular_damp"),&PhysicsDirectBodyState::get_total_angular_damp);
ObjectTypeDB::bind_method(_MD("get_inverse_mass"),&PhysicsDirectBodyState::get_inverse_mass);
ObjectTypeDB::bind_method(_MD("get_inverse_inertia"),&PhysicsDirectBodyState::get_inverse_inertia);
@@ -683,7 +689,8 @@ void PhysicsServer::_bind_methods() {
BIND_CONSTANT( AREA_PARAM_GRAVITY_IS_POINT );
BIND_CONSTANT( AREA_PARAM_GRAVITY_DISTANCE_SCALE );
BIND_CONSTANT( AREA_PARAM_GRAVITY_POINT_ATTENUATION );
- BIND_CONSTANT( AREA_PARAM_DENSITY );
+ BIND_CONSTANT( AREA_PARAM_LINEAR_DAMP );
+ BIND_CONSTANT( AREA_PARAM_ANGULAR_DAMP );
BIND_CONSTANT( AREA_PARAM_PRIORITY );
BIND_CONSTANT( AREA_SPACE_OVERRIDE_COMBINE );
@@ -698,6 +705,9 @@ void PhysicsServer::_bind_methods() {
BIND_CONSTANT( BODY_PARAM_BOUNCE );
BIND_CONSTANT( BODY_PARAM_FRICTION );
BIND_CONSTANT( BODY_PARAM_MASS );
+ BIND_CONSTANT( BODY_PARAM_GRAVITY_SCALE );
+ BIND_CONSTANT( BODY_PARAM_ANGULAR_DAMP );
+ BIND_CONSTANT( BODY_PARAM_LINEAR_DAMP );
BIND_CONSTANT( BODY_PARAM_MAX );
BIND_CONSTANT( BODY_STATE_TRANSFORM );
diff --git a/servers/physics_server.h b/servers/physics_server.h
index f66ea590b8..b82d4cf5da 100644
--- a/servers/physics_server.h
+++ b/servers/physics_server.h
@@ -41,8 +41,9 @@ protected:
static void _bind_methods();
public:
- virtual Vector3 get_total_gravity() const=0; // get gravity vector working on this body space/area
- virtual float get_total_density() const=0; // get density of this body space/area
+ virtual Vector3 get_total_gravity() const=0;
+ virtual float get_total_angular_damp() const=0;
+ virtual float get_total_linear_damp() const=0;
virtual float get_inverse_mass() const=0; // get the mass
virtual Vector3 get_inverse_inertia() const=0; // get density of this body space
@@ -300,7 +301,8 @@ public:
AREA_PARAM_GRAVITY_IS_POINT,
AREA_PARAM_GRAVITY_DISTANCE_SCALE,
AREA_PARAM_GRAVITY_POINT_ATTENUATION,
- AREA_PARAM_DENSITY,
+ AREA_PARAM_LINEAR_DAMP,
+ AREA_PARAM_ANGULAR_DAMP,
AREA_PARAM_PRIORITY
};
@@ -398,6 +400,9 @@ public:
BODY_PARAM_BOUNCE,
BODY_PARAM_FRICTION,
BODY_PARAM_MASS, ///< unused for static, always infinite
+ BODY_PARAM_GRAVITY_SCALE,
+ BODY_PARAM_LINEAR_DAMP,
+ BODY_PARAM_ANGULAR_DAMP,
BODY_PARAM_MAX,
};
@@ -411,7 +416,7 @@ public:
BODY_STATE_LINEAR_VELOCITY,
BODY_STATE_ANGULAR_VELOCITY,
BODY_STATE_SLEEPING,
- BODY_STATE_CAN_SLEEP
+ BODY_STATE_CAN_SLEEP
};
virtual void body_set_state(RID p_body, BodyState p_state, const Variant& p_variant)=0;