#ifndef __SCENEENTITY_H #define __SCENEENTITY_H #include "common.h" #include "AxisAlignedBox3.h" #include "Triangle3.h" #include "LODInfo.h" namespace CHCDemoEngine { class Material; class Geometry; class RenderState; class Transform3; class Camera; /** Class representing a scene entity. A scene entity basically consists of geometry, transformation, and a material */ class SceneEntity { friend class RenderQueue; public: /** Creates a scene entity. */ SceneEntity(Transform3 *trafo); /** Destructor. */ virtual ~SceneEntity(); /** Renders this node. */ virtual void Render(RenderState *state); /** Set pointer to the shape */ void AddShape(Shape *shape); /** See set */ inline Shape *GetShape(int i) const; /** Returns number of shapes in vector. */ inline int GetNumShapes(); /** Set pointer to the geometry */ void SetTransform(Transform3 *trafo); /** set frame where we last rendered this node */ void SetLastRenderedFrame(int lastRendered); /** returns frame where we last visited this node */ int GetLastRenderedFrame() const; /** Returns the trafo of this scene entity. */ inline Transform3 *GetTransform() const; /** Counts number of triangles in this entity using the specified lod level with 0 being the highest or the current lod level (if the argument is -1). */ int CountNumTriangles(int lodLevel = -1); /** Returns the local bounding box. */ AxisAlignedBox3 GetBoundingBox() const; /** Returns the transformed bounding box. */ AxisAlignedBox3 GetWorldBoundingBox() const; /** Only the scene entities are visible that match the global id. */ void SetVisibleId(int id); /** See set */ int GetVisibleId(int id) const; /** Returns true if this entity is visible. */ bool IsVisible() const; //////////////// /** Returns shapes of specified lod level */ void GetLODLevel(int level, ShapeContainer::iterator &start, ShapeContainer::iterator &end); /** Returns shapes of current lod level */ void GetCurrentLODLevel(ShapeContainer::iterator &start, ShapeContainer::iterator &end); /** Adds a new lod level. */ void AddLODLevel(const LODLevel &lod); /** Returns numbers of lod levels. */ int GetNumLODLevels() const; /** Returns center point of this shape. */ Vector3 GetCenter() const; /** Returns transformed center point of this shape. */ Vector3 GetWorldCenter() const; /** Prepare this scene entity for rendering, i.e., sets the state and the transform. This is used with the render queue. When a shape belonging to this scene entity is rendered, this function is called in beforehand. */ void Prepare(RenderState *state); ///////////// //-- static functions /** If false, the highest (most detailed) LOD level is used for all entities. */ static void SetUseLODs(bool useLODs); /** See set */ static bool GetUseLODs(); /** Sets the global visible id. Scene entities are visible only if this id is -1 or their id matches this id. */ static void SetGlobalVisibleId(int id); static int GetGlobalVisibleId(); protected: /** Internally updates current lod level. */ void UpdateLODs(const Vector3 &viewPoint); /** Returns updated index of current lod level. */ int GetCurrentLODLevel(); ///////////////////// /// the bounding box AxisAlignedBox3 mBox; /// describes a 3D transform Transform3 *mTransform; /// Stores information about the LOD levels LODLevelArray mLODLevels; /// the renderable shapes ShapeContainer mShapes; /// when this entity was last rendered int mLastRenderedFrame; /// the LOD level currently used for rendering int mCurrentLODLevel; /// frame number in which the LODs were last updated int mLODLastUpdated; /// the center of gravity of this entity Vector3 mCenter; int mId; static bool sUseLODs; static int sCurrentId; int mVisibleId; static int sVisibleId; }; inline void SceneEntity::AddLODLevel(const LODLevel &lod) { mLODLevels.push_back(lod); } inline int SceneEntity::GetNumLODLevels() const { return (int)mLODLevels.size(); } inline Vector3 SceneEntity::GetCenter() const { return mCenter; } inline void SceneEntity::SetUseLODs(bool useLODs) { sUseLODs = useLODs; } inline bool SceneEntity::GetUseLODs() { return sUseLODs; } inline Shape *SceneEntity::GetShape(int i) const { return mShapes[i]; } inline int SceneEntity::GetNumShapes() { return (int)mShapes.size(); } inline Transform3 *SceneEntity::GetTransform() const { return mTransform; } inline void SceneEntity::SetVisibleId(int id) { mVisibleId = id; } inline void SceneEntity::SetGlobalVisibleId(int id) { sVisibleId = id; } inline int SceneEntity::GetGlobalVisibleId() { return sVisibleId; } inline int SceneEntity::GetVisibleId(int id) const { return mVisibleId; } inline bool SceneEntity::IsVisible() const { return (sVisibleId == -1) || (mVisibleId == sVisibleId); } } #endif // __SCENEENTITY_H