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

Revision 921, 9.6 KB checked in by mattausch, 18 years ago (diff)

added updates for visibility

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