1 | /*************************************************************************** |
---|
2 | octreescenemanager.h - description |
---|
3 | ------------------- |
---|
4 | begin : Fri Sep 27 2002 |
---|
5 | copyright : (C) 2002 by Jon Anderson |
---|
6 | email : janders@users.sf.net |
---|
7 | ***************************************************************************/ |
---|
8 | |
---|
9 | /* |
---|
10 | ----------------------------------------------------------------------------- |
---|
11 | This source file is part of OGRE |
---|
12 | (Object-oriented Graphics Rendering Engine) |
---|
13 | For the latest info, see http://www.ogre3d.org/ |
---|
14 | |
---|
15 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
16 | Also see acknowledgements in Readme.html |
---|
17 | |
---|
18 | This program is free software; you can redistribute it and/or modify it under |
---|
19 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
20 | Foundation; either version 2 of the License, or (at your option) any later |
---|
21 | version. |
---|
22 | |
---|
23 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
24 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
25 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
26 | |
---|
27 | You should have received a copy of the GNU Lesser General Public License along with |
---|
28 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
29 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
30 | http://www.gnu.org/copyleft/lesser.txt. |
---|
31 | |
---|
32 | You may alternatively use this source under the terms of a specific version of |
---|
33 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
34 | Torus Knot Software Ltd. |
---|
35 | ----------------------------------------------------------------------------- |
---|
36 | */ |
---|
37 | |
---|
38 | #ifndef OCTREESCENEMANAGER_H |
---|
39 | #define OCTREESCENEMANAGER_H |
---|
40 | |
---|
41 | #include "OgreTerrainPrerequisites.h" |
---|
42 | #include "OgreSceneManager.h" |
---|
43 | #include "OgreRenderOperation.h" |
---|
44 | #include "OgreSphere.h" |
---|
45 | |
---|
46 | #include <list> |
---|
47 | #include <algorithm> |
---|
48 | |
---|
49 | #include <OgreOctree.h> |
---|
50 | |
---|
51 | |
---|
52 | namespace Ogre |
---|
53 | { |
---|
54 | |
---|
55 | class OctreeNode; |
---|
56 | |
---|
57 | class OctreeCamera; |
---|
58 | class OctreeIntersectionSceneQuery; |
---|
59 | class OctreeRaySceneQuery; |
---|
60 | class OctreeSphereSceneQuery; |
---|
61 | class OctreeAxisAlignedBoxSceneQuery; |
---|
62 | class OctreePlaneBoundedVolumeListSceneQuery; |
---|
63 | |
---|
64 | |
---|
65 | typedef std::list < WireBoundingBox * > BoxList; |
---|
66 | typedef std::list < unsigned long > ColorList; |
---|
67 | //typedef std::list < SceneNode * > SceneNodeList; |
---|
68 | |
---|
69 | |
---|
70 | /** Specialized SceneManager that divides the geometry into an octree in order to facilitate spatial queries. |
---|
71 | @remarks |
---|
72 | */ |
---|
73 | |
---|
74 | class _OgreOctreePluginExport OctreeSceneManager : public SceneManager |
---|
75 | { |
---|
76 | friend class OctreeIntersectionSceneQuery; |
---|
77 | friend class OctreeRaySceneQuery; |
---|
78 | friend class OctreeSphereSceneQuery; |
---|
79 | friend class OctreeAxisAlignedBoxSceneQuery; |
---|
80 | friend class OctreePlaneBoundedVolumeListSceneQuery; |
---|
81 | |
---|
82 | public: |
---|
83 | static int intersect_call; |
---|
84 | /** Standard Constructor. Initializes the octree to -10000,-10000,-10000 to 10000,10000,10000 with a depth of 8. */ |
---|
85 | OctreeSceneManager(const String& name); |
---|
86 | /** Standard Constructor */ |
---|
87 | OctreeSceneManager(const String& name, AxisAlignedBox &box, int max_depth ); |
---|
88 | /** Standard destructor */ |
---|
89 | ~OctreeSceneManager(); |
---|
90 | |
---|
91 | /// @copydoc SceneManager::getTypeName |
---|
92 | const String& getTypeName(void) const; |
---|
93 | |
---|
94 | /** Initializes the manager to the given box and depth. |
---|
95 | */ |
---|
96 | void init( AxisAlignedBox &box, int d ); |
---|
97 | |
---|
98 | /** Creates a specialized OctreeNode */ |
---|
99 | virtual SceneNode * createSceneNode ( void ); |
---|
100 | /** Creates a specialized OctreeNode */ |
---|
101 | virtual SceneNode * createSceneNode ( const String &name ); |
---|
102 | /** Creates a specialized OctreeCamera */ |
---|
103 | virtual Camera * createCamera( const String &name ); |
---|
104 | |
---|
105 | /** Deletes a scene node */ |
---|
106 | virtual void destroySceneNode( const String &name ); |
---|
107 | |
---|
108 | |
---|
109 | |
---|
110 | /** Does nothing more */ |
---|
111 | virtual void _updateSceneGraph( Camera * cam ); |
---|
112 | /** Recurses through the octree determining which nodes are visible. */ |
---|
113 | virtual void _findVisibleObjects ( Camera * cam, |
---|
114 | VisibleObjectsBoundsInfo* visibleBounds, bool onlyShadowCasters ); |
---|
115 | |
---|
116 | /** Alerts each unculled object, notifying it that it will be drawn. |
---|
117 | * Useful for doing calculations only on nodes that will be drawn, prior |
---|
118 | * to drawing them... |
---|
119 | */ |
---|
120 | virtual void _alertVisibleObjects( void ); |
---|
121 | |
---|
122 | /** Walks through the octree, adding any visible objects to the render queue. |
---|
123 | @remarks |
---|
124 | If any octant in the octree if completely within the view frustum, |
---|
125 | all subchildren are automatically added with no visibility tests. |
---|
126 | */ |
---|
127 | void walkOctree( OctreeCamera *, RenderQueue *, Octree *, |
---|
128 | VisibleObjectsBoundsInfo* visibleBounds, bool foundvisible, |
---|
129 | bool onlyShadowCasters); |
---|
130 | |
---|
131 | /** Checks the given OctreeNode, and determines if it needs to be moved |
---|
132 | * to a different octant. |
---|
133 | */ |
---|
134 | void _updateOctreeNode( OctreeNode * ); |
---|
135 | /** Removes the given octree node */ |
---|
136 | void _removeOctreeNode( OctreeNode * ); |
---|
137 | /** Adds the Octree Node, starting at the given octree, and recursing at max to the specified depth. |
---|
138 | */ |
---|
139 | void _addOctreeNode( OctreeNode *, Octree *octree, int depth = 0 ); |
---|
140 | |
---|
141 | /** Recurses the octree, adding any nodes intersecting with the box into the given list. |
---|
142 | It ignores the exclude scene node. |
---|
143 | */ |
---|
144 | void findNodesIn( const AxisAlignedBox &box, std::list < SceneNode * > &list, SceneNode *exclude = 0 ); |
---|
145 | |
---|
146 | /** Recurses the octree, adding any nodes intersecting with the sphere into the given list. |
---|
147 | It ignores the exclude scene node. |
---|
148 | */ |
---|
149 | void findNodesIn( const Sphere &sphere, std::list < SceneNode * > &list, SceneNode *exclude = 0 ); |
---|
150 | |
---|
151 | /** Recurses the octree, adding any nodes intersecting with the volume into the given list. |
---|
152 | It ignores the exclude scene node. |
---|
153 | */ |
---|
154 | void findNodesIn( const PlaneBoundedVolume &volume, std::list < SceneNode * > &list, SceneNode *exclude=0 ); |
---|
155 | |
---|
156 | /** Recurses the octree, adding any nodes intersecting with the ray into the given list. |
---|
157 | It ignores the exclude scene node. |
---|
158 | */ |
---|
159 | void findNodesIn( const Ray &ray, std::list < SceneNode * > &list, SceneNode *exclude=0 ); |
---|
160 | |
---|
161 | /** Sets the box visibility flag */ |
---|
162 | void setShowBoxes( bool b ) |
---|
163 | { |
---|
164 | mShowBoxes = b; |
---|
165 | }; |
---|
166 | |
---|
167 | void setLooseOctree( bool b ) |
---|
168 | { |
---|
169 | mLoose = b; |
---|
170 | }; |
---|
171 | |
---|
172 | |
---|
173 | /** Resizes the octree to the given size */ |
---|
174 | void resize( const AxisAlignedBox &box ); |
---|
175 | |
---|
176 | /** Sets the given option for the SceneManager |
---|
177 | @remarks |
---|
178 | Options are: |
---|
179 | "Size", AxisAlignedBox *; |
---|
180 | "Depth", int *; |
---|
181 | "ShowOctree", bool *; |
---|
182 | */ |
---|
183 | |
---|
184 | virtual bool setOption( const String &, const void * ); |
---|
185 | /** Gets the given option for the Scene Manager. |
---|
186 | @remarks |
---|
187 | See setOption |
---|
188 | */ |
---|
189 | virtual bool getOption( const String &, void * ); |
---|
190 | |
---|
191 | bool getOptionValues( const String & key, StringVector &refValueList ); |
---|
192 | bool getOptionKeys( StringVector &refKeys ); |
---|
193 | /** Overridden from SceneManager */ |
---|
194 | void clearScene(void); |
---|
195 | |
---|
196 | AxisAlignedBoxSceneQuery* createAABBQuery(const AxisAlignedBox& box, unsigned long mask); |
---|
197 | SphereSceneQuery* createSphereQuery(const Sphere& sphere, unsigned long mask); |
---|
198 | PlaneBoundedVolumeListSceneQuery* createPlaneBoundedVolumeQuery(const PlaneBoundedVolumeList& volumes, unsigned long mask); |
---|
199 | RaySceneQuery* createRayQuery(const Ray& ray, unsigned long mask); |
---|
200 | IntersectionSceneQuery* createIntersectionQuery(unsigned long mask); |
---|
201 | |
---|
202 | |
---|
203 | protected: |
---|
204 | |
---|
205 | |
---|
206 | NodeList mVisible; |
---|
207 | |
---|
208 | /// The root octree |
---|
209 | Octree *mOctree; |
---|
210 | |
---|
211 | /// List of boxes to be rendered |
---|
212 | BoxList mBoxes; |
---|
213 | |
---|
214 | /// Number of rendered objs |
---|
215 | int mNumObjects; |
---|
216 | |
---|
217 | /// Max depth for the tree |
---|
218 | int mMaxDepth; |
---|
219 | /// Size of the octree |
---|
220 | AxisAlignedBox mBox; |
---|
221 | |
---|
222 | /// Boxes visibility flag |
---|
223 | bool mShowBoxes; |
---|
224 | |
---|
225 | |
---|
226 | bool mLoose; |
---|
227 | |
---|
228 | Real mCorners[ 24 ]; |
---|
229 | static unsigned long mColors[ 8 ]; |
---|
230 | static unsigned short mIndexes[ 24 ]; |
---|
231 | |
---|
232 | Matrix4 mScaleFactor; |
---|
233 | |
---|
234 | }; |
---|
235 | |
---|
236 | /// Factory for OctreeSceneManager |
---|
237 | class OctreeSceneManagerFactory : public SceneManagerFactory |
---|
238 | { |
---|
239 | protected: |
---|
240 | void initMetaData(void) const; |
---|
241 | public: |
---|
242 | OctreeSceneManagerFactory() {} |
---|
243 | ~OctreeSceneManagerFactory() {} |
---|
244 | /// Factory type name |
---|
245 | static const String FACTORY_TYPE_NAME; |
---|
246 | SceneManager* createInstance(const String& instanceName); |
---|
247 | void destroyInstance(SceneManager* instance); |
---|
248 | }; |
---|
249 | |
---|
250 | |
---|
251 | |
---|
252 | } |
---|
253 | |
---|
254 | #endif |
---|
255 | |
---|