source: trunk/VUT/work/ogre_changes/Plugins/OctreeSceneManager/include/OgreOctree.h @ 135

Revision 135, 6.2 KB checked in by mattausch, 19 years ago (diff)
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25/***************************************************************************
26octree.h  -  description
27-------------------
28begin                : Mon Sep 30 2002
29copyright            : (C) 2002 by Jon Anderson
30email                : janders@users.sf.net
31
32Enhancements 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
44namespace Ogre
45{
46
47class OctreeNode;
48
49typedef std::list < OctreeNode * > NodeList;
50
51
52/** Octree datastructure for managing scene nodes.
53@remarks
54This is a loose octree implementation, meaning that each
55octant child of the octree actually overlaps it's siblings by a factor
56of .5.  This guarantees that any thing that is half the size of the parent will
57fit completely into a child, with no splitting necessary.
58*/
59
60class _OgreTerrainExport Octree
61{
62public:
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
132protected:
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 GTP_VISIBILITY_MODIFIED_OGRE
159public:
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        /** Returns real extent of the octree, i.e., the merged extent of the bounding boxes. */
189        AxisAlignedBox _getWorldAABB(void) const;
190
191        /** Updates bounds of real aabb of octree. */
192        void _updateBounds();
193
194protected:
195       
196        /** the real extent of the octree. */
197        AxisAlignedBox mWorldAABB;
198
199        int mLastRendered;
200        int mLastVisited;
201        bool mVisible;
202        int mDepth;
203
204#endif // GTP_VISIBILITY_MODIFIED_OGRE
205};
206
207}
208
209#endif
210
211
Note: See TracBrowser for help on using the repository browser.