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

Revision 2554, 9.9 KB checked in by mattausch, 17 years ago (diff)

added functions to accumulate render queue and issue it at one point

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 _addOctantToQueue(Camera *cam,
126                                                   Octree *octant,
127                                                   bool onlyShadowCasters,
128                                                   const int leavePassesInQueue);
129
130        void _renderOctant(const int leavePassesInQueue = 0);
131
132        void _renderOctantRecursive(Camera* cam,
133                                                                Octree *octree,
134                                                                bool onlyShadowCasters,
135                                                                const int leavePassesInQueue = 0);
136
137
138        /** Returns stored list of boxes
139        */
140        BoxList *getBoxes();
141
142#endif // GTP_VISIBILITY_MODIFIED_OGRE
143
144    /** Does nothing more */
145    virtual void _updateSceneGraph( Camera * cam );
146    /** Recurses through the octree determining which nodes are visible. */
147    virtual void _findVisibleObjects ( Camera * cam, bool onlyShadowCasters );
148
149    /** Alerts each unculled object, notifying it that it will be drawn.
150     * Useful for doing calculations only on nodes that will be drawn, prior
151     * to drawing them...
152     */
153    virtual void _alertVisibleObjects( void );
154
155    /** Walks through the octree, adding any visible objects to the render queue.
156    @remarks
157    If any octant in the octree if completely within the the view frustum,
158    all subchildren are automatically added with no visibility tests.
159    */
160    void walkOctree( OctreeCamera *, RenderQueue *, Octree *, bool foundvisible,
161                     bool onlyShadowCasters);
162
163    /** Checks the given OctreeNode, and determines if it needs to be moved
164    * to a different octant.
165    */
166    void _updateOctreeNode( OctreeNode * );
167    /** Removes the given octree node */
168    void _removeOctreeNode( OctreeNode * );
169    /** Adds the Octree Node, starting at the given octree, and recursing at max to the specified depth.
170    */
171    void _addOctreeNode( OctreeNode *, Octree *octree, int depth = 0 );
172
173    /** Recurses the octree, adding any nodes intersecting with the box into the given list.
174    It ignores the exclude scene node.
175    */
176    void findNodesIn( const AxisAlignedBox &box, std::list < SceneNode * > &list, SceneNode *exclude = 0 );
177
178    /** Recurses the octree, adding any nodes intersecting with the sphere into the given list.
179    It ignores the exclude scene node.
180    */
181    void findNodesIn( const Sphere &sphere, std::list < SceneNode * > &list, SceneNode *exclude = 0 );
182
183    /** Recurses the octree, adding any nodes intersecting with the volume into the given list.
184      It ignores the exclude scene node.
185      */
186    void findNodesIn( const PlaneBoundedVolume &volume, std::list < SceneNode * > &list, SceneNode *exclude=0 );
187
188    /** Recurses the octree, adding any nodes intersecting with the ray into the given list.
189      It ignores the exclude scene node.
190      */
191    void findNodesIn( const Ray &ray, std::list < SceneNode * > &list, SceneNode *exclude=0 );
192
193    /** Sets the box visibility flag */
194    void setShowBoxes( bool b )
195    {
196        mShowBoxes = b;
197    };
198
199    /** Sets the cull camera flag */
200    void setUseCullCamera( bool b )
201    {
202        mCullCamera = b;
203    };
204
205    void setLooseOctree( bool b )
206    {
207        mLoose = b;
208    };
209
210
211    /** Resizes the octree to the given size */
212    void resize( const AxisAlignedBox &box );
213
214    /** Sets the given option for the SceneManager
215               @remarks
216        Options are:
217        "Size", AxisAlignedBox *;
218        "CullCamera", bool *;
219        "Depth", int *;
220        "ShowOctree", bool *;
221    */
222
223    virtual bool setOption( const String &, const void * );
224    /** Gets the given option for the Scene Manager.
225        @remarks
226        See setOption
227    */
228    virtual bool getOption( const String &, void * );
229
230    bool getOptionValues( const String & key, StringVector &refValueList );
231    bool getOptionKeys( StringVector &refKeys );
232    /** Overridden from SceneManager */
233    void clearScene(void);
234
235    AxisAlignedBoxSceneQuery* createAABBQuery(const AxisAlignedBox& box, unsigned long mask);
236    SphereSceneQuery* createSphereQuery(const Sphere& sphere, unsigned long mask);
237    PlaneBoundedVolumeListSceneQuery* createPlaneBoundedVolumeQuery(const PlaneBoundedVolumeList& volumes, unsigned long mask);
238    RaySceneQuery* createRayQuery(const Ray& ray, unsigned long mask);
239    IntersectionSceneQuery* createIntersectionQuery(unsigned long mask);
240
241
242protected:
243
244
245    NodeList mVisible;
246
247    /// The root octree
248    Octree *mOctree;
249
250    /// list of boxes to be rendered
251    BoxList mBoxes;
252
253    /// number of rendered objs
254    int mNumObjects;
255
256    /// max depth for the tree.
257    int mMaxDepth;
258    /// Size of the octree
259    AxisAlignedBox mBox;
260
261    /// box visibility flag
262    bool mShowBoxes;
263
264    /// cull camera flag
265    bool mCullCamera;
266
267
268    bool mLoose;
269
270    Real mCorners[ 24 ];
271    static unsigned long mColors[ 8 ];
272    static unsigned short mIndexes[ 24 ];
273
274    Matrix4 mScaleFactor;
275
276#ifdef GTP_VISIBILITY_MODIFIED_OGRE
277        /** The number of nodes in the octree.
278                @remark counts the octree hierarchy nodes in the tree.
279        */
280        int mNumOctants;
281#endif // GTP_VISIBILITY_MODIFIED_OGRE
282};
283
284/// Factory for OctreeSceneManager
285class OctreeSceneManagerFactory : public SceneManagerFactory
286{
287protected:
288        void initMetaData(void) const;
289public:
290        OctreeSceneManagerFactory() {}
291        ~OctreeSceneManagerFactory() {}
292        /// Factory type name
293        static const String FACTORY_TYPE_NAME;
294        SceneManager* createInstance(const String& instanceName);
295        void destroyInstance(SceneManager* instance);
296};
297
298
299
300}
301
302#endif
303
Note: See TracBrowser for help on using the repository browser.