Added gravity scale, and linear/angular damp override to 3D physics.
This commit is contained in:
parent
cb6839c5c1
commit
2d8866574d
|
@ -83,15 +83,25 @@ real_t Area::get_gravity() const{
|
||||||
|
|
||||||
return gravity;
|
return gravity;
|
||||||
}
|
}
|
||||||
|
void Area::set_linear_damp(real_t p_linear_damp){
|
||||||
|
|
||||||
void Area::set_density(real_t p_density){
|
linear_damp=p_linear_damp;
|
||||||
|
PhysicsServer::get_singleton()->area_set_param(get_rid(),PhysicsServer::AREA_PARAM_LINEAR_DAMP,p_linear_damp);
|
||||||
density=p_density;
|
|
||||||
PhysicsServer::get_singleton()->area_set_param(get_rid(),PhysicsServer::AREA_PARAM_DENSITY,p_density);
|
|
||||||
}
|
}
|
||||||
real_t Area::get_density() const{
|
real_t Area::get_linear_damp() const{
|
||||||
|
|
||||||
return density;
|
return linear_damp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Area::set_angular_damp(real_t p_angular_damp){
|
||||||
|
|
||||||
|
angular_damp=p_angular_damp;
|
||||||
|
PhysicsServer::get_singleton()->area_set_param(get_rid(),PhysicsServer::AREA_PARAM_ANGULAR_DAMP,p_angular_damp);
|
||||||
|
}
|
||||||
|
|
||||||
|
real_t Area::get_angular_damp() const{
|
||||||
|
|
||||||
|
return angular_damp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Area::set_priority(real_t p_priority){
|
void Area::set_priority(real_t p_priority){
|
||||||
|
@ -533,8 +543,11 @@ void Area::_bind_methods() {
|
||||||
ObjectTypeDB::bind_method(_MD("set_gravity","gravity"),&Area::set_gravity);
|
ObjectTypeDB::bind_method(_MD("set_gravity","gravity"),&Area::set_gravity);
|
||||||
ObjectTypeDB::bind_method(_MD("get_gravity"),&Area::get_gravity);
|
ObjectTypeDB::bind_method(_MD("get_gravity"),&Area::get_gravity);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("set_density","density"),&Area::set_density);
|
ObjectTypeDB::bind_method(_MD("set_angular_damp","angular_damp"),&Area::set_angular_damp);
|
||||||
ObjectTypeDB::bind_method(_MD("get_density"),&Area::get_density);
|
ObjectTypeDB::bind_method(_MD("get_angular_damp"),&Area::get_angular_damp);
|
||||||
|
|
||||||
|
ObjectTypeDB::bind_method(_MD("set_linear_damp","linear_damp"),&Area::set_linear_damp);
|
||||||
|
ObjectTypeDB::bind_method(_MD("get_linear_damp"),&Area::get_linear_damp);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("set_priority","priority"),&Area::set_priority);
|
ObjectTypeDB::bind_method(_MD("set_priority","priority"),&Area::set_priority);
|
||||||
ObjectTypeDB::bind_method(_MD("get_priority"),&Area::get_priority);
|
ObjectTypeDB::bind_method(_MD("get_priority"),&Area::get_priority);
|
||||||
|
@ -571,7 +584,8 @@ void Area::_bind_methods() {
|
||||||
ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity_distance_scale", PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_gravity_distance_scale"),_SCS("get_gravity_distance_scale"));
|
ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity_distance_scale", PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_gravity_distance_scale"),_SCS("get_gravity_distance_scale"));
|
||||||
ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"gravity_vec"),_SCS("set_gravity_vector"),_SCS("get_gravity_vector"));
|
ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"gravity_vec"),_SCS("set_gravity_vector"),_SCS("get_gravity_vector"));
|
||||||
ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity",PROPERTY_HINT_RANGE,"-1024,1024,0.01"),_SCS("set_gravity"),_SCS("get_gravity"));
|
ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity",PROPERTY_HINT_RANGE,"-1024,1024,0.01"),_SCS("set_gravity"),_SCS("get_gravity"));
|
||||||
ADD_PROPERTY( PropertyInfo(Variant::REAL,"density",PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_density"),_SCS("get_density"));
|
ADD_PROPERTY( PropertyInfo(Variant::REAL,"linear_damp",PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_linear_damp"),_SCS("get_linear_damp"));
|
||||||
|
ADD_PROPERTY( PropertyInfo(Variant::REAL,"angular_damp",PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_angular_damp"),_SCS("get_angular_damp"));
|
||||||
ADD_PROPERTY( PropertyInfo(Variant::INT,"priority",PROPERTY_HINT_RANGE,"0,128,1"),_SCS("set_priority"),_SCS("get_priority"));
|
ADD_PROPERTY( PropertyInfo(Variant::INT,"priority",PROPERTY_HINT_RANGE,"0,128,1"),_SCS("set_priority"),_SCS("get_priority"));
|
||||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"monitoring"),_SCS("set_enable_monitoring"),_SCS("is_monitoring_enabled"));
|
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"monitoring"),_SCS("set_enable_monitoring"),_SCS("is_monitoring_enabled"));
|
||||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"monitorable"),_SCS("set_monitorable"),_SCS("is_monitorable"));
|
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"monitorable"),_SCS("set_monitorable"),_SCS("is_monitorable"));
|
||||||
|
@ -586,7 +600,8 @@ Area::Area() : CollisionObject(PhysicsServer::get_singleton()->area_create(),tru
|
||||||
set_gravity_vector(Vector3(0,-1,0));
|
set_gravity_vector(Vector3(0,-1,0));
|
||||||
gravity_is_point=false;
|
gravity_is_point=false;
|
||||||
gravity_distance_scale=0;
|
gravity_distance_scale=0;
|
||||||
density=0.1;
|
linear_damp=0.1;
|
||||||
|
angular_damp=1;
|
||||||
priority=0;
|
priority=0;
|
||||||
monitoring=false;
|
monitoring=false;
|
||||||
set_ray_pickable(false);
|
set_ray_pickable(false);
|
||||||
|
|
|
@ -50,7 +50,8 @@ private:
|
||||||
real_t gravity;
|
real_t gravity;
|
||||||
bool gravity_is_point;
|
bool gravity_is_point;
|
||||||
real_t gravity_distance_scale;
|
real_t gravity_distance_scale;
|
||||||
real_t density;
|
real_t angular_damp;
|
||||||
|
real_t linear_damp;
|
||||||
int priority;
|
int priority;
|
||||||
bool monitoring;
|
bool monitoring;
|
||||||
bool monitorable;
|
bool monitorable;
|
||||||
|
@ -139,8 +140,11 @@ public:
|
||||||
void set_gravity(real_t p_gravity);
|
void set_gravity(real_t p_gravity);
|
||||||
real_t get_gravity() const;
|
real_t get_gravity() const;
|
||||||
|
|
||||||
void set_density(real_t p_density);
|
void set_angular_damp(real_t p_angular_damp);
|
||||||
real_t get_density() const;
|
real_t get_angular_damp() const;
|
||||||
|
|
||||||
|
void set_linear_damp(real_t p_linear_damp);
|
||||||
|
real_t get_linear_damp() const;
|
||||||
|
|
||||||
void set_priority(real_t p_priority);
|
void set_priority(real_t p_priority);
|
||||||
real_t get_priority() const;
|
real_t get_priority() const;
|
||||||
|
|
|
@ -133,6 +133,8 @@ real_t StaticBody::get_bounce() const{
|
||||||
return bounce;
|
return bounce;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void StaticBody::set_constant_linear_velocity(const Vector3& p_vel) {
|
void StaticBody::set_constant_linear_velocity(const Vector3& p_vel) {
|
||||||
|
|
||||||
constant_linear_velocity=p_vel;
|
constant_linear_velocity=p_vel;
|
||||||
|
@ -494,6 +496,42 @@ real_t RigidBody::get_bounce() const{
|
||||||
return bounce;
|
return bounce;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void RigidBody::set_gravity_scale(real_t p_gravity_scale){
|
||||||
|
|
||||||
|
gravity_scale=p_gravity_scale;
|
||||||
|
PhysicsServer::get_singleton()->body_set_param(get_rid(),PhysicsServer::BODY_PARAM_GRAVITY_SCALE,gravity_scale);
|
||||||
|
|
||||||
|
}
|
||||||
|
real_t RigidBody::get_gravity_scale() const{
|
||||||
|
|
||||||
|
return gravity_scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RigidBody::set_linear_damp(real_t p_linear_damp){
|
||||||
|
|
||||||
|
ERR_FAIL_COND(p_linear_damp<-1);
|
||||||
|
linear_damp=p_linear_damp;
|
||||||
|
PhysicsServer::get_singleton()->body_set_param(get_rid(),PhysicsServer::BODY_PARAM_LINEAR_DAMP,linear_damp);
|
||||||
|
|
||||||
|
}
|
||||||
|
real_t RigidBody::get_linear_damp() const{
|
||||||
|
|
||||||
|
return linear_damp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RigidBody::set_angular_damp(real_t p_angular_damp){
|
||||||
|
|
||||||
|
ERR_FAIL_COND(p_angular_damp<-1);
|
||||||
|
angular_damp=p_angular_damp;
|
||||||
|
PhysicsServer::get_singleton()->body_set_param(get_rid(),PhysicsServer::BODY_PARAM_ANGULAR_DAMP,angular_damp);
|
||||||
|
|
||||||
|
}
|
||||||
|
real_t RigidBody::get_angular_damp() const{
|
||||||
|
|
||||||
|
return angular_damp;
|
||||||
|
}
|
||||||
|
|
||||||
void RigidBody::set_axis_velocity(const Vector3& p_axis) {
|
void RigidBody::set_axis_velocity(const Vector3& p_axis) {
|
||||||
|
|
||||||
Vector3 v = state? state->get_linear_velocity() : linear_velocity;
|
Vector3 v = state? state->get_linear_velocity() : linear_velocity;
|
||||||
|
@ -685,6 +723,16 @@ void RigidBody::_bind_methods() {
|
||||||
ObjectTypeDB::bind_method(_MD("set_angular_velocity","angular_velocity"),&RigidBody::set_angular_velocity);
|
ObjectTypeDB::bind_method(_MD("set_angular_velocity","angular_velocity"),&RigidBody::set_angular_velocity);
|
||||||
ObjectTypeDB::bind_method(_MD("get_angular_velocity"),&RigidBody::get_angular_velocity);
|
ObjectTypeDB::bind_method(_MD("get_angular_velocity"),&RigidBody::get_angular_velocity);
|
||||||
|
|
||||||
|
ObjectTypeDB::bind_method(_MD("set_gravity_scale","gravity_scale"),&RigidBody::set_gravity_scale);
|
||||||
|
ObjectTypeDB::bind_method(_MD("get_gravity_scale"),&RigidBody::get_gravity_scale);
|
||||||
|
|
||||||
|
ObjectTypeDB::bind_method(_MD("set_linear_damp","linear_damp"),&RigidBody::set_linear_damp);
|
||||||
|
ObjectTypeDB::bind_method(_MD("get_linear_damp"),&RigidBody::get_linear_damp);
|
||||||
|
|
||||||
|
ObjectTypeDB::bind_method(_MD("set_angular_damp","angular_damp"),&RigidBody::set_angular_damp);
|
||||||
|
ObjectTypeDB::bind_method(_MD("get_angular_damp"),&RigidBody::get_angular_damp);
|
||||||
|
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("set_max_contacts_reported","amount"),&RigidBody::set_max_contacts_reported);
|
ObjectTypeDB::bind_method(_MD("set_max_contacts_reported","amount"),&RigidBody::set_max_contacts_reported);
|
||||||
ObjectTypeDB::bind_method(_MD("get_max_contacts_reported"),&RigidBody::get_max_contacts_reported);
|
ObjectTypeDB::bind_method(_MD("get_max_contacts_reported"),&RigidBody::get_max_contacts_reported);
|
||||||
|
|
||||||
|
@ -722,6 +770,7 @@ void RigidBody::_bind_methods() {
|
||||||
ADD_PROPERTY( PropertyInfo(Variant::REAL,"weight",PROPERTY_HINT_EXP_RANGE,"0.01,65535,0.01",PROPERTY_USAGE_EDITOR),_SCS("set_weight"),_SCS("get_weight"));
|
ADD_PROPERTY( PropertyInfo(Variant::REAL,"weight",PROPERTY_HINT_EXP_RANGE,"0.01,65535,0.01",PROPERTY_USAGE_EDITOR),_SCS("set_weight"),_SCS("get_weight"));
|
||||||
ADD_PROPERTY( PropertyInfo(Variant::REAL,"friction",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_friction"),_SCS("get_friction"));
|
ADD_PROPERTY( PropertyInfo(Variant::REAL,"friction",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_friction"),_SCS("get_friction"));
|
||||||
ADD_PROPERTY( PropertyInfo(Variant::REAL,"bounce",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_bounce"),_SCS("get_bounce"));
|
ADD_PROPERTY( PropertyInfo(Variant::REAL,"bounce",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_bounce"),_SCS("get_bounce"));
|
||||||
|
ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity_scale",PROPERTY_HINT_RANGE,"-128,128,0.01"),_SCS("set_gravity_scale"),_SCS("get_gravity_scale"));
|
||||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"custom_integrator"),_SCS("set_use_custom_integrator"),_SCS("is_using_custom_integrator"));
|
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"custom_integrator"),_SCS("set_use_custom_integrator"),_SCS("is_using_custom_integrator"));
|
||||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"continuous_cd"),_SCS("set_use_continuous_collision_detection"),_SCS("is_using_continuous_collision_detection"));
|
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"continuous_cd"),_SCS("set_use_continuous_collision_detection"),_SCS("is_using_continuous_collision_detection"));
|
||||||
ADD_PROPERTY( PropertyInfo(Variant::INT,"contacts_reported"),_SCS("set_max_contacts_reported"),_SCS("get_max_contacts_reported"));
|
ADD_PROPERTY( PropertyInfo(Variant::INT,"contacts_reported"),_SCS("set_max_contacts_reported"),_SCS("get_max_contacts_reported"));
|
||||||
|
@ -731,6 +780,8 @@ void RigidBody::_bind_methods() {
|
||||||
ADD_PROPERTY( PropertyInfo(Variant::INT,"axis_lock",PROPERTY_HINT_ENUM,"Disabled,Lock X,Lock Y,Lock Z"),_SCS("set_axis_lock"),_SCS("get_axis_lock"));
|
ADD_PROPERTY( PropertyInfo(Variant::INT,"axis_lock",PROPERTY_HINT_ENUM,"Disabled,Lock X,Lock Y,Lock Z"),_SCS("set_axis_lock"),_SCS("get_axis_lock"));
|
||||||
ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"velocity/linear"),_SCS("set_linear_velocity"),_SCS("get_linear_velocity"));
|
ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"velocity/linear"),_SCS("set_linear_velocity"),_SCS("get_linear_velocity"));
|
||||||
ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"velocity/angular"),_SCS("set_angular_velocity"),_SCS("get_angular_velocity"));
|
ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"velocity/angular"),_SCS("set_angular_velocity"),_SCS("get_angular_velocity"));
|
||||||
|
ADD_PROPERTY( PropertyInfo(Variant::REAL,"damp_override/linear",PROPERTY_HINT_RANGE,"-1,128,0.01"),_SCS("set_linear_damp"),_SCS("get_linear_damp"));
|
||||||
|
ADD_PROPERTY( PropertyInfo(Variant::REAL,"damp_override/angular",PROPERTY_HINT_RANGE,"-1,128,0.01"),_SCS("set_angular_damp"),_SCS("get_angular_damp"));
|
||||||
|
|
||||||
ADD_SIGNAL( MethodInfo("body_enter_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"local_shape")));
|
ADD_SIGNAL( MethodInfo("body_enter_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"local_shape")));
|
||||||
ADD_SIGNAL( MethodInfo("body_exit_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"local_shape")));
|
ADD_SIGNAL( MethodInfo("body_exit_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"local_shape")));
|
||||||
|
@ -753,6 +804,10 @@ RigidBody::RigidBody() : PhysicsBody(PhysicsServer::BODY_MODE_RIGID) {
|
||||||
max_contacts_reported=0;
|
max_contacts_reported=0;
|
||||||
state=NULL;
|
state=NULL;
|
||||||
|
|
||||||
|
gravity_scale=1;
|
||||||
|
linear_damp=-1;
|
||||||
|
angular_damp=-1;
|
||||||
|
|
||||||
//angular_velocity=0;
|
//angular_velocity=0;
|
||||||
sleeping=false;
|
sleeping=false;
|
||||||
ccd=false;
|
ccd=false;
|
||||||
|
|
|
@ -129,6 +129,10 @@ private:
|
||||||
|
|
||||||
Vector3 linear_velocity;
|
Vector3 linear_velocity;
|
||||||
Vector3 angular_velocity;
|
Vector3 angular_velocity;
|
||||||
|
real_t gravity_scale;
|
||||||
|
real_t linear_damp;
|
||||||
|
real_t angular_damp;
|
||||||
|
|
||||||
bool sleeping;
|
bool sleeping;
|
||||||
bool ccd;
|
bool ccd;
|
||||||
|
|
||||||
|
@ -217,6 +221,16 @@ public:
|
||||||
void set_angular_velocity(const Vector3&p_velocity);
|
void set_angular_velocity(const Vector3&p_velocity);
|
||||||
Vector3 get_angular_velocity() const;
|
Vector3 get_angular_velocity() const;
|
||||||
|
|
||||||
|
void set_gravity_scale(real_t p_gravity_scale);
|
||||||
|
real_t get_gravity_scale() const;
|
||||||
|
|
||||||
|
void set_linear_damp(real_t p_linear_damp);
|
||||||
|
real_t get_linear_damp() const;
|
||||||
|
|
||||||
|
void set_angular_damp(real_t p_angular_damp);
|
||||||
|
real_t get_angular_damp() const;
|
||||||
|
|
||||||
|
|
||||||
void set_use_custom_integrator(bool p_enable);
|
void set_use_custom_integrator(bool p_enable);
|
||||||
bool is_using_custom_integrator();
|
bool is_using_custom_integrator();
|
||||||
|
|
||||||
|
|
|
@ -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_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_DISTANCE_SCALE: gravity_distance_scale=p_value; ; break;
|
||||||
case PhysicsServer::AREA_PARAM_GRAVITY_POINT_ATTENUATION: point_attenuation=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;
|
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_IS_POINT: return gravity_is_point;
|
||||||
case PhysicsServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE: return gravity_distance_scale;
|
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_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;
|
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_is_point=false;
|
||||||
gravity_distance_scale=0;
|
gravity_distance_scale=0;
|
||||||
point_attenuation=1;
|
point_attenuation=1;
|
||||||
density=0.1;
|
angular_damp=1.0;
|
||||||
|
linear_damp=0.1;
|
||||||
priority=0;
|
priority=0;
|
||||||
set_ray_pickable(false);
|
set_ray_pickable(false);
|
||||||
monitor_callback_id=0;
|
monitor_callback_id=0;
|
||||||
|
|
|
@ -47,7 +47,8 @@ class AreaSW : public CollisionObjectSW{
|
||||||
bool gravity_is_point;
|
bool gravity_is_point;
|
||||||
float gravity_distance_scale;
|
float gravity_distance_scale;
|
||||||
float point_attenuation;
|
float point_attenuation;
|
||||||
float density;
|
float linear_damp;
|
||||||
|
float angular_damp;
|
||||||
int priority;
|
int priority;
|
||||||
bool monitorable;
|
bool monitorable;
|
||||||
|
|
||||||
|
@ -145,8 +146,11 @@ public:
|
||||||
_FORCE_INLINE_ void set_point_attenuation(float p_point_attenuation) { point_attenuation=p_point_attenuation; }
|
_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_ float get_point_attenuation() const { return point_attenuation; }
|
||||||
|
|
||||||
_FORCE_INLINE_ void set_density(float p_density) { density=p_density; }
|
_FORCE_INLINE_ void set_linear_damp(float p_linear_damp) { linear_damp=p_linear_damp; }
|
||||||
_FORCE_INLINE_ float get_density() const { return density; }
|
_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_ void set_priority(int p_priority) { priority=p_priority; }
|
||||||
_FORCE_INLINE_ int get_priority() const { return priority; }
|
_FORCE_INLINE_ int get_priority() const { return priority; }
|
||||||
|
|
|
@ -159,6 +159,17 @@ void BodySW::set_param(PhysicsServer::BodyParameter p_param, float p_value) {
|
||||||
_update_inertia();
|
_update_inertia();
|
||||||
|
|
||||||
} break;
|
} 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:{}
|
default:{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,6 +188,18 @@ float BodySW::get_param(PhysicsServer::BodyParameter p_param) const {
|
||||||
case PhysicsServer::BODY_PARAM_MASS: {
|
case PhysicsServer::BODY_PARAM_MASS: {
|
||||||
return mass;
|
return mass;
|
||||||
} break;
|
} 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:{}
|
default:{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,6 +403,8 @@ void BodySW::integrate_forces(real_t p_step) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AreaSW *def_area = get_space()->get_default_area();
|
AreaSW *def_area = get_space()->get_default_area();
|
||||||
|
AreaSW *damp_area = def_area;
|
||||||
|
|
||||||
ERR_FAIL_COND(!def_area);
|
ERR_FAIL_COND(!def_area);
|
||||||
|
|
||||||
int ac = areas.size();
|
int ac = areas.size();
|
||||||
|
@ -388,7 +413,7 @@ void BodySW::integrate_forces(real_t p_step) {
|
||||||
if (ac) {
|
if (ac) {
|
||||||
areas.sort();
|
areas.sort();
|
||||||
const AreaCMP *aa = &areas[0];
|
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--) {
|
for(int i=ac-1;i>=0;i--) {
|
||||||
_compute_area_gravity(aa[i].area);
|
_compute_area_gravity(aa[i].area);
|
||||||
if (aa[i].area->get_space_override_mode() == PhysicsServer::AREA_SPACE_OVERRIDE_REPLACE) {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
density=def_area->get_density();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !replace ) {
|
if( !replace ) {
|
||||||
_compute_area_gravity(def_area);
|
_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;
|
Vector3 motion;
|
||||||
bool do_motion=false;
|
bool do_motion=false;
|
||||||
|
|
||||||
|
@ -431,12 +468,12 @@ void BodySW::integrate_forces(real_t p_step) {
|
||||||
force+=applied_force;
|
force+=applied_force;
|
||||||
Vector3 torque=applied_torque;
|
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
|
if (damp<0) // reached zero in the given time
|
||||||
damp=0;
|
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
|
if (angular_damp<0) // reached zero in the given time
|
||||||
angular_damp=0;
|
angular_damp=0;
|
||||||
|
@ -695,8 +732,12 @@ BodySW::BodySW() : CollisionObjectSW(TYPE_BODY), active_list(this), inertia_upda
|
||||||
island_list_next=NULL;
|
island_list_next=NULL;
|
||||||
first_time_kinematic=false;
|
first_time_kinematic=false;
|
||||||
_set_static(false);
|
_set_static(false);
|
||||||
density=0;
|
|
||||||
contact_count=0;
|
contact_count=0;
|
||||||
|
gravity_scale=1.0;
|
||||||
|
|
||||||
|
area_angular_damp=0;
|
||||||
|
area_linear_damp=0;
|
||||||
|
|
||||||
still_time=0;
|
still_time=0;
|
||||||
continuous_cd=false;
|
continuous_cd=false;
|
||||||
|
|
|
@ -50,6 +50,10 @@ class BodySW : public CollisionObjectSW {
|
||||||
real_t bounce;
|
real_t bounce;
|
||||||
real_t friction;
|
real_t friction;
|
||||||
|
|
||||||
|
real_t linear_damp;
|
||||||
|
real_t angular_damp;
|
||||||
|
real_t gravity_scale;
|
||||||
|
|
||||||
PhysicsServer::BodyAxisLock axis_lock;
|
PhysicsServer::BodyAxisLock axis_lock;
|
||||||
|
|
||||||
real_t _inv_mass;
|
real_t _inv_mass;
|
||||||
|
@ -57,13 +61,16 @@ class BodySW : public CollisionObjectSW {
|
||||||
Matrix3 _inv_inertia_tensor;
|
Matrix3 _inv_inertia_tensor;
|
||||||
|
|
||||||
Vector3 gravity;
|
Vector3 gravity;
|
||||||
real_t density;
|
|
||||||
|
|
||||||
real_t still_time;
|
real_t still_time;
|
||||||
|
|
||||||
Vector3 applied_force;
|
Vector3 applied_force;
|
||||||
Vector3 applied_torque;
|
Vector3 applied_torque;
|
||||||
|
|
||||||
|
float area_angular_damp;
|
||||||
|
float area_linear_damp;
|
||||||
|
|
||||||
|
|
||||||
SelfList<BodySW> active_list;
|
SelfList<BodySW> active_list;
|
||||||
SelfList<BodySW> inertia_update_list;
|
SelfList<BodySW> inertia_update_list;
|
||||||
SelfList<BodySW> direct_state_query_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_ Matrix3 get_inv_inertia_tensor() const { return _inv_inertia_tensor; }
|
||||||
_FORCE_INLINE_ real_t get_friction() const { return friction; }
|
_FORCE_INLINE_ real_t get_friction() const { return friction; }
|
||||||
_FORCE_INLINE_ Vector3 get_gravity() const { return gravity; }
|
_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_ real_t get_bounce() const { return bounce; }
|
||||||
|
|
||||||
_FORCE_INLINE_ void set_axis_lock(PhysicsServer::BodyAxisLock p_lock) { axis_lock=p_lock; }
|
_FORCE_INLINE_ void set_axis_lock(PhysicsServer::BodyAxisLock p_lock) { axis_lock=p_lock; }
|
||||||
|
@ -335,8 +341,9 @@ public:
|
||||||
BodySW *body;
|
BodySW *body;
|
||||||
real_t step;
|
real_t step;
|
||||||
|
|
||||||
virtual Vector3 get_total_gravity() const { return body->get_gravity(); } // get gravity vector working on 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_density() const { return body->get_density(); } // get density of 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 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
|
virtual Vector3 get_inverse_inertia() const { return body->get_inv_inertia(); } // get density of this body space
|
||||||
|
|
|
@ -337,9 +337,9 @@ public:
|
||||||
Body2DSW *body;
|
Body2DSW *body;
|
||||||
real_t step;
|
real_t step;
|
||||||
|
|
||||||
virtual Vector2 get_total_gravity() const { return body->get_gravity(); } // get gravity vector working on 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->get_angular_damp(); } // get density of 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->get_linear_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 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
|
virtual real_t get_inverse_inertia() const { return body->get_inv_inertia(); } // get density of this body space
|
||||||
|
|
|
@ -39,13 +39,18 @@ void PhysicsDirectBodyState::integrate_forces() {
|
||||||
|
|
||||||
Vector3 av = get_angular_velocity();
|
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
|
if (linear_damp<0) // reached zero in the given time
|
||||||
damp=0;
|
linear_damp=0;
|
||||||
|
|
||||||
lv*=damp;
|
float angular_damp = 1.0 - step * get_total_angular_damp();
|
||||||
av*=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_linear_velocity(lv);
|
||||||
set_angular_velocity(av);
|
set_angular_velocity(av);
|
||||||
|
@ -70,7 +75,8 @@ PhysicsServer * PhysicsServer::get_singleton() {
|
||||||
void PhysicsDirectBodyState::_bind_methods() {
|
void PhysicsDirectBodyState::_bind_methods() {
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("get_total_gravity"),&PhysicsDirectBodyState::get_total_gravity);
|
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_mass"),&PhysicsDirectBodyState::get_inverse_mass);
|
||||||
ObjectTypeDB::bind_method(_MD("get_inverse_inertia"),&PhysicsDirectBodyState::get_inverse_inertia);
|
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_IS_POINT );
|
||||||
BIND_CONSTANT( AREA_PARAM_GRAVITY_DISTANCE_SCALE );
|
BIND_CONSTANT( AREA_PARAM_GRAVITY_DISTANCE_SCALE );
|
||||||
BIND_CONSTANT( AREA_PARAM_GRAVITY_POINT_ATTENUATION );
|
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_PARAM_PRIORITY );
|
||||||
|
|
||||||
BIND_CONSTANT( AREA_SPACE_OVERRIDE_COMBINE );
|
BIND_CONSTANT( AREA_SPACE_OVERRIDE_COMBINE );
|
||||||
|
@ -698,6 +705,9 @@ void PhysicsServer::_bind_methods() {
|
||||||
BIND_CONSTANT( BODY_PARAM_BOUNCE );
|
BIND_CONSTANT( BODY_PARAM_BOUNCE );
|
||||||
BIND_CONSTANT( BODY_PARAM_FRICTION );
|
BIND_CONSTANT( BODY_PARAM_FRICTION );
|
||||||
BIND_CONSTANT( BODY_PARAM_MASS );
|
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_PARAM_MAX );
|
||||||
|
|
||||||
BIND_CONSTANT( BODY_STATE_TRANSFORM );
|
BIND_CONSTANT( BODY_STATE_TRANSFORM );
|
||||||
|
|
|
@ -41,8 +41,9 @@ protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual Vector3 get_total_gravity() const=0; // get gravity vector working on this body space/area
|
virtual Vector3 get_total_gravity() const=0;
|
||||||
virtual float get_total_density() const=0; // get density of this body space/area
|
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 float get_inverse_mass() const=0; // get the mass
|
||||||
virtual Vector3 get_inverse_inertia() const=0; // get density of this body space
|
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_IS_POINT,
|
||||||
AREA_PARAM_GRAVITY_DISTANCE_SCALE,
|
AREA_PARAM_GRAVITY_DISTANCE_SCALE,
|
||||||
AREA_PARAM_GRAVITY_POINT_ATTENUATION,
|
AREA_PARAM_GRAVITY_POINT_ATTENUATION,
|
||||||
AREA_PARAM_DENSITY,
|
AREA_PARAM_LINEAR_DAMP,
|
||||||
|
AREA_PARAM_ANGULAR_DAMP,
|
||||||
AREA_PARAM_PRIORITY
|
AREA_PARAM_PRIORITY
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -398,6 +400,9 @@ public:
|
||||||
BODY_PARAM_BOUNCE,
|
BODY_PARAM_BOUNCE,
|
||||||
BODY_PARAM_FRICTION,
|
BODY_PARAM_FRICTION,
|
||||||
BODY_PARAM_MASS, ///< unused for static, always infinite
|
BODY_PARAM_MASS, ///< unused for static, always infinite
|
||||||
|
BODY_PARAM_GRAVITY_SCALE,
|
||||||
|
BODY_PARAM_LINEAR_DAMP,
|
||||||
|
BODY_PARAM_ANGULAR_DAMP,
|
||||||
BODY_PARAM_MAX,
|
BODY_PARAM_MAX,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -411,7 +416,7 @@ public:
|
||||||
BODY_STATE_LINEAR_VELOCITY,
|
BODY_STATE_LINEAR_VELOCITY,
|
||||||
BODY_STATE_ANGULAR_VELOCITY,
|
BODY_STATE_ANGULAR_VELOCITY,
|
||||||
BODY_STATE_SLEEPING,
|
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;
|
virtual void body_set_state(RID p_body, BodyState p_state, const Variant& p_variant)=0;
|
||||||
|
|
Loading…
Reference in New Issue