[2764] | 1 | #ifndef __SCENEENTITY_H
|
---|
| 2 | #define __SCENEENTITY_H
|
---|
| 3 |
|
---|
| 4 | #include "common.h"
|
---|
| 5 | #include "AxisAlignedBox3.h"
|
---|
| 6 | #include "Triangle3.h"
|
---|
[2839] | 7 | #include "LODInfo.h"
|
---|
[2764] | 8 |
|
---|
[2819] | 9 |
|
---|
[2776] | 10 | namespace CHCDemoEngine
|
---|
[2764] | 11 | {
|
---|
| 12 |
|
---|
| 13 | class Material;
|
---|
| 14 | class Geometry;
|
---|
| 15 | class RenderState;
|
---|
[2840] | 16 | class Transform3;
|
---|
[2844] | 17 | class Camera;
|
---|
[2764] | 18 |
|
---|
[2840] | 19 |
|
---|
[2764] | 20 | /** Class representing a scene entity.
|
---|
[2793] | 21 | A scene entity basically consists of geometry, transformation, and a material
|
---|
[2764] | 22 | */
|
---|
| 23 | class SceneEntity
|
---|
| 24 | {
|
---|
[2802] | 25 | friend class RenderQueue;
|
---|
| 26 |
|
---|
[2764] | 27 | public:
|
---|
[2839] | 28 |
|
---|
[2764] | 29 | /** Creates a scene entity.
|
---|
| 30 | */
|
---|
[2840] | 31 | SceneEntity(Transform3 *trafo);
|
---|
[3070] | 32 | /** Destructor.
|
---|
| 33 | */
|
---|
[3042] | 34 | virtual ~SceneEntity();
|
---|
[2764] | 35 | /** Renders this node.
|
---|
| 36 | */
|
---|
[3042] | 37 | virtual void Render(RenderState *state);
|
---|
[2839] | 38 | /** Set pointer to the shape
|
---|
[2764] | 39 | */
|
---|
[2839] | 40 | void AddShape(Shape *shape);
|
---|
[2764] | 41 | /** See set
|
---|
| 42 | */
|
---|
[3245] | 43 | inline Shape *GetShape(int i) const;
|
---|
[2839] | 44 | /** Returns number of shapes in vector.
|
---|
| 45 | */
|
---|
[3245] | 46 | inline int GetNumShapes();
|
---|
[2764] | 47 | /** Set pointer to the geometry
|
---|
| 48 | */
|
---|
[2840] | 49 | void SetTransform(Transform3 *trafo);
|
---|
[2764] | 50 | /** set frame where we last rendered this node
|
---|
| 51 | */
|
---|
[3245] | 52 | void SetLastRenderedFrame(int lastRendered);
|
---|
[2764] | 53 | /** returns frame where we last visited this node
|
---|
| 54 | */
|
---|
[3245] | 55 | int GetLastRenderedFrame() const;
|
---|
[2839] | 56 | /** Returns the trafo of this scene entity.
|
---|
| 57 | */
|
---|
[3245] | 58 | inline Transform3 *GetTransform() const;
|
---|
[2844] | 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 | */
|
---|
[2848] | 62 | int CountNumTriangles(int lodLevel = -1);
|
---|
[3070] | 63 | /** Returns the local bounding box.
|
---|
[2844] | 64 | */
|
---|
| 65 | AxisAlignedBox3 GetBoundingBox() const;
|
---|
| 66 | /** Returns the transformed bounding box.
|
---|
| 67 | */
|
---|
[3070] | 68 | AxisAlignedBox3 GetWorldBoundingBox() const;
|
---|
[3245] | 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;
|
---|
[2764] | 78 |
|
---|
[2841] | 79 |
|
---|
[2844] | 80 | ////////////////
|
---|
[2842] | 81 |
|
---|
[2847] | 82 |
|
---|
[2844] | 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 | */
|
---|
[3245] | 91 | void AddLODLevel(const LODLevel &lod);
|
---|
[2844] | 92 | /** Returns numbers of lod levels.
|
---|
| 93 | */
|
---|
[3245] | 94 | int GetNumLODLevels() const;
|
---|
[3120] | 95 | /** Returns center point of this shape.
|
---|
| 96 | */
|
---|
[3245] | 97 | Vector3 GetCenter() const;
|
---|
[2847] | 98 | /** Returns transformed center point of this shape.
|
---|
| 99 | */
|
---|
[3070] | 100 | Vector3 GetWorldCenter() const;
|
---|
[3110] | 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 |
|
---|
[2865] | 111 | /** If false, the highest (most detailed) LOD level is used for all entities.
|
---|
| 112 | */
|
---|
[3245] | 113 | static void SetUseLODs(bool useLODs);
|
---|
[3110] | 114 | /** See set
|
---|
| 115 | */
|
---|
[3245] | 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);
|
---|
[2848] | 121 |
|
---|
[3251] | 122 | static int GetGlobalVisibleId();
|
---|
| 123 |
|
---|
[2764] | 124 | protected:
|
---|
| 125 |
|
---|
[3251] | 126 |
|
---|
[2847] | 127 | /** Internally updates current lod level.
|
---|
| 128 | */
|
---|
| 129 | void UpdateLODs(const Vector3 &viewPoint);
|
---|
[2848] | 130 | /** Returns updated index of current lod level.
|
---|
| 131 | */
|
---|
| 132 | int GetCurrentLODLevel();
|
---|
[2847] | 133 |
|
---|
| 134 |
|
---|
[3110] | 135 | /////////////////////
|
---|
| 136 |
|
---|
[2847] | 137 | /// the bounding box
|
---|
[2844] | 138 | AxisAlignedBox3 mBox;
|
---|
[3071] | 139 | /// describes a 3D transform
|
---|
[2840] | 140 | Transform3 *mTransform;
|
---|
| 141 | /// Stores information about the LOD levels
|
---|
[3070] | 142 | LODLevelArray mLODLevels;
|
---|
[2840] | 143 | /// the renderable shapes
|
---|
[2839] | 144 | ShapeContainer mShapes;
|
---|
[2840] | 145 | /// when this entity was last rendered
|
---|
[3245] | 146 | int mLastRenderedFrame;
|
---|
[3071] | 147 | /// the LOD level currently used for rendering
|
---|
[2844] | 148 | int mCurrentLODLevel;
|
---|
[3071] | 149 | /// frame number in which the LODs were last updated
|
---|
[2847] | 150 | int mLODLastUpdated;
|
---|
[3071] | 151 | /// the center of gravity of this entity
|
---|
[2847] | 152 | Vector3 mCenter;
|
---|
[3243] | 153 |
|
---|
| 154 | int mId;
|
---|
[2865] | 155 |
|
---|
| 156 | static bool sUseLODs;
|
---|
[3109] | 157 | static int sCurrentId;
|
---|
[3245] | 158 |
|
---|
| 159 | int mVisibleId;
|
---|
| 160 | static int sVisibleId;
|
---|
[2764] | 161 | };
|
---|
| 162 |
|
---|
[3109] | 163 |
|
---|
[3245] | 164 | inline void SceneEntity::AddLODLevel(const LODLevel &lod)
|
---|
| 165 | {
|
---|
| 166 | mLODLevels.push_back(lod);
|
---|
[2764] | 167 | }
|
---|
| 168 |
|
---|
[3245] | 169 |
|
---|
| 170 | inline int SceneEntity::GetNumLODLevels() const
|
---|
| 171 | {
|
---|
| 172 | return (int)mLODLevels.size();
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 |
|
---|
| 176 | inline Vector3 SceneEntity::GetCenter() const
|
---|
| 177 | {
|
---|
| 178 | return mCenter;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 |
|
---|
| 182 | inline void SceneEntity::SetUseLODs(bool useLODs)
|
---|
| 183 | {
|
---|
| 184 | sUseLODs = useLODs;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 |
|
---|
| 188 | inline bool SceneEntity::GetUseLODs()
|
---|
| 189 | {
|
---|
| 190 | return sUseLODs;
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 | inline Shape *SceneEntity::GetShape(int i) const
|
---|
| 195 | {
|
---|
| 196 | return mShapes[i];
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 |
|
---|
| 200 | inline int SceneEntity::GetNumShapes()
|
---|
| 201 | {
|
---|
| 202 | return (int)mShapes.size();
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 |
|
---|
| 206 | inline Transform3 *SceneEntity::GetTransform() const
|
---|
| 207 | {
|
---|
| 208 | return mTransform;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 |
|
---|
| 212 | inline void SceneEntity::SetVisibleId(int id)
|
---|
| 213 | {
|
---|
| 214 | mVisibleId = id;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 |
|
---|
| 218 | inline void SceneEntity::SetGlobalVisibleId(int id)
|
---|
| 219 | {
|
---|
| 220 | sVisibleId = id;
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 |
|
---|
[3251] | 224 | inline int SceneEntity::GetGlobalVisibleId()
|
---|
| 225 | {
|
---|
| 226 | return sVisibleId;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 |
|
---|
[3245] | 230 | inline int SceneEntity::GetVisibleId(int id) const
|
---|
| 231 | {
|
---|
| 232 | return mVisibleId;
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 |
|
---|
| 236 | inline bool SceneEntity::IsVisible() const
|
---|
| 237 | {
|
---|
| 238 | return (sVisibleId == -1) || (mVisibleId == sVisibleId);
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 |
|
---|
| 242 | }
|
---|
| 243 |
|
---|
[2764] | 244 | #endif // __SCENEENTITY_H |
---|