[692] | 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 | #include "OgreTerrainPage.h"
|
---|
| 26 | #include "OgreTerrainRenderable.h"
|
---|
| 27 |
|
---|
| 28 | namespace Ogre {
|
---|
| 29 |
|
---|
| 30 | //-------------------------------------------------------------------------
|
---|
| 31 | TerrainPage::TerrainPage(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( TerrainRow() );
|
---|
| 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 | TerrainPage::~TerrainPage()
|
---|
| 51 | {
|
---|
| 52 | Terrain2D::iterator i, iend;
|
---|
| 53 | iend = tiles.end();
|
---|
| 54 | for (i = tiles.begin(); i != iend; ++i)
|
---|
| 55 | {
|
---|
| 56 | TerrainRow::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 TerrainPage::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( TerrainRenderable::SOUTH, tiles[ i ][ j + 1 ] );
|
---|
| 78 | tiles[ i ][ j + 1 ] -> _setNeighbor( TerrainRenderable::NORTH, tiles[ i ][ j ] );
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | if ( i != tilesPerPage - 1 )
|
---|
| 82 | {
|
---|
| 83 | tiles[ i ][ j ] -> _setNeighbor( TerrainRenderable::EAST, tiles[ i + 1 ][ j ] );
|
---|
| 84 | tiles[ i + 1 ][ j ] -> _setNeighbor( TerrainRenderable::WEST, tiles[ i ][ j ] );
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 | //-------------------------------------------------------------------------
|
---|
| 91 | TerrainRenderable * TerrainPage::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 | TerrainRenderable * 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( TerrainRenderable::WEST );
|
---|
| 106 | else if ( pt.x > corners[ 4 ].x )
|
---|
| 107 | tile = tile -> _getNeighbor( TerrainRenderable::EAST );
|
---|
| 108 | else if ( pt.z < corners[ 0 ].z )
|
---|
| 109 | tile = tile -> _getNeighbor( TerrainRenderable::NORTH );
|
---|
| 110 | else if ( pt.z > corners[ 4 ].z )
|
---|
| 111 | tile = tile -> _getNeighbor( TerrainRenderable::SOUTH );
|
---|
| 112 | else
|
---|
| 113 | return tile;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | return 0;
|
---|
| 117 | }
|
---|
| 118 | //-------------------------------------------------------------------------
|
---|
| 119 | void TerrainPage::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 |
|
---|