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

Revision 3243, 3.8 KB checked in by mattausch, 15 years ago (diff)
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        friend class EntityMerger;
27
28public:
29       
30        /** Creates a scene entity.
31        */
32        SceneEntity(Transform3 *trafo);
33        /** Copy constructur.
34        */
35        //SceneEntity(const SceneEntity &e);
36        /** Destructor.
37        */
38        virtual ~SceneEntity();
39        /** Renders this node.
40        */
41        virtual void Render(RenderState *state);       
42        /** Set pointer to the shape
43        */
44        void AddShape(Shape *shape);
45        /** See set
46        */
47        inline Shape *GetShape(int i) const { return mShapes[i]; }
48        /** Returns number of shapes in vector.
49        */
50        inline int GetNumShapes() { return (int)mShapes.size(); }
51        /** Set pointer to the geometry
52        */
53        void SetTransform(Transform3 *trafo);
54        /** set frame where we last rendered this node
55        */
56        void SetLastRendered(int lastRendered);
57        /** returns frame where we last visited this node
58        */
59        int GetLastRendered() const;
60        /** Returns the trafo of this scene entity.
61        */
62        inline Transform3 *GetTransform() const  { return mTransform; }
63        /** Counts number of triangles in this entity using the specified lod level
64                with 0 being the highest or the current lod level (if the argument is -1).
65        */
66        int CountNumTriangles(int lodLevel = -1);
67        /** Returns the local bounding box.
68        */
69        AxisAlignedBox3 GetBoundingBox() const;
70        /** Returns the transformed bounding box.
71        */
72        AxisAlignedBox3 GetWorldBoundingBox() const;
73       
74
75
76        ////////////////
77
78       
79        /** Returns shapes of specified lod level
80        */
81        void GetLODLevel(int level, ShapeContainer::iterator &start, ShapeContainer::iterator &end);
82        /** Returns shapes of current lod level
83        */
84        void GetCurrentLODLevel(ShapeContainer::iterator &start, ShapeContainer::iterator &end);
85        /** Adds a new lod level.
86        */
87        void AddLODLevel(const LODLevel &lod) { mLODLevels.push_back(lod); }
88        /** Returns numbers of lod levels.
89        */
90        int GetNumLODLevels() const { return (int)mLODLevels.size(); }
91        /** Returns center point of this shape.
92        */
93        Vector3 GetCenter() const {return mCenter; }
94        /** Returns transformed center point of this shape.
95        */
96        Vector3 GetWorldCenter() const;
97        /** Prepare this scene entity for rendering, i.e., sets the state and the transform.
98                This is used with the render queue. When a shape belonging to this scene entity
99                is rendered, this function is called in beforehand.
100        */
101        void Prepare(RenderState *state);
102
103
104        /////////////
105        //-- static functions
106
107        /** If false, the highest (most detailed) LOD level is used for all entities.
108        */
109        static void SetUseLODs(bool useLODs) { sUseLODs = useLODs; }
110        /** See set
111        */
112        static bool GetUseLODs() { return sUseLODs; }
113
114protected:
115
116        /** Internally updates current lod level.
117        */
118        void UpdateLODs(const Vector3 &viewPoint);
119        /** Returns updated index of current lod level.
120        */
121        int GetCurrentLODLevel();
122
123
124        /////////////////////
125
126        /// the bounding box
127        AxisAlignedBox3 mBox;
128        /// describes a 3D transform
129        Transform3 *mTransform;
130        /// Stores information about the LOD levels
131        LODLevelArray mLODLevels;
132        /// the renderable shapes
133        ShapeContainer mShapes;
134        /// when this entity was last rendered
135        int mLastRendered;
136        /// the LOD level currently used for rendering
137        int mCurrentLODLevel;
138        /// frame number in which the LODs were last updated
139        int mLODLastUpdated;
140        /// the center of gravity of this entity
141        Vector3 mCenter;
142       
143        int mId;
144
145        static bool sUseLODs;
146        static int sCurrentId;
147};
148
149
150}
151
152#endif // __SCENEENTITY_H
Note: See TracBrowser for help on using the repository browser.