X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcollision.hpp;h=a31878c88e8553dd808796598401d49b7005c093;hb=708a1fe72ec39e9fb35100c60e0fccc2d06a2481;hp=360f94d0abf589843dd660f951500cd2684d8d6d;hpb=02288dc76442bd6616a200a2d22c0954d2fc8180;p=supertux.git diff --git a/src/collision.hpp b/src/collision.hpp index 360f94d0a..a31878c88 100644 --- a/src/collision.hpp +++ b/src/collision.hpp @@ -1,7 +1,7 @@ // $Id$ -// +// // SuperTux -// Copyright (C) 2005 Matthias Braun +// Copyright (C) 2006 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -12,7 +12,7 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA @@ -20,29 +20,54 @@ #ifndef __COLLISION_H__ #define __COLLISION_H__ +#include +#include "collision_hit.hpp" +#include + class Vector; class Rect; class AATriangle; -class CollisionHit; -class Collision +namespace collision +{ + +class Constraints { public: - /** checks if 2 rectangle intersect each other */ - static bool intersects(const Rect& r1, const Rect& r2); - - /** does collision detection between 2 rectangles. Returns true in case of - * collision and fills in the hit structure then. - */ - static bool rectangle_rectangle(CollisionHit& hit, const Rect& r1, - const Vector& movement, const Rect& r2); - - /** does collision detection between a rectangle and an axis aligned triangle - * Returns true in case of a collision and fills in the hit structure then. - */ - static bool rectangle_aatriangle(CollisionHit& hit, const Rect& rect, - const Vector& movement, const AATriangle& triangle); + Constraints() { + float infinity = (std::numeric_limits::has_infinity ? std::numeric_limits::infinity() : std::numeric_limits::max()); + left = -infinity; + right = infinity; + top = -infinity; + bottom = infinity; + } + + bool has_constraints() const { + float infinity = (std::numeric_limits::has_infinity ? std::numeric_limits::infinity() : std::numeric_limits::max()); + return left > -infinity || right < infinity + || top > -infinity || bottom < infinity; + } + + float left; + float right; + float top; + float bottom; + Vector ground_movement; + CollisionHit hit; }; -#endif +/** checks if 2 rectangle intersect each other */ +bool intersects(const Rect& r1, const Rect& r2); + +/** does collision detection between a rectangle and an axis aligned triangle + * Returns true in case of a collision and fills in the hit structure then. + */ +bool rectangle_aatriangle(Constraints* constraints, const Rect& rect, + const AATriangle& triangle, const Vector& addl_ground_movement = Vector(0,0)); +void set_rectangle_rectangle_constraints(Constraints* constraints, + const Rect& r1, const Rect& r2, const Vector& addl_ground_movement = Vector(0,0)); + +} + +#endif