source: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreSharedRuns.h @ 790

Revision 790, 6.9 KB checked in by szirmay, 19 years ago (diff)
Line 
1#pragma once
2#include "SharedRuns.h"
3#include "OgreRenderable.h"
4#include "Ogre.h"
5
6using namespace Ogre;
7
8/**
9        @brief Class of SharedRuns used in an OGRE environment.
10*/
11class OgreSharedRuns : public SharedRuns
12{
13public:
14       
15        /**
16                @brief Constructor.
17        */
18        OgreSharedRuns(){}
19
20        /**
21                @brief Retrieves the contaied RenderingRuns with their type information
22
23                @return map of renderables
24        */
25        std::map<RenderingRunType, RenderingRun*>& getSharedRuns(){return sharedRuns;} 
26        /**
27                @brief Sets the bounding sphere of the node.
28
29                @param sphere bounding sphere
30        */
31        void setBoundingSphere(Sphere& sphere){boundingSphere = sphere;}
32        /**
33                @brief Sets the axis-aligned bounding box of the node.
34
35                @param box bounding box
36        */
37        void setBoundingBox(AxisAlignedBox& box){boundingBox = box;}
38        /**
39                @brief Returns the bounding sphere of the node.
40
41                @return a reference to the bounding sphere
42        */
43        Sphere& getBoundingSphere(){ return boundingSphere;}
44        /**
45                @brief Returns the axis-aligned bounding box of the node.
46
47                @return a reference to the bounding box
48        */
49        AxisAlignedBox& getBoundingBox(){ return boundingBox;}
50        /**
51                @brief Returns the bounding sphere of the root parent node.
52
53                @return a reference to the bounding sphere
54        */
55        Sphere& getRootBoundingSphere()
56                {return ((OgreSharedRuns*)getRoot())->getBoundingSphere();}
57        /**
58                @brief Retrieves the bounding sphere of the topmost parent node
59                of this SharedRuns node, which have a specified RenderingRun type.
60
61                @param runType the RenderingRun type
62
63                @return a reference to the bounding sphere
64        */
65        Sphere& getRootBoundingSphere(RenderingRunType runType)
66                {return ((OgreSharedRuns*)getRoot(runType))->getBoundingSphere();}
67        /**
68                @brief Returns the axis-aligned bounding box of the root parent node.
69
70                @return a reference to the bounding box
71        */
72        AxisAlignedBox& getRootBoundingBox()
73                {return ((OgreSharedRuns*)getRoot())->getBoundingBox();}
74        /**
75                @brief Retrieves the axis-aligned bounding box of the topmost parent node
76                of this SharedRuns node, which have a specified RenderingRun type.
77
78                @param runType the RenderingRun type
79
80                @return a reference to the bounding box
81        */
82        AxisAlignedBox& getRootBoundingBox(RenderingRunType runType)
83                {return ((OgreSharedRuns*)getRoot(runType))->getBoundingBox();}
84        /**
85                @brief Returns the world space center position of the root parent node.
86
87                @return a reference to the center position
88        */
89        const Vector3& getRootPosition()
90                {return getRootBoundingSphere().getCenter();}
91        /**
92                @brief Retrieves the world space center position of the topmost parent node
93                of this SharedRuns node, which have a specified RenderingRun type.
94
95                @param runType the RenderingRun type
96
97                @return a reference to the center position
98        */
99        const Vector3& getRootPosition(RenderingRunType runType)
100                {return getRootBoundingSphere(runType).getCenter();}
101        /**
102                @brief Checks if two SharedRuns node can be joined.
103
104                @param r1 pointer to one of the SharedRuns instance
105                @param r2 pointer to the other SharedRuns instance
106        */
107        static bool canJoin(SharedRuns* r1, SharedRuns* r2);
108        /**
109                @brief Checks if two SharedRuns have common resources so that they can be joined.
110
111                @param r1 pointer to one of the SharedRuns instance
112                @param r2 pointer to the other SharedRuns instance
113        */
114        static bool haveCommonRuns(SharedRuns* r1, SharedRuns* r2);
115        /**
116                @brief Checks if this node has a resource with the given type.
117
118                Only this node none of the child nodes are checked.
119
120                @param the type of the RenderingRun to look for
121        */
122        bool hasOwnRun(RenderingRunType runType);
123        /**
124                @brief Adds all the Renderables connected to this node to a given RenderQueue.
125
126                The function is called recoursively for all child nodes.
127
128                @param pointer to the RenderQueue to add the Renderables to
129        */
130        void addRenderablesToQueue(RenderQueue* rq);
131        /**
132                @brief Calls notifyCamera() to all the Renderables connected to this node
133
134                The function is called recoursively for all child nodes.
135
136                @param pointer to the Camera instance to call notifyCamera() with
137        */
138        void notifyCamera(Camera* cam);
139        /**
140                @brief Finds all the topmost nodes which have resources of the given type.
141
142                This function is called for the root node, and will be called recoursively downwards in the tree for all childs.
143                If a node with with the given resource is found, the node can be added and it's childs don't need to be checked anymore.
144
145                From a given group of objects (root node) a new set of groups will be created (they will be the members of the given vector).
146                Each new group will be a subtree of the original tree. They will form groups that contain the maximum number of objects
147                that can be joined by the the given resource type.
148
149                @param runType the type of RenderingRun to look for
150                @param roots reference to the collection to add the new groups to
151        */
152        void findSharedRootsForType(RenderingRunType runType, std::vector<OgreSharedRuns*>& roots);
153       
154        //inherited
155        RenderingRun* getRun(RenderingRunType runType);
156        //inherited
157        void addRun(RenderingRunType runType, RenderingRun* run);
158        //inherited
159        void updateRun(RenderingRunType runType, unsigned long frameNum);
160        //inherited
161        void addRenderable(OgreRenderable* rend)
162        {
163                if(renderables[rend] != 0)
164                        renderables[rend] = rend->isVisible();
165        }
166        //inherited
167        void updateBounds();
168        //inherited
169        void validate();       
170        //inherited
171        void destroy();
172       
173protected:
174        /**
175                @brief map of contained RenderingRuns
176        */
177        std::map<RenderingRunType, RenderingRun*> sharedRuns;
178        /**
179                @brief map of connected renderablis with visibility information
180
181                Used to show or hide the renderables connected to a leaf OgreSharedRuns node.
182        */
183        std::map<OgreRenderable*, bool> renderables;
184        /**
185                @brief the bounding sphere of all the objects connected to this node.
186        */
187        Sphere boundingSphere;
188        /**
189                @brief the axis aligned bounding box of all the objects connected to this node.
190        */
191        AxisAlignedBox boundingBox;
192
193        //inherited
194        void gatherRuns();
195        //inherited
196        void fireRunChanges();
197        //inherited
198        SharedRuns* createInstance();
199        //inherited
200        void hideRenderables()
201        {
202                std::map<OgreRenderable*, bool>::iterator it = renderables.begin();
203                std::map<OgreRenderable*, bool>::iterator itend = renderables.end();
204                while(it != itend)
205                {               
206                        (*it).second = (*it).first->isVisible();
207                        (*it).first->setVisible(false);
208                        it++;
209                }               
210        }
211        //inherited
212        void restoreRenderableVisibility()
213        {
214                std::map<OgreRenderable*, bool>::iterator it = renderables.begin();
215                std::map<OgreRenderable*, bool>::iterator itend = renderables.end();
216                while(it != itend)
217                {               
218                        (*it).first->setVisible((*it).second);
219                        it++;
220                }
221        }
222        //inherited
223        void setRenderablesVisible(bool visible)
224        {
225                std::map<OgreRenderable*, bool>::iterator it = renderables.begin();
226                std::map<OgreRenderable*, bool>::iterator itend = renderables.end();
227                while(it != itend)
228                {               
229                        (*it).first->setVisible(visible);
230                        it++;
231                }
232        }
233       
234};
235
Note: See TracBrowser for help on using the repository browser.