From 7d7975644369e393d44950d3b0083743b39db173 Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Wed, 12 Dec 2007 20:05:18 +0000 Subject: solved corner case issue --- src/game/game.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/game/game.cpp') diff --git a/src/game/game.cpp b/src/game/game.cpp index cb00ae0e..29e4da14 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -75,18 +75,30 @@ void move_box(vec2 *inout_pos, vec2 *inout_vel, vec2 size, float elasticity) vec2 new_pos = pos + vel*fraction; // TODO: this row is not nice - // make sure that we quantize. this is to make sure that when we set - // the final position that we don't move it into the ground. - if(test_box(vec2((int)new_pos.x,(int) new_pos.y), size)) + if(test_box(vec2(new_pos.x, new_pos.y), size)) { - if(test_box(vec2((int)pos.x, (int)new_pos.y), size)) + int hits = 0; + + if(test_box(vec2(pos.x, new_pos.y), size)) { new_pos.y = pos.y; vel.y *= -elasticity; + hits++; + } + + if(test_box(vec2(new_pos.x, pos.y), size)) + { + new_pos.x = pos.x; + vel.x *= -elasticity; + hits++; } - if(test_box(vec2((int)new_pos.x, (int)pos.y), size)) + // neither of the tests got a collision. + // this is a real _corner case_! + if(hits == 0) { + new_pos.y = pos.y; + vel.y *= -elasticity; new_pos.x = pos.x; vel.x *= -elasticity; } -- cgit 1.4.1