source: OGRE/trunk/ogre_changes/Ogre1.2/PlugIns/OctreeSceneManager/include/OgreOctreeSceneManager.h @ 2257

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