/src/ogre/PlugIns/OctreeSceneManager/include/OgreOctreeSceneManager.h
Line | Count | Source (jump to first uncovered line) |
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-2014 Torus Knot Software Ltd |
16 | | |
17 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
18 | | of this software and associated documentation files (the "Software"), to deal |
19 | | in the Software without restriction, including without limitation the rights |
20 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
21 | | copies of the Software, and to permit persons to whom the Software is |
22 | | furnished to do so, subject to the following conditions: |
23 | | |
24 | | The above copyright notice and this permission notice shall be included in |
25 | | all copies or substantial portions of the Software. |
26 | | |
27 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
28 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
29 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
30 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
31 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
32 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
33 | | THE SOFTWARE. |
34 | | ----------------------------------------------------------------------------- |
35 | | */ |
36 | | |
37 | | #ifndef OCTREESCENEMANAGER_H |
38 | | #define OCTREESCENEMANAGER_H |
39 | | |
40 | | #include "OgreOctreePrerequisites.h" |
41 | | #include "OgreSceneManager.h" |
42 | | |
43 | | #include <list> |
44 | | #include <algorithm> |
45 | | |
46 | | #include "OgreOctree.h" |
47 | | |
48 | | |
49 | | namespace Ogre |
50 | | { |
51 | | /** \addtogroup Plugins Plugins |
52 | | * @{ |
53 | | */ |
54 | | /** \addtogroup Octree OctreeSceneManager |
55 | | * Octree datastructure for managing scene nodes. |
56 | | * @{ |
57 | | */ |
58 | | class OctreeNode; |
59 | | class OctreeCamera; |
60 | | |
61 | | typedef std::list< WireBoundingBox * > BoxList; |
62 | | typedef std::list< unsigned long > ColorList; |
63 | | |
64 | | /** Specialized SceneManager that divides the geometry into an octree in order to facilitate spatial queries. |
65 | | */ |
66 | | |
67 | | class _OgreOctreePluginExport OctreeSceneManager : public SceneManager |
68 | | { |
69 | | friend class OctreeIntersectionSceneQuery; |
70 | | friend class OctreeRaySceneQuery; |
71 | | friend class OctreeSphereSceneQuery; |
72 | | friend class OctreeAxisAlignedBoxSceneQuery; |
73 | | friend class OctreePlaneBoundedVolumeListSceneQuery; |
74 | | |
75 | | public: |
76 | | static int intersect_call; |
77 | | /** Standard Constructor. Initializes the octree to -10000,-10000,-10000 to 10000,10000,10000 with a depth of 8. */ |
78 | | OctreeSceneManager(const String& name); |
79 | | /** Standard Constructor */ |
80 | | OctreeSceneManager(const String& name, AxisAlignedBox &box, int max_depth ); |
81 | | /** Standard destructor */ |
82 | | ~OctreeSceneManager(); |
83 | | |
84 | | /// @copydoc SceneManager::getTypeName |
85 | | const String& getTypeName(void) const override; |
86 | | |
87 | | /** Initializes the manager to the given box and depth. |
88 | | */ |
89 | | void init( AxisAlignedBox &box, int d ); |
90 | | |
91 | | /** Creates a specialized OctreeNode */ |
92 | | SceneNode * createSceneNodeImpl ( void ) override; |
93 | | /** Creates a specialized OctreeNode */ |
94 | | SceneNode * createSceneNodeImpl ( const String &name ) override; |
95 | | /** Creates a specialized OctreeCamera */ |
96 | | Camera * createCamera( const String &name ) override; |
97 | | |
98 | | /** Deletes a scene node */ |
99 | | void destroySceneNode( const String &name ) override; |
100 | | |
101 | | |
102 | | |
103 | | /** Does nothing more */ |
104 | | void _updateSceneGraph( Camera * cam ) override; |
105 | | /** Recurses through the octree determining which nodes are visible. */ |
106 | | void _findVisibleObjects ( Camera * cam, |
107 | | VisibleObjectsBoundsInfo* visibleBounds, bool onlyShadowCasters ) override; |
108 | | |
109 | | /** Walks through the octree, adding any visible objects to the render queue. |
110 | | |
111 | | If any octant in the octree if completely within the view frustum, |
112 | | all subchildren are automatically added with no visibility tests. |
113 | | */ |
114 | | void walkOctree( OctreeCamera *, RenderQueue *, Octree *, |
115 | | VisibleObjectsBoundsInfo* visibleBounds, bool foundvisible, |
116 | | bool onlyShadowCasters); |
117 | | |
118 | | /** Checks the given OctreeNode, and determines if it needs to be moved |
119 | | * to a different octant. |
120 | | */ |
121 | | void _updateOctreeNode( OctreeNode * ); |
122 | | /** Removes the given octree node */ |
123 | | void _removeOctreeNode( OctreeNode * ); |
124 | | /** Adds the Octree Node, starting at the given octree, and recursing at max to the specified depth. |
125 | | */ |
126 | | void _addOctreeNode( OctreeNode *, Octree *octree, int depth = 0 ); |
127 | | |
128 | | /** Recurses the octree, adding any nodes intersecting with the box into the given list. |
129 | | It ignores the exclude scene node. |
130 | | */ |
131 | | void findNodesIn( const AxisAlignedBox &box, std::list< SceneNode * > &list, SceneNode *exclude = 0 ); |
132 | | |
133 | | /** Recurses the octree, adding any nodes intersecting with the sphere into the given list. |
134 | | It ignores the exclude scene node. |
135 | | */ |
136 | | void findNodesIn( const Sphere &sphere, std::list< SceneNode * > &list, SceneNode *exclude = 0 ); |
137 | | |
138 | | /** Recurses the octree, adding any nodes intersecting with the volume into the given list. |
139 | | It ignores the exclude scene node. |
140 | | */ |
141 | | void findNodesIn( const PlaneBoundedVolume &volume, std::list< SceneNode * > &list, SceneNode *exclude=0 ); |
142 | | |
143 | | /** Recurses the octree, adding any nodes intersecting with the ray into the given list. |
144 | | It ignores the exclude scene node. |
145 | | */ |
146 | | void findNodesIn( const Ray &ray, std::list< SceneNode * > &list, SceneNode *exclude=0 ); |
147 | | |
148 | | /** Sets the box visibility flag */ |
149 | | void setShowBoxes( bool b ) |
150 | 0 | { |
151 | 0 | mShowBoxes = b; |
152 | 0 | }; |
153 | | |
154 | | /** Resizes the octree to the given size */ |
155 | | void resize( const AxisAlignedBox &box ); |
156 | | |
157 | | /** Sets the given option for the SceneManager |
158 | | |
159 | | Options are: |
160 | | "Size", AxisAlignedBox *; |
161 | | "Depth", int *; |
162 | | "ShowOctree", bool *; |
163 | | */ |
164 | | |
165 | | bool setOption( const String &, const void * ) override; |
166 | | /** Gets the given option for the Scene Manager. |
167 | | |
168 | | See setOption |
169 | | */ |
170 | | bool getOption( const String &, void * ) override; |
171 | | |
172 | | bool getOptionValues( const String & key, StringVector &refValueList ) override; |
173 | | bool getOptionKeys( StringVector &refKeys ) override; |
174 | | /** Overridden from SceneManager */ |
175 | | void clearScene(void) override; |
176 | | |
177 | | AxisAlignedBoxSceneQuery* createAABBQuery(const AxisAlignedBox& box, uint32 mask) override; |
178 | | SphereSceneQuery* createSphereQuery(const Sphere& sphere, uint32 mask) override; |
179 | | PlaneBoundedVolumeListSceneQuery* createPlaneBoundedVolumeQuery(const PlaneBoundedVolumeList& volumes, uint32 mask) override; |
180 | | RaySceneQuery* createRayQuery(const Ray& ray, uint32 mask) override; |
181 | | IntersectionSceneQuery* createIntersectionQuery(uint32 mask) override; |
182 | | |
183 | | protected: |
184 | | |
185 | | |
186 | | Octree::NodeList mVisible; |
187 | | |
188 | | /// The root octree |
189 | | Octree *mOctree; |
190 | | |
191 | | /// List of boxes to be rendered |
192 | | BoxList mBoxes; |
193 | | |
194 | | /// Number of rendered objs |
195 | | int mNumObjects; |
196 | | |
197 | | /// Max depth for the tree |
198 | | int mMaxDepth; |
199 | | /// Size of the octree |
200 | | AxisAlignedBox mBox; |
201 | | |
202 | | /// Boxes visibility flag |
203 | | bool mShowBoxes; |
204 | | |
205 | | Real mCorners[ 24 ]; |
206 | | static unsigned long mColors[ 8 ]; |
207 | | static unsigned short mIndexes[ 24 ]; |
208 | | |
209 | | Matrix4 mScaleFactor; |
210 | | |
211 | | }; |
212 | | |
213 | | /// Factory for OctreeSceneManager |
214 | | class OctreeSceneManagerFactory : public SceneManagerFactory |
215 | | { |
216 | | public: |
217 | | /// Factory type name |
218 | | static const String FACTORY_TYPE_NAME; |
219 | | SceneManager* createInstance(const String& instanceName) override; |
220 | 0 | const String& getTypeName(void) const override { return FACTORY_TYPE_NAME; } |
221 | | }; |
222 | | |
223 | | |
224 | | /** @} */ |
225 | | /** @} */ |
226 | | } |
227 | | |
228 | | #endif |
229 | | |