X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fcullable.hh;fp=src%2Frectangle.cc;h=e4fe4ca7f292ee408c37f350c76a6acee31e8b9c;hp=0f9bb9f4a74c60977ae9141267886c665e160593;hb=7d15b919681bb9ec0088b4b27c6abf62d6dfb9b1;hpb=0fffd0097d7b496454413e57b398c903ecc252e4 diff --git a/src/rectangle.cc b/src/cullable.hh similarity index 55% rename from src/rectangle.cc rename to src/cullable.hh index 0f9bb9f..e4fe4ca 100644 --- a/src/rectangle.cc +++ b/src/cullable.hh @@ -26,59 +26,29 @@ *******************************************************************************/ -#include +#ifndef _CULLABLE_HH_ +#define _CULLABLE_HH_ -#include "rectangle.hh" +#include "camera.hh" namespace dc { -bool rectangle::containsRect(const rectangle& r) const -{ - point o = r.origin; - point s = r.size; - if (origin.x <= o.x && origin.y <= o.y) - { - scalar a = origin.x + size.x; - scalar b = origin.y + size.y; - scalar c = o.x + s.x; - scalar d = o.y + s.y; - return o.x <= a && o.y <= b && origin.x <= c && - origin.y <= d && c <= a && d <= b; - } - return false; -} +/** + * Interface for anything that can be culled given a camera's frustrum. + */ -bool rectangle::intersectsRect(const rectangle& r) const +class cullable { - // TODO - Perhaps this could be optimized if it proves to be a bottleneck. - rectangle rect = intersectionWith(r); - return rect.isValid(); -} +public: + virtual bool isVisible(const camera& cam) = 0; +}; -rectangle rectangle::unionWith(const rectangle& r) const -{ - point o = r.origin; - point s = r.size; - scalar a = std::min(origin.x, o.x); - scalar b = std::min(origin.y, o.y); - return rectangle(point(a, b), - point(std::max(origin.x + size.x, o.x + s.x) - a, - std::max(origin.y + size.y, o.y + s.y) - b)); -} -rectangle rectangle::intersectionWith(const rectangle& r) const -{ - point o = r.origin; - point s = r.size; - scalar a = std::max(origin.x, o.x); - scalar b = std::max(origin.y, o.y); - return rectangle(point(a, b), - point(std::min(origin.x + size.x, o.x + s.x) - a, - std::min(origin.y + size.y, o.y + s.y) - b)); -} +} // namespace dc +#endif // _CULLABLE_HH_ -} // namespace dc +/** vim: set ts=4 sw=4 tw=80: *************************************************/