JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
proper moving-away detection in bounce()?
authorJoshua Grams <josh@qualdan.com>
Sat, 25 Mar 2006 21:16:48 +0000 (21:16 +0000)
committerJoshua Grams <josh@qualdan.com>
Sat, 25 Mar 2006 21:16:48 +0000 (21:16 +0000)
sprite.c

index e63fd68..1a35a6a 100644 (file)
--- a/sprite.c
+++ b/sprite.c
@@ -349,8 +349,9 @@ bounce(Sprite *a, Sprite *b)
        n = sqrt(x*x + y*y); x /= n; y /= n;
 
        // velocities along (x, y), or 0 if already moving away.
-       va = max(x*a->dx + y*a->dy, 0);
-       vb = min(x*b->dx + y*b->dy, 0);
+       va = x*a->dx + y*a->dy;
+       vb = x*b->dx + y*b->dy;
+       if(vb-va > 0) return;
 
        ma = sprite_mass(a); mb = sprite_mass(b);
        vc = (va*ma + vb*mb) / (ma+mb);