source: trunk/VUT/work/ogre_changes/Plugins/OctreeSceneManager/include/OgreOctreeSceneManager.h @ 115

Revision 115, 9.0 KB checked in by mattausch, 19 years ago (diff)

added depth pass algorithm + delayed transparent object rendering (so depth ordering is right)

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