diff --git a/SpriteHandler.h b/SpriteHandler.h index 255e89a..c367fcb 100644 --- a/SpriteHandler.h +++ b/SpriteHandler.h @@ -9,6 +9,7 @@ #include "Texture.h" #include "ScreenHandler.h" #include "Drawing.h" +#include "AABB.h" #include #include @@ -29,7 +30,7 @@ class Sprite virtual ~Sprite() = default; Sprite(const std::string& a_name) : name(a_name) {} - virtual ttl::Rectangle calc_curr_AABB(int /*sim_frame*/) = 0; + virtual AABB calc_curr_AABB(int /*sim_frame*/) = 0; }; class BitmapSprite : public Sprite @@ -245,7 +246,7 @@ class BitmapSprite : public Sprite } - virtual ttl::Rectangle calc_curr_AABB(int /*sim_frame*/) override + virtual AABB calc_curr_AABB(int /*sim_frame*/) override { return { pos.r, pos.c, size.r, size.c }; } @@ -334,27 +335,18 @@ class VectorSprite : public Sprite } } - virtual ttl::Rectangle calc_curr_AABB(int sim_frame) override + virtual AABB calc_curr_AABB(int sim_frame) override { auto& vector_frame = get_curr_frame(sim_frame); - - auto rmin = math::get_max(); - auto rmax = math::get_min(); - auto cmin = math::get_max(); - auto cmax = math::get_max(); + + AABB aabb; for (const auto& line_seg : vector_frame.line_segments) { auto [p0, p1] = calc_seg_world_pos(line_seg); - math::minimize(rmin, p0.r); - math::minimize(rmin, p1.r); - math::maximize(rmax, p0.r); - math::maximize(rmax, p1.r); - math::minimize(cmin, p0.c); - math::minimize(cmin, p1.c); - math::maximize(cmax, p0.c); - math::maximize(cmax, p1.c); + aabb.add_point(p0); + aabb.add_point(p1); } - return { rmin, cmin, rmax - rmin, cmax - cmin }; + return aabb; } };