source: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBiTerrainPage.cpp @ 2348

Revision 2348, 4.5 KB checked in by vizrt_christian_seidl, 17 years ago (diff)

Added: BIHierarchy SceneManager?

BITerrain SceneManager?

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#include "OgreBiTerrainPage.h"
26#include "OgreBiTerrainRenderable.h"
27
28namespace Ogre {
29
30    //-------------------------------------------------------------------------
31    BiTerrainPage::BiTerrainPage(unsigned short numTiles)
32    {
33        tilesPerPage = numTiles;
34        // Set up an empty array of TerrainRenderable pointers
35        int i, j;
36        for ( i = 0; i < tilesPerPage; i++ )
37        {
38            tiles.push_back( BiTerrainRow() );
39
40            for ( j = 0; j < tilesPerPage; j++ )
41            {
42                tiles[ i ].push_back( 0 );
43            }
44        }
45
46        pageSceneNode = 0;
47
48    }
49    //-------------------------------------------------------------------------
50    BiTerrainPage::~BiTerrainPage()
51    {
52        BiTerrain2D::iterator i, iend;
53        iend = tiles.end();
54        for (i = tiles.begin(); i != iend; ++i)
55        {
56            BiTerrainRow::iterator j, jend;
57            jend = i->end();
58            for (j = i->begin(); j != jend; ++j)
59            {
60                delete *j;
61                *j = 0;
62            }
63        }
64
65    }
66    //-------------------------------------------------------------------------
67    void BiTerrainPage::linkNeighbours(void)
68    {
69        //setup the neighbor links.
70
71        for ( size_t j = 0; j < tilesPerPage; j++ )
72        {
73            for ( size_t i = 0; i < tilesPerPage; i++ )
74            {
75                if ( j != tilesPerPage - 1 )
76                {
77                    tiles[ i ][ j ] -> _setNeighbor( BiTerrainRenderable::SOUTH, tiles[ i ][ j + 1 ] );
78                    tiles[ i ][ j + 1 ] -> _setNeighbor( BiTerrainRenderable::NORTH, tiles[ i ][ j ] );
79                }
80
81                if ( i != tilesPerPage - 1 )
82                {
83                    tiles[ i ][ j ] -> _setNeighbor( BiTerrainRenderable::EAST, tiles[ i + 1 ][ j ] );
84                    tiles[ i + 1 ][ j ] -> _setNeighbor( BiTerrainRenderable::WEST, tiles[ i ][ j ] );
85                }
86
87            }
88        }
89    }
90    //-------------------------------------------------------------------------
91    BiTerrainRenderable * BiTerrainPage::getTerrainTile( const Vector3 & pt )
92    {
93        /* Since we don't know if the terrain is square, or has holes, we use a line trace
94        to find the containing tile...
95        */
96
97        BiTerrainRenderable * tile = tiles[ 0 ][ 0 ];
98
99        while ( tile != 0 )
100        {
101            AxisAlignedBox b = tile -> getBoundingBox();
102            const Vector3 *corners = b.getAllCorners();
103
104            if ( pt.x < corners[ 0 ].x )
105                tile = tile -> _getNeighbor( BiTerrainRenderable::WEST );
106            else if ( pt.x > corners[ 4 ].x )
107                tile = tile -> _getNeighbor( BiTerrainRenderable::EAST );
108            else if ( pt.z < corners[ 0 ].z )
109                tile = tile -> _getNeighbor( BiTerrainRenderable::NORTH );
110            else if ( pt.z > corners[ 4 ].z )
111                tile = tile -> _getNeighbor( BiTerrainRenderable::SOUTH );
112            else
113                return tile;
114        }
115
116        return 0;
117    }
118        //-------------------------------------------------------------------------
119        void BiTerrainPage::setRenderQueue(uint8 qid)
120        {
121                for ( size_t j = 0; j < tilesPerPage; j++ )
122                {
123                        for ( size_t i = 0; i < tilesPerPage; i++ )
124                        {
125                                if ( j != tilesPerPage - 1 )
126                                {
127                                        tiles[ i ][ j ]->setRenderQueueGroup(qid);
128                                }
129                        }
130                }
131        }
132
133}
134
Note: See TracBrowser for help on using the repository browser.