summaryrefslogtreecommitdiff
path: root/servers/physics_2d
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2014-04-05 12:39:30 -0300
committerJuan Linietsky <reduzio@gmail.com>2014-04-05 12:39:30 -0300
commit9f33134c93ecbadda70e8eefc50563e29b2eb7f2 (patch)
tree299ded94fe74a61bf8094935d0f3283f6f30e435 /servers/physics_2d
parent35b84d2c85fd152bee05d7d5a05e20a5f602a285 (diff)
-Support for changing fonts
-Detect when free() might crash the project and throw error -fixed 2D Bounce in physics (3d still broken) -renamed “on_top” property to “behind_parent”, which makes more sense, old on_top remains there for compatibility but is invisible. -large amount of fixes
Diffstat (limited to 'servers/physics_2d')
-rw-r--r--servers/physics_2d/body_pair_2d_sw.cpp15
-rw-r--r--servers/physics_2d/body_pair_2d_sw.h2
2 files changed, 15 insertions, 2 deletions
diff --git a/servers/physics_2d/body_pair_2d_sw.cpp b/servers/physics_2d/body_pair_2d_sw.cpp
index 931125a1c0..669240b8da 100644
--- a/servers/physics_2d/body_pair_2d_sw.cpp
+++ b/servers/physics_2d/body_pair_2d_sw.cpp
@@ -375,6 +375,18 @@ bool BodyPair2DSW::setup(float p_step) {
}
#endif
+
+
+ c.bounce=MAX(A->get_bounce(),B->get_bounce());
+ if (c.bounce) {
+
+ Vector2 crA( -A->get_angular_velocity() * c.rA.y, A->get_angular_velocity() * c.rA.x );
+ Vector2 crB( -B->get_angular_velocity() * c.rB.y, B->get_angular_velocity() * c.rB.x );
+ Vector2 dv = B->get_linear_velocity() + crB - A->get_linear_velocity() - crA;
+ c.bounce = c.bounce * dv.dot(c.normal);
+ }
+
+
}
return true;
@@ -420,8 +432,7 @@ void BodyPair2DSW::solve(float p_step) {
A->apply_bias_impulse(c.rA,-jb);
B->apply_bias_impulse(c.rB, jb);
- real_t bounce=MAX(A->get_bounce(),B->get_bounce());
- real_t jn = -(bounce + vn)*c.mass_normal;
+ real_t jn = -(c.bounce + vn)*c.mass_normal;
real_t jnOld = c.acc_normal_impulse;
c.acc_normal_impulse = MAX(jnOld + jn, 0.0f);
diff --git a/servers/physics_2d/body_pair_2d_sw.h b/servers/physics_2d/body_pair_2d_sw.h
index ebe26776ed..15d7e62d3a 100644
--- a/servers/physics_2d/body_pair_2d_sw.h
+++ b/servers/physics_2d/body_pair_2d_sw.h
@@ -66,6 +66,8 @@ class BodyPair2DSW : public Constraint2DSW {
bool active;
Vector2 rA,rB;
bool reused;
+ float bounce;
+
};
Vector2 offset_B; //use local A coordinates to avoid numerical issues on collision detection