no penetration also for central gravity ball

This commit is contained in:
Antonio Carzaniga 2022-12-27 18:26:03 +01:00
parent db219a255a
commit 5a6fea0522

View File

@ -91,6 +91,11 @@ void gravity_collisions (ball * begin, ball * end) {
double d2 = vec2d::dot(b_c, b_c); double d2 = vec2d::dot(b_c, b_c);
double r = b->radius + g_r; double r = b->radius + g_r;
if (d2 <= r*r) { if (d2 <= r*r) {
double d = sqrt(d2);
if (d <= b->radius)
b->position = vec2d{width/2.0,height/2.0+r};
else
b->position += (r - d)/d*b_c;
double f = vec2d::dot(b->velocity, b_c); double f = vec2d::dot(b->velocity, b_c);
if (f < 0) { if (f < 0) {
f /= d2; f /= d2;