source: OGRE/trunk/ogre_changes/Ogre1.2/PlugIns/OctreeSceneManager/include/OgreOctree.h @ 921

Revision 921, 6.3 KB checked in by mattausch, 19 years ago (diff)

added updates for visibility

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