]> Dogcows Code - chaz/yoink/blob - src/moof/entity.hh
the massive refactoring effort
[chaz/yoink] / src / moof / entity.hh
1
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
4 *
5 * vi:ts=4 sw=4 tw=75
6 *
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
9 *
10 **************************************************************************/
11
12 #ifndef _MOOF_ENTITY_HH_
13 #define _MOOF_ENTITY_HH_
14
15 /**
16 * \file entity.hh
17 * Interface class for cullable and drawable objects.
18 */
19
20 #include <boost/shared_ptr.hpp>
21
22 #include <moof/aabb.hh>
23 #include <moof/cullable.hh>
24 #include <moof/drawable.hh>
25 #include <moof/sphere.hh>
26
27
28 namespace moof {
29
30
31 class frustum;
32
33
34 class entity;
35
36 /**
37 * Entity pointer.
38 */
39 typedef boost::shared_ptr<entity> entity_ptr;
40
41
42 /**
43 * Interface for game objects that can be drawn to the screen and have a
44 * specified volume (take up space).
45 */
46 class entity : public cullable, public drawable
47 {
48 public:
49
50 virtual ~entity() {}
51
52 /**
53 * Draw the entity only if it is visible. This method melds the
54 * cullable and drawable interfaces, and the default implementation is
55 * usually on the money.
56 * \param alpha The fraction between the last timestep and the next
57 * timestep.
58 * \param frustum The camera frustum for determining visibility.
59 */
60 virtual void draw_if_visible(scalar alpha, const frustum& frustum) const
61 {
62 if (is_visible(frustum)) draw(alpha);
63 }
64
65 /**
66 * Get whether or not the entity is within a frustum. The default
67 * implementation returns the visibility of the bounding sphere and
68 * box.
69 * \param frustum The camera frustum.
70 * \return True if the entity is visible, false otherwise.
71 */
72 virtual bool is_visible(const frustum& frustum) const
73 {
74 return sphere_.is_visible(frustum) && aabb_.is_visible(frustum);
75 }
76
77
78 /**
79 * Get the axis-aligned bounding box surrounding the entity.
80 * \return The AABB.
81 */
82 const moof::aabb<3>& aabb() const
83 {
84 return aabb_;
85 }
86
87 /** Get the bounding sphere surrounding the entity.
88 * \return The sphere.
89 */
90 const moof::sphere<3>& sphere() const
91 {
92 return sphere_;
93 }
94
95
96 protected:
97
98 moof::aabb<3> aabb_;
99 moof::sphere<3> sphere_;
100 };
101
102
103 } // namespace moof
104
105 #endif // _MOOF_ENTITY_HH_
106
This page took 0.036098 seconds and 4 git commands to generate.