source: GTP/trunk/App/Demos/Geom/OgreStuff/include/opt/OgreOctreeSceneManager.h @ 1092

Revision 1092, 8.0 KB checked in by gumbau, 18 years ago (diff)

LodStrips? and LODTrees demos

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( );
84    /** Standard Constructor */
85    OctreeSceneManager( AxisAlignedBox &box, int max_depth );
86    /** Standard desctructor */
87    ~OctreeSceneManager();
88
89    /** Initializeds the manager to the given box and depth.
90    */
91    void init( AxisAlignedBox &box, int d );
92
93    /** Creates a specialized OctreeNode */
94    virtual     SceneNode * createSceneNode ( void );
95    /** Creates a specialized OctreeNode */
96    virtual SceneNode * createSceneNode ( const String &name );
97    /** Creates a specialized OctreeCamera */
98    virtual Camera * createCamera( const String &name );
99
100    /** Deletes a scene node */
101    virtual void destroySceneNode( const String &name );
102
103
104
105    /** Does nothing more */
106    virtual void _updateSceneGraph( Camera * cam );
107    /** Recurses through the octree determining which nodes are visible. */
108    virtual void _findVisibleObjects ( Camera * cam, bool onlyShadowCasters );
109
110    /** Alerts each unculled object, notifying it that it will be drawn.
111     * Useful for doing calculations only on nodes that will be drawn, prior
112     * to drawing them...
113     */
114    virtual void _alertVisibleObjects( void );
115
116    /** Walks through the octree, adding any visible objects to the render queue.
117    @remarks
118    If any octant in the octree if completely within the the view frustum,
119    all subchildren are automatically added with no visibility tests.
120    */
121    void walkOctree( OctreeCamera *, RenderQueue *, Octree *, bool foundvisible,
122                     bool onlyShadowCasters);
123
124    /** Checks the given OctreeNode, and determines if it needs to be moved
125    * to a different octant.
126    */
127    void _updateOctreeNode( OctreeNode * );
128    /** Removes the given octree node */
129    void _removeOctreeNode( OctreeNode * );
130    /** Adds the Octree Node, starting at the given octree, and recursing at max to the specified depth.
131    */
132    void _addOctreeNode( OctreeNode *, Octree *octree, int depth = 0 );
133
134    /** Recurses the octree, adding any nodes intersecting with the box into the given list.
135    It ignores the exclude scene node.
136    */
137    void findNodesIn( const AxisAlignedBox &box, std::list < SceneNode * > &list, SceneNode *exclude = 0 );
138
139    /** Recurses the octree, adding any nodes intersecting with the sphere into the given list.
140    It ignores the exclude scene node.
141    */
142    void findNodesIn( const Sphere &sphere, std::list < SceneNode * > &list, SceneNode *exclude = 0 );
143
144    /** Recurses the octree, adding any nodes intersecting with the volume into the given list.
145      It ignores the exclude scene node.
146      */
147    void findNodesIn( const PlaneBoundedVolume &volume, std::list < SceneNode * > &list, SceneNode *exclude=0 );
148
149    /** Recurses the octree, adding any nodes intersecting with the ray into the given list.
150      It ignores the exclude scene node.
151      */
152    void findNodesIn( const Ray &ray, std::list < SceneNode * > &list, SceneNode *exclude=0 );
153
154    /** Sets the box visibility flag */
155    void setShowBoxes( bool b )
156    {
157        mShowBoxes = b;
158    };
159
160    /** Sets the cull camera flag */
161    void setUseCullCamera( bool b )
162    {
163        mCullCamera = b;
164    };
165
166    void setLooseOctree( bool b )
167    {
168        mLoose = b;
169    };
170
171
172    /** Resizes the octree to the given size */
173    void resize( const AxisAlignedBox &box );
174
175    /** Sets the given option for the SceneManager
176               @remarks
177        Options are:
178        "Size", AxisAlignedBox *;
179        "CullCamera", bool *;
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* OctreeSceneManager::createAABBQuery(const AxisAlignedBox& box, unsigned long mask);
197    SphereSceneQuery* OctreeSceneManager::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
203protected:
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    /// box visibility flag
223    bool mShowBoxes;
224
225    /// cull camera flag
226    bool mCullCamera;
227
228
229    bool mLoose;
230
231    Real mCorners[ 24 ];
232    static unsigned long mColors[ 8 ];
233    static unsigned short mIndexes[ 24 ];
234
235    Matrix4 mScaleFactor;
236
237};
238
239
240}
241
242#endif
243
Note: See TracBrowser for help on using the repository browser.