source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h @ 3245

Revision 3245, 4.9 KB checked in by mattausch, 15 years ago (diff)

pvs seems to work now

Line 
1#ifndef __SCENEENTITY_H
2#define __SCENEENTITY_H
3
4#include "common.h"
5#include "AxisAlignedBox3.h"
6#include "Triangle3.h"
7#include "LODInfo.h"
8
9
10namespace CHCDemoEngine
11{
12
13class Material;
14class Geometry;
15class RenderState;
16class Transform3;
17class Camera;
18
19
20/** Class representing a scene entity.
21    A scene entity basically consists of geometry, transformation, and a material
22*/
23class SceneEntity
24{
25        friend class RenderQueue;
26
27public:
28       
29        /** Creates a scene entity.
30        */
31        SceneEntity(Transform3 *trafo);
32        /** Destructor.
33        */
34        virtual ~SceneEntity();
35        /** Renders this node.
36        */
37        virtual void Render(RenderState *state);       
38        /** Set pointer to the shape
39        */
40        void AddShape(Shape *shape);
41        /** See set
42        */
43        inline Shape *GetShape(int i) const;
44        /** Returns number of shapes in vector.
45        */
46        inline int GetNumShapes();
47        /** Set pointer to the geometry
48        */
49        void SetTransform(Transform3 *trafo);
50        /** set frame where we last rendered this node
51        */
52        void SetLastRenderedFrame(int lastRendered);
53        /** returns frame where we last visited this node
54        */
55        int GetLastRenderedFrame() const;
56        /** Returns the trafo of this scene entity.
57        */
58        inline Transform3 *GetTransform() const;
59        /** Counts number of triangles in this entity using the specified lod level
60                with 0 being the highest or the current lod level (if the argument is -1).
61        */
62        int CountNumTriangles(int lodLevel = -1);
63        /** Returns the local bounding box.
64        */
65        AxisAlignedBox3 GetBoundingBox() const;
66        /** Returns the transformed bounding box.
67        */
68        AxisAlignedBox3 GetWorldBoundingBox() const;
69        /** Only the scene entities are visible that match the global id.
70        */
71        void SetVisibleId(int id);
72        /** See set
73        */
74        int GetVisibleId(int id) const;
75        /** Returns true if this entity is visible.
76        */
77        bool IsVisible() const;
78
79
80        ////////////////
81
82       
83        /** Returns shapes of specified lod level
84        */
85        void GetLODLevel(int level, ShapeContainer::iterator &start, ShapeContainer::iterator &end);
86        /** Returns shapes of current lod level
87        */
88        void GetCurrentLODLevel(ShapeContainer::iterator &start, ShapeContainer::iterator &end);
89        /** Adds a new lod level.
90        */
91        void AddLODLevel(const LODLevel &lod);
92        /** Returns numbers of lod levels.
93        */
94        int GetNumLODLevels() const;
95        /** Returns center point of this shape.
96        */
97        Vector3 GetCenter() const;
98        /** Returns transformed center point of this shape.
99        */
100        Vector3 GetWorldCenter() const;
101        /** Prepare this scene entity for rendering, i.e., sets the state and the transform.
102                This is used with the render queue. When a shape belonging to this scene entity
103                is rendered, this function is called in beforehand.
104        */
105        void Prepare(RenderState *state);
106
107
108        /////////////
109        //-- static functions
110
111        /** If false, the highest (most detailed) LOD level is used for all entities.
112        */
113        static void SetUseLODs(bool useLODs);
114        /** See set
115        */
116        static bool GetUseLODs();
117        /** Sets the global visible id. Scene entities are visible only if
118                this id is -1 or their id matches this id.
119        */
120        static void SetGlobalVisibleId(int id);
121
122protected:
123
124        /** Internally updates current lod level.
125        */
126        void UpdateLODs(const Vector3 &viewPoint);
127        /** Returns updated index of current lod level.
128        */
129        int GetCurrentLODLevel();
130
131
132        /////////////////////
133
134        /// the bounding box
135        AxisAlignedBox3 mBox;
136        /// describes a 3D transform
137        Transform3 *mTransform;
138        /// Stores information about the LOD levels
139        LODLevelArray mLODLevels;
140        /// the renderable shapes
141        ShapeContainer mShapes;
142        /// when this entity was last rendered
143        int mLastRenderedFrame;
144        /// the LOD level currently used for rendering
145        int mCurrentLODLevel;
146        /// frame number in which the LODs were last updated
147        int mLODLastUpdated;
148        /// the center of gravity of this entity
149        Vector3 mCenter;
150       
151        int mId;
152
153        static bool sUseLODs;
154        static int sCurrentId;
155
156        int mVisibleId;
157        static int sVisibleId;
158};
159
160
161inline void SceneEntity::AddLODLevel(const LODLevel &lod)
162{
163        mLODLevels.push_back(lod);
164}
165
166
167inline int SceneEntity::GetNumLODLevels() const
168{
169        return (int)mLODLevels.size();
170}
171
172
173inline Vector3 SceneEntity::GetCenter() const
174{
175        return mCenter;
176}
177
178
179inline void SceneEntity::SetUseLODs(bool useLODs)
180{
181        sUseLODs = useLODs;
182}
183
184
185inline bool SceneEntity::GetUseLODs()
186{
187        return sUseLODs;
188}
189
190
191inline Shape *SceneEntity::GetShape(int i) const
192{
193        return mShapes[i];
194}
195
196
197inline int SceneEntity::GetNumShapes()
198{
199        return (int)mShapes.size();
200}
201
202
203inline Transform3 *SceneEntity::GetTransform() const 
204{
205        return mTransform;
206}
207
208
209inline void SceneEntity::SetVisibleId(int id)
210{
211        mVisibleId = id;
212}
213
214
215inline void SceneEntity::SetGlobalVisibleId(int id)
216{
217        sVisibleId = id;
218}
219
220
221inline int SceneEntity::GetVisibleId(int id) const
222{
223        return mVisibleId;
224}
225
226
227inline bool SceneEntity::IsVisible() const
228{
229        return (sVisibleId == -1) || (mVisibleId == sVisibleId);
230}
231
232
233}
234
235#endif // __SCENEENTITY_H
Note: See TracBrowser for help on using the repository browser.