From 91abdd3ed4925497eba8304ed7ae4f9ab58f3a83 Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Thu, 10 Feb 2011 00:14:21 +0000 Subject: [PATCH] camera max height/ default are calculated based on the max height of a map --- source/glest_game/game/game.cpp | 4 ++++ source/glest_game/game/game_camera.cpp | 13 +++++++++++-- source/glest_game/game/game_camera.h | 6 ++++++ source/glest_game/world/map.cpp | 5 +++++ source/glest_game/world/map.h | 2 ++ 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index aa4ed4f5..3fe000f6 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -549,6 +549,10 @@ void Game::init(bool initForPreviewOnly) gameCamera.init(map->getW(), map->getH()); + if(gameCamera.getCalculatedDefault()getMaxMapHeight()+13.0f){ + gameCamera.setCalculatedDefault(map->getMaxMapHeight()+13.0f); + } + if(world.getThisFaction() != NULL) { const Vec2i &v= map->getStartLocation(world.getThisFaction()->getStartLocationIndex()); gameCamera.setPos(Vec2f(v.x, v.y)); diff --git a/source/glest_game/game/game_camera.cpp b/source/glest_game/game/game_camera.cpp index 2ac12417..8c79df7e 100644 --- a/source/glest_game/game/game_camera.cpp +++ b/source/glest_game/game/game_camera.cpp @@ -46,6 +46,7 @@ const float GameCamera::centerOffsetZ= 8.0f; GameCamera::GameCamera() : pos(0.f, defaultHeight, 0.f), destPos(0.f, defaultHeight, 0.f), destAng(startingVAng, startingHAng) { Config &config = Config::getInstance(); + calculatedDefault=defaultHeight; state= sGame; cacheVisibleQuad.clear(); @@ -88,6 +89,14 @@ void GameCamera::setMaxHeight(float value) { } } +void GameCamera::setCalculatedDefault(float calculatedDefault){ + this->calculatedDefault= calculatedDefault; + if(maxHeight>0 && maxHeightlimitX= limitX; this->limitY= limitY; @@ -239,7 +248,7 @@ void GameCamera::switchState(){ state= sGame; destAng.x = startingVAng; destAng.y = startingHAng; - destPos.y = defaultHeight; + destPos.y = calculatedDefault; } } @@ -247,7 +256,7 @@ void GameCamera::resetPosition(){ state= sGame; destAng.x = startingVAng; destAng.y = startingHAng; - destPos.y = defaultHeight; + destPos.y = calculatedDefault; } void GameCamera::centerXZ(float x, float z){ diff --git a/source/glest_game/game/game_camera.h b/source/glest_game/game/game_camera.h index 9f6a31a9..84687304 100644 --- a/source/glest_game/game/game_camera.h +++ b/source/glest_game/game/game_camera.h @@ -83,6 +83,8 @@ private: float maxVAng; float fov; + float calculatedDefault; + int MaxVisibleQuadItemCache; public: @@ -130,6 +132,10 @@ public: void setClampBounds(bool value) { clampBounds = value; } void setMaxHeight(float value); + float getCalculatedDefault() const{ return calculatedDefault; } + void setCalculatedDefault(float calculatedDefault); + + float getMaxHeight() const {return maxHeight;} void setFov(float value) { fov = value; } void setMinVAng(float value) { minVAng = value; } void setMaxVAng(float value) { maxVAng = value; } diff --git a/source/glest_game/world/map.cpp b/source/glest_game/world/map.cpp index 1d02cf9b..f67fa007 100644 --- a/source/glest_game/world/map.cpp +++ b/source/glest_game/world/map.cpp @@ -273,6 +273,7 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) { void Map::init(Tileset *tileset) { Logger::getInstance().add("Heightmap computations", true); + maxMapHeight=0.0f; smoothSurface(tileset); computeNormals(); computeInterpolatedHeights(); @@ -1094,6 +1095,7 @@ void Map::computeInterpolatedHeights(){ void Map::smoothSurface(Tileset *tileset) { float *oldHeights = new float[getSurfaceCellArraySize()]; + int arraySize=getSurfaceCellArraySize(); for (int i = 0; i < getSurfaceCellArraySize(); ++i) { oldHeights[i] = surfaceCells[i].getHeight(); @@ -1135,6 +1137,9 @@ void Map::smoothSurface(Tileset *tileset) { } height /= numUsedToSmooth; + if(maxMapHeightsetHeight(height); Object *object = getSurfaceCell(i, j)->getObject(); diff --git a/source/glest_game/world/map.h b/source/glest_game/world/map.h index dd3bd9a9..0a8bb8f6 100755 --- a/source/glest_game/world/map.h +++ b/source/glest_game/world/map.h @@ -166,6 +166,7 @@ private: SurfaceCell *surfaceCells; Vec2i *startLocations; Checksum checksumValue; + float maxMapHeight; private: Map(Map&); @@ -194,6 +195,7 @@ public: float getHeightFactor() const {return heightFactor;} float getWaterLevel() const {return waterLevel;} float getCliffLevel() const {return cliffLevel;} + float getMaxMapHeight() const {return maxMapHeight;} Vec2i getStartLocation(int locationIndex) const; bool getSubmerged(const SurfaceCell *sc) const {return sc->getHeight()getHeight()