From afa4fe31eeaf5f00433e4fa9fe6c8e1015692002 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 22 Sep 2024 15:26:32 +0300 Subject: [PATCH] rendering height data in minimaps --- map.h | 3 +++ mapEditorAppState.cpp | 24 +++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/map.h b/map.h index 6b4980c..c8b2ce8 100755 --- a/map.h +++ b/map.h @@ -64,6 +64,8 @@ namespace battleship{ inline vb01::Node* getLight(int i){return lights[i];} inline std::vector getLights(){return lights;} inline vb01::u8* getOldMinimapImage(){return oldImageData;} + inline float getBaseHeight(){return baseHeight;} + inline void setBaseHeight(float bh){this->baseHeight = bh;} private: std::string mapTable = "map"; vb01::Node *terrainNode = nullptr, *cellNode = nullptr; @@ -72,6 +74,7 @@ namespace battleship{ vb01::Vector3 CELL_SIZE = vb01::Vector3(7, 7, 7), mapSize; std::vector spawnPoints; std::vector cells; + float baseHeight; std::vector lights; vb01::u8 *oldImageData = nullptr; diff --git a/mapEditorAppState.cpp b/mapEditorAppState.cpp index 6e88995..1900032 100644 --- a/mapEditorAppState.cpp +++ b/mapEditorAppState.cpp @@ -191,6 +191,20 @@ namespace battleship{ } mesh->updateVerts(meshData); + + int minId = 0, maxId = 0; + + for(int i = 0; i < numVerts; i++){ + if(verts[i].pos->y < verts[minId].pos->y) + minId = i; + + if(verts[i].pos->y > verts[maxId].pos->y) + maxId = i; + } + + Vector3 mapSize = map->getMapSize(); + map->setBaseHeight(verts[minId].pos->y); + map->setMapSize(Vector3(mapSize.x, verts[maxId].pos->y - verts[minId].pos->y, mapSize.z)); } void MapEditorAppState::MapEditor::generatePlane(Vector2 size){ @@ -404,14 +418,18 @@ namespace battleship{ int numChannels = 3; int size = width * height * numChannels; int cellId = 0; + float baseHeight = map->getBaseHeight(); u8 *imgData = new u8[size]; for(u8 *p = imgData; p != imgData + size; p+= numChannels, cellId++){ + float min = .6, max = 1.; + float heightFactor = min + (max - min) * (cells[cellId].pos.y - baseHeight) / mapSize.y; Vector3 color = (cells[cellId].type == Map::Cell::Type::WATER ? Vector3::VEC_K : Vector3::VEC_J); - *p = color.x * 255.f; - *(p + 1) = color.y * 255.f; - *(p + 2) = color.z * 255.f; + + *p = color.x * heightFactor * 255.f; + *(p + 1) = color.y * heightFactor * 255.f; + *(p + 2) = color.z * heightFactor * 255.f; } stbi_write_jpg(string(mapFolder + "minimap.jpg").c_str(), width, height, numChannels, imgData, 100);