*******************************************************************************/
-#include <algorithm>
+#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: *************************************************/