1 | /*==========================================================================
|
---|
2 | * (C) 2006 Universidad Jaime I de Castellón
|
---|
3 | *==========================================================================
|
---|
4 | * PROYECT: GAME TOOLS
|
---|
5 | *==========================================================================*/
|
---|
6 | /* CONTENT:
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * @file GeoLodManager.h
|
---|
10 | *==========================================================================*/
|
---|
11 |
|
---|
12 | #ifndef _GEOLODMANAGER
|
---|
13 | #define _GEOLODMANAGER
|
---|
14 |
|
---|
15 | #include "GeoVector3.h"
|
---|
16 | #include "GeoLodObject.h"
|
---|
17 |
|
---|
18 | namespace Geometry
|
---|
19 | {
|
---|
20 | class NodeContainer;
|
---|
21 | class lodobj_node_t;
|
---|
22 |
|
---|
23 | /// This class implements a LOD manager for level of detail objects such as (LodStrips and LodTree objects)
|
---|
24 | /** This class automatically manages the level of detail of all objects added to the lod manager.
|
---|
25 | The key idea is to minimize the number of real changes in levels of detail because they consume
|
---|
26 | CPU and that can cause stalls and CPU bottlenecks in massive applications. The LodManager solves
|
---|
27 | this issue by deciding which objects have to change the level of detail and which objects can just
|
---|
28 | share an already calculated one. The system also decides whether an object can chage its level of
|
---|
29 | detail or it is not needed because it would take not effect on the performance. This drastically
|
---|
30 | reduces the CPU usage. in a completely transparent way to the user. */
|
---|
31 |
|
---|
32 | class GEOLODLIBRARYDLL_API LodManager
|
---|
33 | {
|
---|
34 | public:
|
---|
35 | /// LodManager constructor
|
---|
36 | /** Constucts a LodManager object from the following parameters:
|
---|
37 | - The near and far distances that define the active LOD range.
|
---|
38 | - The initial camera position
|
---|
39 | - The number of LOD slots in the snapshot list (this parameter is optional)
|
---|
40 | */
|
---|
41 | LodManager(Real near, Real far, const Geometry::Vector3 &campos, int numslots=10);
|
---|
42 |
|
---|
43 | /// class destructor
|
---|
44 | ~LodManager(void);
|
---|
45 |
|
---|
46 | /// Adds a new LOD object (a LodStrips or a LodTree object)
|
---|
47 | /** When an object is added to the system, its level of detail is automatically managed, and the
|
---|
48 | client application does not need to manually change its level of detail.
|
---|
49 | The parameters needed to add an object to the system are:
|
---|
50 | - The class name of the object. The class name is the type of object. This is used by the system to
|
---|
51 | know which objects are compatible to change the level of detail between themselves.
|
---|
52 | - A reference to the LodObject itself (a LodStrips or a LodTree object).
|
---|
53 | - The initial position in the 3D space of the added object. */
|
---|
54 | void AddLodObj(const std::string &name, LodObject*, const Geometry::Vector3 &);
|
---|
55 |
|
---|
56 | /// Performs all needed LOD updates
|
---|
57 | /** This function should be called once per frame (or at some reasonable interval).
|
---|
58 | Internally it performs all needed steps to change the level of detail of the objects. */
|
---|
59 | void UpdateLOD(void);
|
---|
60 |
|
---|
61 | /// Updates the camera position
|
---|
62 | void UpdateCamera(const Geometry::Vector3 &);
|
---|
63 |
|
---|
64 | /// Updates the position of a certain LodObject
|
---|
65 | void UpdateLODObjectPos(LodObject*,const Geometry::Vector3 &);
|
---|
66 |
|
---|
67 | /// Set it to true to force all LOD calculations (disable the LodManager features)
|
---|
68 | bool always_calculate_lod;
|
---|
69 |
|
---|
70 | /// if set to true, all objects will be set to their highest level of detail
|
---|
71 | bool force_highest_lod;
|
---|
72 |
|
---|
73 | private:
|
---|
74 | NodeContainer *lodobj_container;
|
---|
75 | uint32 lasttime;
|
---|
76 | bool camera_changed, node_added;
|
---|
77 | float near_range, far_range;
|
---|
78 | float SelectRandomDistance(void) const;
|
---|
79 | void ChangeLOD(lodobj_node_t*,Real);
|
---|
80 | void ReallyGoToLOD(lodobj_node_t*,Real);
|
---|
81 |
|
---|
82 | lodobj_node_t * FindMostSimilarRealLOD(const std::string &, Real desired_lod);
|
---|
83 |
|
---|
84 | void MakeDiscipleOf(lodobj_node_t *master, lodobj_node_t *disciple);
|
---|
85 | void MakeIndependent(lodobj_node_t*);
|
---|
86 | void RemoveDiscipleFrom(LodObject *master, LodObject *disciple);
|
---|
87 | void UpdateDisciples(lodobj_node_t *master);
|
---|
88 | void DeleteMeFromMyMastersDiscipleList(lodobj_node_t *);
|
---|
89 | void ChangeMaster(lodobj_node_t *orig, lodobj_node_t *newmaster);
|
---|
90 | };
|
---|
91 | }
|
---|
92 |
|
---|
93 | #endif |
---|