#ifndef __SCENEENTITY_H #define __SCENEENTITY_H #include "glInterface.h" #include #include #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); ~SceneEntity(); /** Renders this node. */ 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 bounding box. */ AxisAlignedBox3 GetBoundingBox() const; /** Returns the transformed bounding box. */ AxisAlignedBox3 GetTransformedBoundingBox() 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(LODLevel *lod) { mLODLevels.push_back(lod); } /** Returns numbers of lod levels. */ int GetNumLODLevels() const { return (int)mLODLevels.size(); } /** Returns transformed center point of this shape. */ Vector3 GetCenter() const; /** If false, the highest (most detailed) LOD level is used for all entities. */ static void SetUseLODs(bool useLODs) { sUseLODs = useLODs; } 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; /// transform matrix Transform3 *mTransform; /// Stores information about the LOD levels LODLevelContainer mLODLevels; /// the renderable shapes ShapeContainer mShapes; /// when this entity was last rendered int mLastRendered; int mCurrentLODLevel; /// which frame the lod info was last updated int mLODLastUpdated; /// the center of gravity of this scene entity Vector3 mCenter; static bool sUseLODs; }; } #endif // __SCENEENTITY_H