source: GTP/trunk/Lib/Geom/OgreStuff/include/opt/OgreOctreeSceneManager.h @ 1809

Revision 1809, 8.4 KB checked in by gumbau, 18 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#include "OgreSceneManager.h"
38#include "OgreRenderOperation.h"
39#include "OgreSphere.h"
40
41#include <list>
42#include <algorithm>
43
44#include <OgreOctree.h>
45
46
47namespace Ogre
48{
49
50class OctreeNode;
51
52class OctreeCamera;
53class OctreeIntersectionSceneQuery;
54class OctreeRaySceneQuery;
55class OctreeSphereSceneQuery;
56class OctreeAxisAlignedBoxSceneQuery;
57class OctreePlaneBoundedVolumeListSceneQuery;
58
59
60typedef std::list < WireBoundingBox * > BoxList;
61typedef std::list < unsigned long > ColorList;
62//typedef std::list < SceneNode * > SceneNodeList;
63
64
65/** Specialized SceneManager that divides the geometry into an octree in order to faciliate spatial queries.
66@remarks
67For debugging purposes, a special "CullCamera" can be defined.  To use it, call setUseCallCamera( true ),
68and create a camera named "CullCamera".  All culling will be performed using that camera, instead of the viewport
69camera, allowing you to fly around and examine culling.
70*/
71
72class OctreeSceneManager : public SceneManager
73{
74    friend class OctreeIntersectionSceneQuery;
75    friend class OctreeRaySceneQuery;
76    friend class OctreeSphereSceneQuery;
77    friend class OctreeAxisAlignedBoxSceneQuery;
78    friend class OctreePlaneBoundedVolumeListSceneQuery;
79
80public:
81    static int intersect_call;
82    /** Standard Constructor.  Initializes the octree to -500,-500,-500 to 500,500,500 with unlimited depth. */
83    OctreeSceneManager(const String& name);
84    /** Standard Constructor */
85    OctreeSceneManager(const String& name, AxisAlignedBox &box, int max_depth );
86    /** Standard desctructor */
87    ~OctreeSceneManager();
88
89        /// @copydoc SceneManager::getTypeName
90        const String& getTypeName(void) const;
91
92    /** Initializeds the manager to the given box and depth.
93    */
94    void init( AxisAlignedBox &box, int d );
95
96    /** Creates a specialized OctreeNode */
97    virtual     SceneNode * createSceneNode ( void );
98    /** Creates a specialized OctreeNode */
99    virtual SceneNode * createSceneNode ( const String &name );
100    /** Creates a specialized OctreeCamera */
101    virtual Camera * createCamera( const String &name );
102
103    /** Deletes a scene node */
104    virtual void destroySceneNode( const String &name );
105
106
107
108    /** Does nothing more */
109    virtual void _updateSceneGraph( Camera * cam );
110    /** Recurses through the octree determining which nodes are visible. */
111    virtual void _findVisibleObjects ( Camera * cam, bool onlyShadowCasters );
112
113    /** Alerts each unculled object, notifying it that it will be drawn.
114     * Useful for doing calculations only on nodes that will be drawn, prior
115     * to drawing them...
116     */
117    virtual void _alertVisibleObjects( void );
118
119    /** Walks through the octree, adding any visible objects to the render queue.
120    @remarks
121    If any octant in the octree if completely within the the view frustum,
122    all subchildren are automatically added with no visibility tests.
123    */
124    void walkOctree( OctreeCamera *, RenderQueue *, Octree *, bool foundvisible,
125                     bool onlyShadowCasters);
126
127    /** Checks the given OctreeNode, and determines if it needs to be moved
128    * to a different octant.
129    */
130    void _updateOctreeNode( OctreeNode * );
131    /** Removes the given octree node */
132    void _removeOctreeNode( OctreeNode * );
133    /** Adds the Octree Node, starting at the given octree, and recursing at max to the specified depth.
134    */
135    void _addOctreeNode( OctreeNode *, Octree *octree, int depth = 0 );
136
137    /** Recurses the octree, adding any nodes intersecting with the box into the given list.
138    It ignores the exclude scene node.
139    */
140    void findNodesIn( const AxisAlignedBox &box, std::list < SceneNode * > &list, SceneNode *exclude = 0 );
141
142    /** Recurses the octree, adding any nodes intersecting with the sphere into the given list.
143    It ignores the exclude scene node.
144    */
145    void findNodesIn( const Sphere &sphere, std::list < SceneNode * > &list, SceneNode *exclude = 0 );
146
147    /** Recurses the octree, adding any nodes intersecting with the volume into the given list.
148      It ignores the exclude scene node.
149      */
150    void findNodesIn( const PlaneBoundedVolume &volume, std::list < SceneNode * > &list, SceneNode *exclude=0 );
151
152    /** Recurses the octree, adding any nodes intersecting with the ray into the given list.
153      It ignores the exclude scene node.
154      */
155    void findNodesIn( const Ray &ray, std::list < SceneNode * > &list, SceneNode *exclude=0 );
156
157    /** Sets the box visibility flag */
158    void setShowBoxes( bool b )
159    {
160        mShowBoxes = b;
161    };
162
163    /** Sets the cull camera flag */
164    void setUseCullCamera( bool b )
165    {
166        mCullCamera = b;
167    };
168
169    void setLooseOctree( bool b )
170    {
171        mLoose = b;
172    };
173
174
175    /** Resizes the octree to the given size */
176    void resize( const AxisAlignedBox &box );
177
178    /** Sets the given option for the SceneManager
179               @remarks
180        Options are:
181        "Size", AxisAlignedBox *;
182        "CullCamera", bool *;
183        "Depth", int *;
184        "ShowOctree", bool *;
185    */
186
187    virtual bool setOption( const String &, const void * );
188    /** Gets the given option for the Scene Manager.
189        @remarks
190        See setOption
191    */
192    virtual bool getOption( const String &, void * );
193
194    bool getOptionValues( const String & key, StringVector &refValueList );
195    bool getOptionKeys( StringVector &refKeys );
196    /** Overridden from SceneManager */
197    void clearScene(void);
198
199    AxisAlignedBoxSceneQuery* createAABBQuery(const AxisAlignedBox& box, unsigned long mask);
200    SphereSceneQuery* createSphereQuery(const Sphere& sphere, unsigned long mask);
201    PlaneBoundedVolumeListSceneQuery* createPlaneBoundedVolumeQuery(const PlaneBoundedVolumeList& volumes, unsigned long mask);
202    RaySceneQuery* createRayQuery(const Ray& ray, unsigned long mask);
203    IntersectionSceneQuery* createIntersectionQuery(unsigned long mask);
204
205
206protected:
207
208
209    NodeList mVisible;
210
211    /// The root octree
212    Octree *mOctree;
213
214    /// list of boxes to be rendered
215    BoxList mBoxes;
216
217    /// number of rendered objs
218    int mNumObjects;
219
220    /// max depth for the tree.
221    int mMaxDepth;
222    /// Size of the octree
223    AxisAlignedBox mBox;
224
225    /// box visibility flag
226    bool mShowBoxes;
227
228    /// cull camera flag
229    bool mCullCamera;
230
231
232    bool mLoose;
233
234    Real mCorners[ 24 ];
235    static unsigned long mColors[ 8 ];
236    static unsigned short mIndexes[ 24 ];
237
238    Matrix4 mScaleFactor;
239
240};
241
242/// Factory for OctreeSceneManager
243class OctreeSceneManagerFactory : public SceneManagerFactory
244{
245protected:
246        void initMetaData(void) const;
247public:
248        OctreeSceneManagerFactory() {}
249        ~OctreeSceneManagerFactory() {}
250        /// Factory type name
251        static const String FACTORY_TYPE_NAME;
252        SceneManager* createInstance(const String& instanceName);
253        void destroyInstance(SceneManager* instance);
254};
255
256
257
258}
259
260#endif
261
Note: See TracBrowser for help on using the repository browser.