X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsupertux%2Fcollision.cpp;h=4e1c601d5915ba3887c55f88ab65132b4f1ed402;hb=1a9e5d95df809bbc0612357ed965fa3f11d31f64;hp=6729d05402ba522665593b524219a44c4b8b26ff;hpb=ff08b8e1983016221967a024dab76799a3d75059;p=supertux.git diff --git a/src/supertux/collision.cpp b/src/supertux/collision.cpp index 6729d0540..4e1c601d5 100644 --- a/src/supertux/collision.cpp +++ b/src/supertux/collision.cpp @@ -54,29 +54,29 @@ bool rectangle_aatriangle(Constraints* constraints, const Rectf& rect, return false; Vector normal; - float c; + float c = 0.0; Vector p1; Rectf area; switch(triangle.dir & AATriangle::DEFORM_MASK) { case 0: - area.p1 = triangle.p1; - area.p2 = triangle.p2; + area.p1 = triangle.bbox.p1; + area.p2 = triangle.bbox.p2; break; - case AATriangle::DEFORM1: - area.p1 = Vector(triangle.p1.x, triangle.p1.y + triangle.get_height()/2); - area.p2 = triangle.p2; + case AATriangle::DEFORM_BOTTOM: + area.p1 = Vector(triangle.bbox.p1.x, triangle.bbox.p1.y + triangle.bbox.get_height()/2); + area.p2 = triangle.bbox.p2; break; - case AATriangle::DEFORM2: - area.p1 = triangle.p1; - area.p2 = Vector(triangle.p2.x, triangle.p1.y + triangle.get_height()/2); + case AATriangle::DEFORM_TOP: + area.p1 = triangle.bbox.p1; + area.p2 = Vector(triangle.bbox.p2.x, triangle.bbox.p1.y + triangle.bbox.get_height()/2); break; - case AATriangle::DEFORM3: - area.p1 = triangle.p1; - area.p2 = Vector(triangle.p1.x + triangle.get_width()/2, triangle.p2.y); + case AATriangle::DEFORM_LEFT: + area.p1 = triangle.bbox.p1; + area.p2 = Vector(triangle.bbox.p1.x + triangle.bbox.get_width()/2, triangle.bbox.p2.y); break; - case AATriangle::DEFORM4: - area.p1 = Vector(triangle.p1.x + triangle.get_width()/2, triangle.p1.y); - area.p2 = triangle.p2; + case AATriangle::DEFORM_RIGHT: + area.p1 = Vector(triangle.bbox.p1.x + triangle.bbox.get_width()/2, triangle.bbox.p1.y); + area.p2 = triangle.bbox.p2; break; default: assert(false); @@ -121,21 +121,21 @@ bool rectangle_aatriangle(Constraints* constraints, const Rectf& rect, if(p1.x < area.p1.x - RDELTA || p1.x > area.p2.x + RDELTA || p1.y < area.p1.y - RDELTA || p1.y > area.p2.y + RDELTA) { set_rectangle_rectangle_constraints(constraints, rect, area); - constraints->hit.left = false; - constraints->hit.right = false; } else { if(outvec.x < 0) { - constraints->right = rect.get_right() + outvec.x; + constraints->constrain_right(rect.get_right() + outvec.x, addl_ground_movement.x); + constraints->hit.right = true; } else { - constraints->left = rect.get_left() + outvec.x; + constraints->constrain_left(rect.get_left() + outvec.x, addl_ground_movement.x); + constraints->hit.left = true; } if(outvec.y < 0) { - constraints->bottom = rect.get_bottom() + outvec.y; + constraints->constrain_bottom(rect.get_bottom() + outvec.y, addl_ground_movement.y); constraints->hit.bottom = true; constraints->ground_movement += addl_ground_movement; } else { - constraints->top = rect.get_top() + outvec.y; + constraints->constrain_top(rect.get_top() + outvec.y, addl_ground_movement.y); constraints->hit.top = true; } constraints->hit.slope_normal = normal; @@ -156,19 +156,19 @@ void set_rectangle_rectangle_constraints(Constraints* constraints, float horiz_penetration = std::min(ileft, iright); if(vert_penetration < horiz_penetration) { if(itop < ibottom) { - constraints->bottom = std::min(constraints->bottom, r2.get_top()); + constraints->constrain_bottom(r2.get_top(), addl_ground_movement.y); constraints->hit.bottom = true; constraints->ground_movement += addl_ground_movement; } else { - constraints->top = std::max(constraints->top, r2.get_bottom()); + constraints->constrain_top(r2.get_bottom(), addl_ground_movement.y); constraints->hit.top = true; } } else { if(ileft < iright) { - constraints->right = std::min(constraints->right, r2.get_left()); + constraints->constrain_right(r2.get_left(), addl_ground_movement.x); constraints->hit.right = true; } else { - constraints->left = std::max(constraints->left, r2.get_right()); + constraints->constrain_left(r2.get_right(), addl_ground_movement.x); constraints->hit.left = true; } }