X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fmoof%2Fentity.hh;fp=src%2Fmoof%2Fentity.hh;h=b503551b38f2422fa4b9f6597c79314f1d91a0c0;hb=831f04d4bc19a390415ac0bbac4331c7a65509bc;hp=0000000000000000000000000000000000000000;hpb=299af4f2047e767e5d79501c26444473bda64c64;p=chaz%2Fyoink diff --git a/src/moof/entity.hh b/src/moof/entity.hh new file mode 100644 index 0000000..b503551 --- /dev/null +++ b/src/moof/entity.hh @@ -0,0 +1,106 @@ + +/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +**] All rights reserved. +* +* vi:ts=4 sw=4 tw=75 +* +* Distributable under the terms and conditions of the 2-clause BSD license; +* see the file COPYING for a complete text of the license. +* +**************************************************************************/ + +#ifndef _MOOF_ENTITY_HH_ +#define _MOOF_ENTITY_HH_ + +/** + * \file entity.hh + * Interface class for cullable and drawable objects. + */ + +#include + +#include +#include +#include +#include + + +namespace moof { + + +class frustum; + + +class entity; + +/** + * Entity pointer. + */ +typedef boost::shared_ptr entity_ptr; + + +/** + * Interface for game objects that can be drawn to the screen and have a + * specified volume (take up space). + */ +class entity : public cullable, public drawable +{ +public: + + virtual ~entity() {} + + /** + * Draw the entity only if it is visible. This method melds the + * cullable and drawable interfaces, and the default implementation is + * usually on the money. + * \param alpha The fraction between the last timestep and the next + * timestep. + * \param frustum The camera frustum for determining visibility. + */ + virtual void draw_if_visible(scalar alpha, const frustum& frustum) const + { + if (is_visible(frustum)) draw(alpha); + } + + /** + * Get whether or not the entity is within a frustum. The default + * implementation returns the visibility of the bounding sphere and + * box. + * \param frustum The camera frustum. + * \return True if the entity is visible, false otherwise. + */ + virtual bool is_visible(const frustum& frustum) const + { + return sphere_.is_visible(frustum) && aabb_.is_visible(frustum); + } + + + /** + * Get the axis-aligned bounding box surrounding the entity. + * \return The AABB. + */ + const moof::aabb<3>& aabb() const + { + return aabb_; + } + + /** Get the bounding sphere surrounding the entity. + * \return The sphere. + */ + const moof::sphere<3>& sphere() const + { + return sphere_; + } + + +protected: + + moof::aabb<3> aabb_; + moof::sphere<3> sphere_; +}; + + +} // namespace moof + +#endif // _MOOF_ENTITY_HH_ +