From 5d2428ee596fc95781019c5a0ce5f3c28b990575 Mon Sep 17 00:00:00 2001 From: ketmar Date: Sun, 19 Jan 2014 21:19:14 +0200 Subject: [PATCH] demo: removing bodies that fell off the platform --- src/main.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 2505f8e..082810c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -197,6 +197,17 @@ static void update (int elapsed_ms) { sdl_frame_changed = 1; // UPDATE the physics! for (int i = 0; i < 10; ++i) mWorld->update(1/600.0f); + // remove out-of-bounds bodies + for (int f = mWorld->bodyCount()-1; f > 0; --f) { + Body *b = mWorld->getBody(f); + Vector2 p = b->getDerivedPosition(); + Vector2 v = b->getDerivedVelocity(); + //fprintf(stderr, "(%f,%f); v.X=%f; v.Y=%f\n", p.X, p.Y, v.X, v.Y); + if (p.Y < -8.0f && v.Y <= 0.0f) { + // kill it with fire! + delete b; + } + } } -- 2.11.4.GIT