#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; friend class EntityMerger; public: /** Creates a scene entity. */ SceneEntity(Transform3 *trafo); /** Copy constructur. */ //SceneEntity(const SceneEntity &e); /** 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 { return mShapes[i]; } /** Returns number of shapes in vector. */ inline int GetNumShapes() { return (int)mShapes.size(); } /** Set pointer to the geometry */ void SetTransform(Transform3 *trafo); /** set frame where we last rendered this node */ void SetLastRendered(int lastRendered); /** returns frame where we last visited this node */ int GetLastRendered() const; /** Returns the trafo of this scene entity. */ inline Transform3 *GetTransform() const { return mTransform; } /** 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; //////////////// /** 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) { mLODLevels.push_back(lod); } /** Returns numbers of lod levels. */ int GetNumLODLevels() const { return (int)mLODLevels.size(); } /** Returns center point of this shape. */ Vector3 GetCenter() const {return mCenter; } /** 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) { sUseLODs = useLODs; } /** See set */ static bool GetUseLODs() { return sUseLODs; } int mId; 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 mLastRendered; /// 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; static bool sUseLODs; static int sCurrentId; }; } #endif // __SCENEENTITY_H