[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;
|
---|
[2980] | 26 | friend class EntityMerger;
|
---|
[2802] | 27 |
|
---|
[2764] | 28 | public:
|
---|
[2839] | 29 |
|
---|
[2764] | 30 | /** Creates a scene entity.
|
---|
| 31 | */
|
---|
[2840] | 32 | SceneEntity(Transform3 *trafo);
|
---|
[3070] | 33 | /** Copy constructur.
|
---|
| 34 | */
|
---|
[3071] | 35 | //SceneEntity(const SceneEntity &e);
|
---|
[3070] | 36 | /** Destructor.
|
---|
| 37 | */
|
---|
[3042] | 38 | virtual ~SceneEntity();
|
---|
[2764] | 39 | /** Renders this node.
|
---|
| 40 | */
|
---|
[3042] | 41 | virtual void Render(RenderState *state);
|
---|
[2839] | 42 | /** Set pointer to the shape
|
---|
[2764] | 43 | */
|
---|
[2839] | 44 | void AddShape(Shape *shape);
|
---|
[2764] | 45 | /** See set
|
---|
| 46 | */
|
---|
[2839] | 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(); }
|
---|
[2764] | 51 | /** Set pointer to the geometry
|
---|
| 52 | */
|
---|
[2840] | 53 | void SetTransform(Transform3 *trafo);
|
---|
[2764] | 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;
|
---|
[2839] | 60 | /** Returns the trafo of this scene entity.
|
---|
| 61 | */
|
---|
[2840] | 62 | inline Transform3 *GetTransform() const { return mTransform; }
|
---|
[2844] | 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 | */
|
---|
[2848] | 66 | int CountNumTriangles(int lodLevel = -1);
|
---|
[3070] | 67 | /** Returns the local bounding box.
|
---|
[2844] | 68 | */
|
---|
| 69 | AxisAlignedBox3 GetBoundingBox() const;
|
---|
| 70 | /** Returns the transformed bounding box.
|
---|
| 71 | */
|
---|
[3070] | 72 | AxisAlignedBox3 GetWorldBoundingBox() const;
|
---|
[2844] | 73 |
|
---|
[2764] | 74 |
|
---|
[2841] | 75 |
|
---|
[2844] | 76 | ////////////////
|
---|
[2842] | 77 |
|
---|
[2847] | 78 |
|
---|
[2844] | 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 | */
|
---|
[3070] | 87 | void AddLODLevel(const LODLevel &lod) { mLODLevels.push_back(lod); }
|
---|
[2844] | 88 | /** Returns numbers of lod levels.
|
---|
| 89 | */
|
---|
| 90 | int GetNumLODLevels() const { return (int)mLODLevels.size(); }
|
---|
[2847] | 91 | /** Returns transformed center point of this shape.
|
---|
| 92 | */
|
---|
[3070] | 93 | Vector3 GetWorldCenter() const;
|
---|
[2865] | 94 | /** If false, the highest (most detailed) LOD level is used for all entities.
|
---|
| 95 | */
|
---|
| 96 | static void SetUseLODs(bool useLODs) { sUseLODs = useLODs; }
|
---|
[2847] | 97 |
|
---|
[2848] | 98 |
|
---|
[2764] | 99 | protected:
|
---|
| 100 |
|
---|
[2847] | 101 | /** Internally updates current lod level.
|
---|
| 102 | */
|
---|
| 103 | void UpdateLODs(const Vector3 &viewPoint);
|
---|
[2848] | 104 | /** Returns updated index of current lod level.
|
---|
| 105 | */
|
---|
| 106 | int GetCurrentLODLevel();
|
---|
[2847] | 107 |
|
---|
| 108 |
|
---|
| 109 | /// the bounding box
|
---|
[2844] | 110 | AxisAlignedBox3 mBox;
|
---|
[3071] | 111 | /// describes a 3D transform
|
---|
[2840] | 112 | Transform3 *mTransform;
|
---|
| 113 | /// Stores information about the LOD levels
|
---|
[3070] | 114 | LODLevelArray mLODLevels;
|
---|
[2840] | 115 | /// the renderable shapes
|
---|
[2839] | 116 | ShapeContainer mShapes;
|
---|
[2840] | 117 | /// when this entity was last rendered
|
---|
[2764] | 118 | int mLastRendered;
|
---|
[3071] | 119 | /// the LOD level currently used for rendering
|
---|
[2844] | 120 | int mCurrentLODLevel;
|
---|
[3071] | 121 | /// frame number in which the LODs were last updated
|
---|
[2847] | 122 | int mLODLastUpdated;
|
---|
[3071] | 123 | /// the center of gravity of this entity
|
---|
[2847] | 124 | Vector3 mCenter;
|
---|
[2865] | 125 |
|
---|
| 126 | static bool sUseLODs;
|
---|
[2764] | 127 | };
|
---|
| 128 |
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | #endif // __SCENEENTITY_H |
---|