[1812] | 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-2005 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 | octree.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 OCTREE_H
|
---|
| 36 | #define OCTREE_H
|
---|
| 37 |
|
---|
| 38 | #include <OgreAxisAlignedBox.h>
|
---|
| 39 | #include <OgreWireBoundingBox.h>
|
---|
| 40 |
|
---|
| 41 | #include <list>
|
---|
| 42 |
|
---|
| 43 | namespace Ogre
|
---|
| 44 | {
|
---|
| 45 |
|
---|
| 46 | class OctreeNode;
|
---|
| 47 |
|
---|
| 48 | typedef std::list < OctreeNode * > NodeList;
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 | /** Octree datastructure for managing scene nodes.
|
---|
| 52 | @remarks
|
---|
| 53 | This is a loose octree implementation, meaning that each
|
---|
| 54 | octant child of the octree actually overlaps it's siblings by a factor
|
---|
| 55 | of .5. This guarantees that any thing that is half the size of the parent will
|
---|
| 56 | fit completely into a child, with no splitting necessary.
|
---|
| 57 | */
|
---|
| 58 |
|
---|
| 59 | class Octree
|
---|
| 60 | {
|
---|
| 61 | public:
|
---|
| 62 | Octree( Octree * p );
|
---|
| 63 | ~Octree();
|
---|
| 64 |
|
---|
| 65 | /** Adds an Octree scene node to this octree level.
|
---|
| 66 | @remarks
|
---|
| 67 | This is called by the OctreeSceneManager after
|
---|
| 68 | it has determined the correct Octree to insert the node into.
|
---|
| 69 | */
|
---|
| 70 | void _addNode( OctreeNode * );
|
---|
| 71 |
|
---|
| 72 | /** Removes an Octree scene node to this octree level.
|
---|
| 73 | */
|
---|
| 74 | void _removeNode( OctreeNode * );
|
---|
| 75 |
|
---|
| 76 | /** Returns the number of scene nodes attached to this octree
|
---|
| 77 | */
|
---|
| 78 | int numNodes()
|
---|
| 79 | {
|
---|
| 80 | return mNumNodes;
|
---|
| 81 | };
|
---|
| 82 |
|
---|
| 83 | /** The bounding box of the octree
|
---|
| 84 | @remarks
|
---|
| 85 | This is used for octant index determination and rendering, but not culling
|
---|
| 86 | */
|
---|
| 87 | AxisAlignedBox mBox;
|
---|
| 88 | WireBoundingBox* mWireBoundingBox;
|
---|
| 89 |
|
---|
| 90 | /** Creats the wire frame bounding box for this octant
|
---|
| 91 | */
|
---|
| 92 | WireBoundingBox* getWireBoundingBox();
|
---|
| 93 |
|
---|
| 94 | /** Vector containing the dimensions of this octree / 2
|
---|
| 95 | */
|
---|
| 96 | Vector3 mHalfSize;
|
---|
| 97 |
|
---|
| 98 | /** 3D array of children of this octree.
|
---|
| 99 | @remarks
|
---|
| 100 | Children are dynamically created as needed when nodes are inserted in the Octree.
|
---|
| 101 | If, later, the all the nodes are removed from the child, it is still kept arround.
|
---|
| 102 | */
|
---|
| 103 | Octree * mChildren[ 2 ][ 2 ][ 2 ];
|
---|
| 104 |
|
---|
| 105 | /** Determines if this octree is twice as big as the given box.
|
---|
| 106 | @remarks
|
---|
| 107 | This method is used by the OctreeSceneManager to determine if the given
|
---|
| 108 | box will fit into a child of this octree.
|
---|
| 109 | */
|
---|
| 110 | bool _isTwiceSize( const AxisAlignedBox &box ) const;
|
---|
| 111 |
|
---|
| 112 | /** Returns the appropriate indexes for the child of this octree into which the box will fit.
|
---|
| 113 | @remarks
|
---|
| 114 | This is used by the OCtreeSceneManager to determine which child to traverse next when
|
---|
| 115 | finding the appropriate octree to insert the box. Since it is a loose octree, only the
|
---|
| 116 | center of the box is checked to determine the octant.
|
---|
| 117 | */
|
---|
| 118 | void _getChildIndexes( const AxisAlignedBox &, int *x, int *y, int *z ) const;
|
---|
| 119 |
|
---|
| 120 | /** Creates the AxisAlignedBox used for culling this octree.
|
---|
| 121 | @remarks
|
---|
| 122 | Since it's a loose octree, the culling bounds can be different than the actual bounds of the octree.
|
---|
| 123 | */
|
---|
| 124 | void _getCullBounds( AxisAlignedBox * ) const;
|
---|
| 125 |
|
---|
| 126 |
|
---|
| 127 | /** Public list of SceneNodes attached to this particular octree
|
---|
| 128 | */
|
---|
| 129 | NodeList mNodes;
|
---|
| 130 |
|
---|
| 131 | protected:
|
---|
| 132 |
|
---|
| 133 | /** Increments the overall node count of this octree and all it's parents
|
---|
| 134 | */
|
---|
| 135 | inline void _ref()
|
---|
| 136 | {
|
---|
| 137 | mNumNodes++;
|
---|
| 138 |
|
---|
| 139 | if ( mParent != 0 ) mParent -> _ref();
|
---|
| 140 | };
|
---|
| 141 |
|
---|
| 142 | /** Decrements the overall node count of this octree and all it's parents
|
---|
| 143 | */
|
---|
| 144 | inline void _unref()
|
---|
| 145 | {
|
---|
| 146 | mNumNodes--;
|
---|
| 147 |
|
---|
| 148 | if ( mParent != 0 ) mParent -> _unref();
|
---|
| 149 | };
|
---|
| 150 |
|
---|
| 151 | ///number of SceneNodes in this octree and all it's children.
|
---|
| 152 | int mNumNodes;
|
---|
| 153 |
|
---|
| 154 | ///parent octree
|
---|
| 155 | Octree * mParent;
|
---|
| 156 |
|
---|
| 157 | };
|
---|
| 158 |
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | #endif
|
---|
| 162 |
|
---|
| 163 |
|
---|