Changes to 2D physics engine

-=-=-=-=-=-=-=-=-=-=-=-=-=-=

-Removed "density" property
-Added instead more flexible "angular damp" and "linear damp"
-Added ability to override angular and linear damp in rigidbody
-Added gravity scale option rigidbody

Test well and iron out bugs, when it works the same will be moved to 3D
This commit is contained in:
Juan Linietsky 2015-01-05 18:37:12 -03:00
parent 1ff0d5c4e5
commit b51f645711
13 changed files with 188 additions and 42 deletions

View file

@ -39,20 +39,24 @@ void Physics2DDirectBodyState::integrate_forces() {
real_t av = get_angular_velocity();
float damp = 1.0 - step * get_total_density();
float damp = 1.0 - step * get_total_linear_damp();
if (damp<0) // reached zero in the given time
damp=0;
lv*=damp;
damp = 1.0 - step * get_total_angular_damp();
if (damp<0) // reached zero in the given time
damp=0;
av*=damp;
set_linear_velocity(lv);
set_angular_velocity(av);
}
Object* Physics2DDirectBodyState::get_contact_collider_object(int p_contact_idx) const {
@ -70,7 +74,8 @@ Physics2DServer * Physics2DServer::get_singleton() {
void Physics2DDirectBodyState::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_total_gravity"),&Physics2DDirectBodyState::get_total_gravity);
ObjectTypeDB::bind_method(_MD("get_total_density"),&Physics2DDirectBodyState::get_total_density);
ObjectTypeDB::bind_method(_MD("get_total_linear_damp"),&Physics2DDirectBodyState::get_total_linear_damp);
ObjectTypeDB::bind_method(_MD("get_total_angular_damp"),&Physics2DDirectBodyState::get_total_angular_damp);
ObjectTypeDB::bind_method(_MD("get_inverse_mass"),&Physics2DDirectBodyState::get_inverse_mass);
ObjectTypeDB::bind_method(_MD("get_inverse_inertia"),&Physics2DDirectBodyState::get_inverse_inertia);
@ -538,7 +543,8 @@ void Physics2DServer::_bind_methods() {
BIND_CONSTANT( AREA_PARAM_GRAVITY_VECTOR );
BIND_CONSTANT( AREA_PARAM_GRAVITY_IS_POINT );
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 );
@ -553,6 +559,9 @@ void Physics2DServer::_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_LINEAR_DAMP);
BIND_CONSTANT( BODY_PARAM_ANGULAR_DAMP);
BIND_CONSTANT( BODY_PARAM_MAX );
BIND_CONSTANT( BODY_STATE_TRANSFORM );