[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(); }
|
---|
[3120] | 91 | /** Returns center point of this shape.
|
---|
| 92 | */
|
---|
| 93 | Vector3 GetCenter() const {return mCenter; }
|
---|
[2847] | 94 | /** Returns transformed center point of this shape.
|
---|
| 95 | */
|
---|
[3070] | 96 | Vector3 GetWorldCenter() const;
|
---|
[3110] | 97 | /** Prepare this scene entity for rendering, i.e., sets the state and the transform.
|
---|
| 98 | This is used with the render queue. When a shape belonging to this scene entity
|
---|
| 99 | is rendered, this function is called in beforehand.
|
---|
| 100 | */
|
---|
| 101 | void Prepare(RenderState *state);
|
---|
| 102 |
|
---|
| 103 |
|
---|
| 104 | /////////////
|
---|
| 105 | //-- static functions
|
---|
| 106 |
|
---|
[2865] | 107 | /** If false, the highest (most detailed) LOD level is used for all entities.
|
---|
| 108 | */
|
---|
| 109 | static void SetUseLODs(bool useLODs) { sUseLODs = useLODs; }
|
---|
[3110] | 110 | /** See set
|
---|
| 111 | */
|
---|
[3102] | 112 | static bool GetUseLODs() { return sUseLODs; }
|
---|
[2848] | 113 |
|
---|
[3102] | 114 |
|
---|
[3110] | 115 | int mId;
|
---|
[3102] | 116 |
|
---|
[2764] | 117 | protected:
|
---|
| 118 |
|
---|
[2847] | 119 | /** Internally updates current lod level.
|
---|
| 120 | */
|
---|
| 121 | void UpdateLODs(const Vector3 &viewPoint);
|
---|
[2848] | 122 | /** Returns updated index of current lod level.
|
---|
| 123 | */
|
---|
| 124 | int GetCurrentLODLevel();
|
---|
[2847] | 125 |
|
---|
| 126 |
|
---|
[3110] | 127 | /////////////////////
|
---|
| 128 |
|
---|
[2847] | 129 | /// the bounding box
|
---|
[2844] | 130 | AxisAlignedBox3 mBox;
|
---|
[3071] | 131 | /// describes a 3D transform
|
---|
[2840] | 132 | Transform3 *mTransform;
|
---|
| 133 | /// Stores information about the LOD levels
|
---|
[3070] | 134 | LODLevelArray mLODLevels;
|
---|
[2840] | 135 | /// the renderable shapes
|
---|
[2839] | 136 | ShapeContainer mShapes;
|
---|
[2840] | 137 | /// when this entity was last rendered
|
---|
[2764] | 138 | int mLastRendered;
|
---|
[3071] | 139 | /// the LOD level currently used for rendering
|
---|
[2844] | 140 | int mCurrentLODLevel;
|
---|
[3071] | 141 | /// frame number in which the LODs were last updated
|
---|
[2847] | 142 | int mLODLastUpdated;
|
---|
[3071] | 143 | /// the center of gravity of this entity
|
---|
[2847] | 144 | Vector3 mCenter;
|
---|
[2865] | 145 |
|
---|
| 146 | static bool sUseLODs;
|
---|
[3109] | 147 | static int sCurrentId;
|
---|
[2764] | 148 | };
|
---|
| 149 |
|
---|
[3109] | 150 |
|
---|
[2764] | 151 | }
|
---|
| 152 |
|
---|
| 153 | #endif // __SCENEENTITY_H |
---|