~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/SceneManagers/EmberPagingSceneManager/include/OgrePagingLandScapeOctree.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
-----------------------------------------------------------------------------
 
3
This source file is part of OGRE
 
4
(Object-oriented Graphics Rendering Engine)
 
5
For the latest info, see http://www.ogre3d.org/
 
6
 
 
7
Copyright (c) 2000-2006 The OGRE Team
 
8
Also see acknowledgements in Readme.html
 
9
 
 
10
This program is free software; you can redistribute it and/or modify it under
 
11
the terms of the GNU Lesser General Public License as published by the Free Software
 
12
Foundation; either version 2 of the License, or (at your option) any later
 
13
version.
 
14
 
 
15
This program is distributed in the hope that it will be useful, but WITHOUT
 
16
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
17
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 
18
 
 
19
You should have received a copy of the GNU Lesser General Public License along with
 
20
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
21
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
 
22
http://www.gnu.org/copyleft/lesser.txt.
 
23
-----------------------------------------------------------------------------
 
24
*/
 
25
/***************************************************************************
 
26
PagingLandScapeOctree.h  -  description
 
27
-------------------
 
28
begin                : Mon Sep 30 2002
 
29
copyright            : (C) 2002 by Jon Anderson
 
30
email                : janders@users.sf.net
 
31
 
 
32
Enhancements 2003 - 2004 (C) The OGRE Team
 
33
***************************************************************************/
 
34
 
 
35
#ifndef __PagingLandScapeOctree_H
 
36
#define __PagingLandScapeOctree_H
 
37
 
 
38
 
 
39
#include "OgreAxisAlignedBox.h"
 
40
#include "OgrePagingLandScapeOcclusionElement.h"
 
41
#include "OgrePagingLandScapeOcclusionTraversal.h"
 
42
 
 
43
#include <list>
 
44
 
 
45
namespace Ogre
 
46
{
 
47
 
 
48
        class PagingLandScapeOctreeNode;
 
49
 
 
50
        typedef std::list < PagingLandScapeOctreeNode* > NodeList;
 
51
 
 
52
 
 
53
        /** PagingLandScapeOctree data structure for managing scene nodes.
 
54
        @remarks
 
55
                This is a loose PagingLandScapeOctree implementation, meaning that each
 
56
                octant child of the PagingLandScapeOctree actually overlaps it's siblings by a factor
 
57
                of .5.  This guarantees that any thing that is half the size of the parent will
 
58
                fit completely into a child, with no splitting necessary.
 
59
        */
 
60
 
 
61
    class PagingLandScapeOctree : public OcclusionElement
 
62
        {
 
63
 
 
64
            public:
 
65
            PagingLandScapeOctree();
 
66
            ~PagingLandScapeOctree(void);
 
67
 
 
68
            void reset();
 
69
 
 
70
            void setParent(PagingLandScapeOctree * parent);
 
71
            void setSceneManager(PagingLandScapeOctreeSceneManager * scn);
 
72
 
 
73
                    /** Adds an PagingLandScapeOctree scene node to this PagingLandScapeOctree level.
 
74
                    @remarks
 
75
                            This is called by the PagingLandScapeOctreeSceneManager after
 
76
                            it has determined the correct PagingLandScapeOctree to insert the node into.
 
77
                    */
 
78
                    void _addNode(PagingLandScapeOctreeNode* nod);
 
79
 
 
80
                /** Removes an PagingLandScapeOctree scene node to this PagingLandScapeOctree level.
 
81
                */
 
82
                void _removeNode(PagingLandScapeOctreeNode* nod);
 
83
 
 
84
                    /** Returns the number of scene nodes attached to this PagingLandScapeOctree
 
85
                    */
 
86
                    inline size_t numNodes(void) const
 
87
                    {
 
88
                    return mNumNodes;
 
89
                };
 
90
 
 
91
        
 
92
        
 
93
                    /** creates the wire frame bounding box for this octant
 
94
                    */
 
95
                    WireBoundingBox* getWireBoundingBox(void);
 
96
 
 
97
                    /** creates the opaque Cull bounding box (bbox*2) for this octant
 
98
                    */
 
99
                    OcclusionBoundingBox* getOcclusionBoundingBox();
 
100
 
 
101
 
 
102
                    /** 3D array of children of this PagingLandScapeOctree.
 
103
                    @remarks
 
104
                            Children are dynamically created as needed when nodes are inserted in the PagingLandScapeOctree.
 
105
                            If, later, the all the nodes are removed from the child, it is still kept around.
 
106
                    */
 
107
                    PagingLandScapeOctree* mChildren[ 2 ][ 2 ][ 2 ];
 
108
 
 
109
                    /** Determines if this PagingLandScapeOctree is twice as big as the given box.
 
110
                    @remarks
 
111
                            This method is used by the PagingLandScapeOctreeSceneManager to determine if the given
 
112
                            box will fit into a child of this PagingLandScapeOctree.
 
113
                    */
 
114
                    bool _isTwiceSize(const AxisAlignedBox& box) const;
 
115
 
 
116
            /** Determines if this PagingLandScapeOctree is twice as big as the given box.
 
117
                    @remarks
 
118
                            This method is used by the PagingLandScapeOctreeSceneManager to determine if the given
 
119
                            box will fit into a child of this PagingLandScapeOctree.
 
120
                    */
 
121
                    bool _isTwiceCullSize(const AxisAlignedBox& box) const;
 
122
 
 
123
            bool _isNotCrossingAxes(const AxisAlignedBox& box) const;
 
124
 
 
125
                    /**  Returns the appropriate indexes for the child of this PagingLandScapeOctree into which the box will fit.
 
126
                    @remarks
 
127
                            This is used by the PagingLandScapeOctreeSceneManager to determine which child to traverse next when
 
128
                            finding the appropriate PagingLandScapeOctree to insert the box.  Since it is a loose PagingLandScapeOctree, only the
 
129
                    center of the box is checked to determine the octant.
 
130
                    */
 
131
                    PagingLandScapeOctree* _getChildWhereBoxFits(const AxisAlignedBox& bx, PagingLandScapeOctreeSceneManager *scn);
 
132
            /**  Returns the appropriate indexes for the child of this PagingLandScapeOctree into which the box will fit.
 
133
                    @remarks
 
134
                            This is used by the PagingLandScapeOctreeSceneManager to determine which child to traverse next when
 
135
                            finding the appropriate PagingLandScapeOctree to insert the box.  Since it is a loose PagingLandScapeOctree, only the
 
136
                    center of the box is checked to determine the octant.
 
137
                    */
 
138
            PagingLandScapeOctree *_getCullChildWhereBoxFits(const AxisAlignedBox& bx, PagingLandScapeOctreeSceneManager *scn);
 
139
                    /** Creates the AxisAlignedBox used for culling this PagingLandScapeOctree.
 
140
                    @remarks
 
141
                            Since it's a loose PagingLandScapeOctree, the culling bounds can be different than the actual bounds of the PagingLandScapeOctree.
 
142
                    */
 
143
                    void _getCullBounds(AxisAlignedBox* bound) const;
 
144
 
 
145
                    /** Public list of SceneNodes attached to this particular PagingLandScapeOctree
 
146
                    */
 
147
                    NodeList mNodes;
 
148
                    NodeList mMovingNodes;
 
149
                    NodeList mStaticNodes;
 
150
 
 
151
            inline OcclusionElement* getParent () {return mParent;};  
 
152
 
 
153
            inline bool isLeaf() const {return false;};
 
154
            
 
155
            inline void traversal(Traversal &tr, VisibleObjectsBoundsInfo * const visibleBounds) 
 
156
            {   
 
157
                tr.onTree (*this, visibleBounds);
 
158
            };
 
159
            inline void traversal(const TraversalConst &tr, VisibleObjectsBoundsInfo * const visibleBounds)
 
160
            {  
 
161
                tr.onTree(*this, visibleBounds);
 
162
            };
 
163
            inline void traversal(const ConstTraversalConst &tr, VisibleObjectsBoundsInfo * const visibleBounds) const
 
164
            {   
 
165
                tr.onTree (*this, visibleBounds);
 
166
            };
 
167
 
 
168
            // check if need to traverse it.
 
169
            inline bool hasChildren() const
 
170
            {
 
171
                return (mNumNodes != 0);
 
172
            };
 
173
 
 
174
            void setBoundingBox(const Vector3 &min,  const Vector3 &max);
 
175
 
 
176
            #ifdef _VISIBILITYDEBUG
 
177
                void setDebugCorners(PagingLandScapeOctreeSceneManager *scnMgr);
 
178
            #endif //_VISIBILITYDEBUG    
 
179
 
 
180
            inline const AxisAlignedBox &getCullBoundingBox() const {return mCullBox;};
 
181
            inline const AxisAlignedBox &getBoundingBox()     const {return mBox;};
 
182
            inline const Vector3        &getHalfSize()        const {return mHalfSize;};
 
183
            inline const Vector3        &getCullHalfSize()    const {return mCullHalfSize;};
 
184
 
 
185
            inline bool isOccluder () const  { return true; }
 
186
 
 
187
            protected:
 
188
 
 
189
                /** The bounding box of the PagingLandScapeOctree
 
190
                    @remarks
 
191
                            This is used for octant index determination and rendering, but not culling
 
192
                    */
 
193
                    AxisAlignedBox mBox;
 
194
                    /// Octree double size bounding box
 
195
                    AxisAlignedBox mCullBox;
 
196
                    WireBoundingBox* mWireBoundingBox;
 
197
                    /** Vector containing the dimensions of this PagingLandScapeOctree 
 
198
                    */
 
199
                    Vector3 mHalfSize;
 
200
                    /** Vector containing the dimensions of this PagingLandScapeOctree / 2
 
201
                    */
 
202
                    Vector3 mCullHalfSize;
 
203
 
 
204
 
 
205
                    /** Increments the overall node count of this PagingLandScapeOctree and all it's parents
 
206
                */
 
207
                inline void _ref(void)
 
208
                    {
 
209
                    ++mNumNodes;
 
210
                            if (mParent != 0)
 
211
                            {
 
212
                                    mParent->_ref();
 
213
                            }
 
214
                    };
 
215
 
 
216
                    /** Decrements the overall node count of this PagingLandScapeOctree and all it's parents
 
217
                    */
 
218
                    void _unref(const bool removeChildren);
 
219
 
 
220
                    ///number of SceneNodes in this PagingLandScapeOctree and all it's children.
 
221
            size_t mNumNodes;
 
222
                    ///parent PagingLandScapeOctree
 
223
                    PagingLandScapeOctree* mParent;
 
224
            PagingLandScapeOctreeSceneManager *mSceneMgr;
 
225
            OcclusionBoundingBox* mOcclusionBoundingBox;
 
226
        };
 
227
 
 
228
}
 
229
 
 
230
#endif