source: OGRE/trunk/ogre_changes/obsolete/Plugins/OctreeSceneManager/include/OgreOctreeSceneManager.h @ 316

Revision 316, 9.2 KB checked in by mattausch, 19 years ago (diff)

queries are realized as templates

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( );
91    /** Standard Constructor */
92    OctreeSceneManager( AxisAlignedBox &box, int max_depth );
93    /** Standard desctructor */
94    ~OctreeSceneManager();
95
96    /** Initializeds the manager to the given box and depth.
97    */
98    void init( AxisAlignedBox &box, int d );
99
100    /** Creates a specialized OctreeNode */
101    virtual     SceneNode * createSceneNode ( void );
102    /** Creates a specialized OctreeNode */
103    virtual SceneNode * createSceneNode ( const String &name );
104    /** Creates a specialized OctreeCamera */
105    virtual Camera * createCamera( const String &name );
106
107    /** Deletes a scene node */
108    virtual void destroySceneNode( const String &name );
109
110#ifdef GTP_VISIBILITY_MODIFIED_OGRE
111        /** Renders one octant of an octree, i.e., renders current octant
112                node and does not traverse deeper into the tree.
113
114                @remark Note that OctreeNode instances are NOT part of the octree
115                hierarchy, instead one octant of an Octree contains many OctreeNode instances.
116               
117                @param cam current camera
118                @param octree the octant to be rendered (without children)
119                @param onlyShadowCasters if only shadow casters are rendered
120                @param passes if passes should be left in queue for later processing
121        */
122        void _renderOctant(Camera* cam, Octree *octree, bool onlyShadowCasters,
123                const int leavePassesInQueue = 0);
124
125        /** Returns stored list of boxes */
126        BoxList *getBoxes();
127#endif // GTP_VISIBILITY_MODIFIED_OGRE
128
129
130    /** Does nothing more */
131    virtual void _updateSceneGraph( Camera * cam );
132    /** Recurses through the octree determining which nodes are visible. */
133    virtual void _findVisibleObjects ( Camera * cam, bool onlyShadowCasters );
134
135    /** Alerts each unculled object, notifying it that it will be drawn.
136     * Useful for doing calculations only on nodes that will be drawn, prior
137     * to drawing them...
138     */
139    virtual void _alertVisibleObjects( void );
140
141    /** Walks through the octree, adding any visible objects to the render queue.
142    @remarks
143    If any octant in the octree if completely within the the view frustum,
144    all subchildren are automatically added with no visibility tests.
145    */
146    void walkOctree( OctreeCamera *, RenderQueue *, Octree *, bool foundvisible,
147                     bool onlyShadowCasters);
148
149    /** Checks the given OctreeNode, and determines if it needs to be moved
150    * to a different octant.
151    */
152    void _updateOctreeNode( OctreeNode * );
153    /** Removes the given octree node */
154    void _removeOctreeNode( OctreeNode * );
155    /** Adds the Octree Node, starting at the given octree, and recursing at max to the specified depth.
156    */
157    void _addOctreeNode( OctreeNode *, Octree *octree, int depth = 0 );
158
159    /** Recurses the octree, adding any nodes intersecting with the box into the given list.
160    It ignores the exclude scene node.
161    */
162    void findNodesIn( const AxisAlignedBox &box, std::list < SceneNode * > &list, SceneNode *exclude = 0 );
163
164    /** Recurses the octree, adding any nodes intersecting with the sphere into the given list.
165    It ignores the exclude scene node.
166    */
167    void findNodesIn( const Sphere &sphere, std::list < SceneNode * > &list, SceneNode *exclude = 0 );
168
169    /** Recurses the octree, adding any nodes intersecting with the volume into the given list.
170      It ignores the exclude scene node.
171      */
172    void findNodesIn( const PlaneBoundedVolume &volume, std::list < SceneNode * > &list, SceneNode *exclude=0 );
173
174    /** Recurses the octree, adding any nodes intersecting with the ray into the given list.
175      It ignores the exclude scene node.
176      */
177    void findNodesIn( const Ray &ray, std::list < SceneNode * > &list, SceneNode *exclude=0 );
178
179    /** Sets the box visibility flag */
180    void setShowBoxes( bool b )
181    {
182        mShowBoxes = b;
183    };
184
185    /** Sets the cull camera flag */
186    void setUseCullCamera( bool b )
187    {
188        mCullCamera = b;
189    };
190
191    void setLooseOctree( bool b )
192    {
193        mLoose = b;
194    };
195
196
197    /** Resizes the octree to the given size */
198    void resize( const AxisAlignedBox &box );
199
200    /** Sets the given option for the SceneManager
201               @remarks
202        Options are:
203        "Size", AxisAlignedBox *;
204        "CullCamera", bool *;
205        "Depth", int *;
206        "ShowOctree", bool *;
207    */
208
209    virtual bool setOption( const String &, const void * );
210    /** Gets the given option for the Scene Manager.
211        @remarks
212        See setOption
213    */
214    virtual bool getOption( const String &, void * );
215
216    bool getOptionValues( const String & key, StringVector &refValueList );
217    bool getOptionKeys( StringVector &refKeys );
218    /** Overridden from SceneManager */
219    void clearScene(void);
220
221    AxisAlignedBoxSceneQuery* OctreeSceneManager::createAABBQuery(const AxisAlignedBox& box, unsigned long mask);
222    SphereSceneQuery* OctreeSceneManager::createSphereQuery(const Sphere& sphere, unsigned long mask);
223    PlaneBoundedVolumeListSceneQuery* createPlaneBoundedVolumeQuery(const PlaneBoundedVolumeList& volumes, unsigned long mask);
224    RaySceneQuery* createRayQuery(const Ray& ray, unsigned long mask);
225    IntersectionSceneQuery* createIntersectionQuery(unsigned long mask);
226
227
228protected:
229
230
231    NodeList mVisible;
232
233    /// The root octree
234    Octree *mOctree;
235
236    /// list of boxes to be rendered
237    BoxList mBoxes;
238
239    /// number of rendered objs
240    int mNumObjects;
241
242    /// max depth for the tree.
243    int mMaxDepth;
244    /// Size of the octree
245    AxisAlignedBox mBox;
246
247    /// box visibility flag
248    bool mShowBoxes;
249
250    /// cull camera flag
251    bool mCullCamera;
252
253
254    bool mLoose;
255
256    Real mCorners[ 24 ];
257    static unsigned long mColors[ 8 ];
258    static unsigned short mIndexes[ 24 ];
259
260    Matrix4 mScaleFactor;
261
262#ifdef GTP_VISIBILITY_MODIFIED_OGRE
263        /** The number of nodes in the octree.
264                @remark counts the octree hierarchy nodes in the tree.
265        */
266        int mNumOctants;
267#endif // GTP_VISIBILITY_MODIFIED_OGRE
268
269};
270
271
272}
273
274#endif
275
Note: See TracBrowser for help on using the repository browser.