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