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/
7
Copyright (c) 2000-2006 The OGRE Team
8
Also see acknowledgements in Readme.html
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
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.
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
-----------------------------------------------------------------------------
25
/***************************************************************************
26
PagingLandScapeOctree.h - description
28
begin : Mon Sep 30 2002
29
copyright : (C) 2002 by Jon Anderson
30
email : janders@users.sf.net
32
Enhancements 2003 - 2004 (C) The OGRE Team
33
***************************************************************************/
35
#ifndef __PagingLandScapeOctree_H
36
#define __PagingLandScapeOctree_H
39
#include "OgreAxisAlignedBox.h"
40
#include "OgrePagingLandScapeOcclusionElement.h"
41
#include "OgrePagingLandScapeOcclusionTraversal.h"
48
class PagingLandScapeOctreeNode;
50
typedef std::list < PagingLandScapeOctreeNode* > NodeList;
53
/** PagingLandScapeOctree data structure for managing scene nodes.
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.
61
class PagingLandScapeOctree : public OcclusionElement
65
PagingLandScapeOctree();
66
~PagingLandScapeOctree(void);
70
void setParent(PagingLandScapeOctree * parent);
71
void setSceneManager(PagingLandScapeOctreeSceneManager * scn);
73
/** Adds an PagingLandScapeOctree scene node to this PagingLandScapeOctree level.
75
This is called by the PagingLandScapeOctreeSceneManager after
76
it has determined the correct PagingLandScapeOctree to insert the node into.
78
void _addNode(PagingLandScapeOctreeNode* nod);
80
/** Removes an PagingLandScapeOctree scene node to this PagingLandScapeOctree level.
82
void _removeNode(PagingLandScapeOctreeNode* nod);
84
/** Returns the number of scene nodes attached to this PagingLandScapeOctree
86
inline size_t numNodes(void) const
93
/** creates the wire frame bounding box for this octant
95
WireBoundingBox* getWireBoundingBox(void);
97
/** creates the opaque Cull bounding box (bbox*2) for this octant
99
OcclusionBoundingBox* getOcclusionBoundingBox();
102
/** 3D array of children of this PagingLandScapeOctree.
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.
107
PagingLandScapeOctree* mChildren[ 2 ][ 2 ][ 2 ];
109
/** Determines if this PagingLandScapeOctree is twice as big as the given box.
111
This method is used by the PagingLandScapeOctreeSceneManager to determine if the given
112
box will fit into a child of this PagingLandScapeOctree.
114
bool _isTwiceSize(const AxisAlignedBox& box) const;
116
/** Determines if this PagingLandScapeOctree is twice as big as the given box.
118
This method is used by the PagingLandScapeOctreeSceneManager to determine if the given
119
box will fit into a child of this PagingLandScapeOctree.
121
bool _isTwiceCullSize(const AxisAlignedBox& box) const;
123
bool _isNotCrossingAxes(const AxisAlignedBox& box) const;
125
/** Returns the appropriate indexes for the child of this PagingLandScapeOctree into which the box will fit.
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.
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.
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.
138
PagingLandScapeOctree *_getCullChildWhereBoxFits(const AxisAlignedBox& bx, PagingLandScapeOctreeSceneManager *scn);
139
/** Creates the AxisAlignedBox used for culling this PagingLandScapeOctree.
141
Since it's a loose PagingLandScapeOctree, the culling bounds can be different than the actual bounds of the PagingLandScapeOctree.
143
void _getCullBounds(AxisAlignedBox* bound) const;
145
/** Public list of SceneNodes attached to this particular PagingLandScapeOctree
148
NodeList mMovingNodes;
149
NodeList mStaticNodes;
151
inline OcclusionElement* getParent () {return mParent;};
153
inline bool isLeaf() const {return false;};
155
inline void traversal(Traversal &tr, VisibleObjectsBoundsInfo * const visibleBounds)
157
tr.onTree (*this, visibleBounds);
159
inline void traversal(const TraversalConst &tr, VisibleObjectsBoundsInfo * const visibleBounds)
161
tr.onTree(*this, visibleBounds);
163
inline void traversal(const ConstTraversalConst &tr, VisibleObjectsBoundsInfo * const visibleBounds) const
165
tr.onTree (*this, visibleBounds);
168
// check if need to traverse it.
169
inline bool hasChildren() const
171
return (mNumNodes != 0);
174
void setBoundingBox(const Vector3 &min, const Vector3 &max);
176
#ifdef _VISIBILITYDEBUG
177
void setDebugCorners(PagingLandScapeOctreeSceneManager *scnMgr);
178
#endif //_VISIBILITYDEBUG
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;};
185
inline bool isOccluder () const { return true; }
189
/** The bounding box of the PagingLandScapeOctree
191
This is used for octant index determination and rendering, but not culling
194
/// Octree double size bounding box
195
AxisAlignedBox mCullBox;
196
WireBoundingBox* mWireBoundingBox;
197
/** Vector containing the dimensions of this PagingLandScapeOctree
200
/** Vector containing the dimensions of this PagingLandScapeOctree / 2
202
Vector3 mCullHalfSize;
205
/** Increments the overall node count of this PagingLandScapeOctree and all it's parents
207
inline void _ref(void)
216
/** Decrements the overall node count of this PagingLandScapeOctree and all it's parents
218
void _unref(const bool removeChildren);
220
///number of SceneNodes in this PagingLandScapeOctree and all it's children.
222
///parent PagingLandScapeOctree
223
PagingLandScapeOctree* mParent;
224
PagingLandScapeOctreeSceneManager *mSceneMgr;
225
OcclusionBoundingBox* mOcclusionBoundingBox;