solved corner case issue

This commit is contained in:
Magnus Auvinen 2007-12-12 20:05:18 +00:00
parent f7ea0b2ba8
commit 7d79756443
2 changed files with 23 additions and 9 deletions

View file

@ -75,20 +75,32 @@ 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((int)new_pos.x, (int)pos.y), size))
if(test_box(vec2(new_pos.x, pos.y), size))
{
new_pos.x = pos.x;
vel.x *= -elasticity;
hits++;
}
// 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;
}
}

View file

@ -1011,7 +1011,6 @@ void player::tick_defered()
vec2 start_pos = core.pos;
vec2 start_vel = core.vel;
bool stuck_before = test_box(core.pos, vec2(28.0f, 28.0f));
core.move();
bool stuck_after_move = test_box(core.pos, vec2(28.0f, 28.0f));
core.quantize();
@ -1020,11 +1019,14 @@ void player::tick_defered()
if(!stuck_before && (stuck_after_move || stuck_after_quant))
{
dbg_msg("player", "STUCK!!! %f %f %f %f %x %x %x %x",
dbg_msg("player", "STUCK!!! %d %d %d %f %f %f %f %x %x %x %x",
stuck_before,
stuck_after_move,
stuck_after_quant,
start_pos.x, start_pos.y,
start_vel.x, start_vel.y,
start_pos.x, start_pos.y,
start_vel.x, start_vel.y);
*((unsigned *)&start_pos.x), *((unsigned *)&start_pos.y),
*((unsigned *)&start_vel.x), *((unsigned *)&start_vel.y));
}