[61] | 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 "OgreTerrainPrerequisites.h"
|
---|
| 39 | #include <OgreAxisAlignedBox.h>
|
---|
| 40 | #include <OgreWireBoundingBox.h>
|
---|
| 41 |
|
---|
| 42 | #include <list>
|
---|
| 43 |
|
---|
| 44 | namespace Ogre
|
---|
| 45 | {
|
---|
| 46 |
|
---|
| 47 | class OctreeNode;
|
---|
| 48 |
|
---|
| 49 | typedef std::list < OctreeNode * > NodeList;
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 | /** Octree datastructure for managing scene nodes.
|
---|
| 53 | @remarks
|
---|
| 54 | This is a loose octree implementation, meaning that each
|
---|
| 55 | octant child of the octree actually overlaps it's siblings by a factor
|
---|
| 56 | of .5. This guarantees that any thing that is half the size of the parent will
|
---|
| 57 | fit completely into a child, with no splitting necessary.
|
---|
| 58 | */
|
---|
| 59 |
|
---|
| 60 | class _OgreTerrainExport Octree
|
---|
| 61 | {
|
---|
| 62 | public:
|
---|
| 63 | Octree( Octree * p );
|
---|
| 64 | ~Octree();
|
---|
| 65 |
|
---|
| 66 | /** Adds an Octree scene node to this octree level.
|
---|
| 67 | @remarks
|
---|
| 68 | This is called by the OctreeSceneManager after
|
---|
| 69 | it has determined the correct Octree to insert the node into.
|
---|
| 70 | */
|
---|
| 71 | void _addNode( OctreeNode * );
|
---|
| 72 |
|
---|
| 73 | /** Removes an Octree scene node to this octree level.
|
---|
| 74 | */
|
---|
| 75 | void _removeNode( OctreeNode * );
|
---|
| 76 |
|
---|
| 77 | /** Returns the number of scene nodes attached to this octree
|
---|
| 78 | */
|
---|
| 79 | int numNodes()
|
---|
| 80 | {
|
---|
| 81 | return mNumNodes;
|
---|
| 82 | };
|
---|
| 83 |
|
---|
| 84 | /** The bounding box of the octree
|
---|
| 85 | @remarks
|
---|
| 86 | This is used for octant index determination and rendering, but not culling
|
---|
| 87 | */
|
---|
| 88 | AxisAlignedBox mBox;
|
---|
| 89 | WireBoundingBox* mWireBoundingBox;
|
---|
| 90 |
|
---|
| 91 | /** Creats the wire frame bounding box for this octant
|
---|
| 92 | */
|
---|
| 93 | WireBoundingBox* getWireBoundingBox();
|
---|
| 94 |
|
---|
| 95 | /** Vector containing the dimensions of this octree / 2
|
---|
| 96 | */
|
---|
| 97 | Vector3 mHalfSize;
|
---|
| 98 |
|
---|
| 99 | /** 3D array of children of this octree.
|
---|
| 100 | @remarks
|
---|
| 101 | Children are dynamically created as needed when nodes are inserted in the Octree.
|
---|
| 102 | If, later, the all the nodes are removed from the child, it is still kept arround.
|
---|
| 103 | */
|
---|
| 104 | Octree * mChildren[ 2 ][ 2 ][ 2 ];
|
---|
| 105 |
|
---|
| 106 | /** Determines if this octree is twice as big as the given box.
|
---|
| 107 | @remarks
|
---|
| 108 | This method is used by the OctreeSceneManager to determine if the given
|
---|
| 109 | box will fit into a child of this octree.
|
---|
| 110 | */
|
---|
| 111 | bool _isTwiceSize( AxisAlignedBox &box );
|
---|
| 112 |
|
---|
| 113 | /** Returns the appropriate indexes for the child of this octree into which the box will fit.
|
---|
| 114 | @remarks
|
---|
| 115 | This is used by the OCtreeSceneManager to determine which child to traverse next when
|
---|
| 116 | finding the appropriate octree to insert the box. Since it is a loose octree, only the
|
---|
| 117 | center of the box is checked to determine the octant.
|
---|
| 118 | */
|
---|
| 119 | void _getChildIndexes( AxisAlignedBox &, int *x, int *y, int *z );
|
---|
| 120 |
|
---|
| 121 | /** Creates the AxisAlignedBox used for culling this octree.
|
---|
| 122 | @remarks
|
---|
| 123 | Since it's a loose octree, the culling bounds can be different than the actual bounds of the octree.
|
---|
| 124 | */
|
---|
| 125 | void _getCullBounds( AxisAlignedBox * );
|
---|
| 126 |
|
---|
| 127 |
|
---|
| 128 | /** Public list of SceneNodes attached to this particular octree
|
---|
| 129 | */
|
---|
| 130 | NodeList mNodes;
|
---|
| 131 |
|
---|
| 132 | protected:
|
---|
| 133 |
|
---|
| 134 | /** Increments the overall node count of this octree and all it's parents
|
---|
| 135 | */
|
---|
| 136 | inline void _ref()
|
---|
| 137 | {
|
---|
| 138 | mNumNodes++;
|
---|
| 139 |
|
---|
| 140 | if ( mParent != 0 ) mParent -> _ref();
|
---|
| 141 | };
|
---|
| 142 |
|
---|
| 143 | /** Decrements the overall node count of this octree and all it's parents
|
---|
| 144 | */
|
---|
| 145 | inline void _unref()
|
---|
| 146 | {
|
---|
| 147 | mNumNodes--;
|
---|
| 148 |
|
---|
| 149 | if ( mParent != 0 ) mParent -> _unref();
|
---|
| 150 | };
|
---|
| 151 |
|
---|
| 152 | ///number of SceneNodes in this octree and all it's children.
|
---|
| 153 | int mNumNodes;
|
---|
| 154 |
|
---|
| 155 | ///parent octree
|
---|
| 156 | Octree * mParent;
|
---|
| 157 |
|
---|
| 158 | #ifdef OGRE_COHERENT_OCCLUSION_CULLING
|
---|
| 159 | public:
|
---|
| 160 | /** Returns last visited frame id. */
|
---|
| 161 | int lastVisited(void);
|
---|
| 162 | /** Set to current frame id.
|
---|
| 163 | @param current frame id.
|
---|
| 164 | */
|
---|
| 165 | void setLastVisited(int frameid);
|
---|
| 166 | /** Makes this octree become visible / invisble.
|
---|
| 167 | @param visible Whether this node is to be made visible or invisible
|
---|
| 168 | */
|
---|
| 169 | void setOctreeVisible(bool visible);
|
---|
| 170 | /** Returns true if this node is marked visible, false otherwise.
|
---|
| 171 | */
|
---|
| 172 | bool isOctreeVisible(void);
|
---|
| 173 | /** Gets this node's parent (NULL if this is the root).
|
---|
| 174 | */
|
---|
| 175 | Octree *getParent();
|
---|
| 176 | /** Frame id when this octree was last rendered.
|
---|
| 177 | @return last rendered frame id
|
---|
| 178 | */
|
---|
| 179 | int lastRendered(void);
|
---|
| 180 | /** Sets frame id when this octree was last rendered.
|
---|
| 181 | @param last rendered frame id
|
---|
| 182 | */
|
---|
| 183 | void setLastRendered(int frameid);
|
---|
| 184 | /** Returns current depth of octree
|
---|
| 185 | @return current depth
|
---|
| 186 | */
|
---|
| 187 | int getDepth();
|
---|
| 188 |
|
---|
| 189 | protected:
|
---|
| 190 |
|
---|
| 191 | int mLastRendered;
|
---|
| 192 | int mLastVisited;
|
---|
| 193 | bool mVisible;
|
---|
| 194 | int mDepth;
|
---|
| 195 |
|
---|
| 196 | #endif //OGRE_COHERENT_OCCLUSION_CULLING
|
---|
| 197 | };
|
---|
| 198 |
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | #endif
|
---|
| 202 |
|
---|
| 203 |
|
---|