fixed minimap generation

This commit is contained in:
devZoGok
2026-05-03 11:25:54 +03:00
parent 304ced2ca3
commit 80302ccfc5
7 changed files with 16 additions and 6 deletions
+16 -6
View File
@@ -64,15 +64,25 @@ namespace battleship{
}
else{
map->load(name);
int numPlayers = map->getNumSpawnPoints();
int numVerts = 3 * map->getNodeParent()->getChild(0)->getMesh(0)->getMeshBase().numTris;
oldLandmassVertHeights = new float[numVerts];
for(int i = 0; i < numPlayers; i++)
game->addPlayer(new Player(0, 0, 0, Vector3(1, 1, 1)));
map->loadPlayersGameObjects();
MeshData meshData = map->getNodeParent()->getChild(0)->getMesh(0)->getMeshBase();
int minId = 0, numVerts = 3 * meshData.numTris;
oldLandmassVertHeights = new float[numVerts];
for(int i = 0; i < numVerts; i++){
oldLandmassVertHeights[i] = meshData.vertices[i].pos->y;
if(oldLandmassVertHeights[i] < oldLandmassVertHeights[minId])
minId = i;
}
map->setBaseHeight(oldLandmassVertHeights[minId]);
}
}
@@ -412,16 +422,16 @@ namespace battleship{
Vector3 mapSize = map->getMapSize(), cellSize = map->getCellSize();
int width = int(mapSize.x / cellSize.x);
int height = int(mapSize.z / cellSize.z);
int numChannels = 3;
int cellId = 0, 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;
float bottomCellHeight = cells[cellId].pos.y - map->getCellSize().y * cells[cellId].underWaterCellIds.size();
float heightFactor = min + (max - min) * (bottomCellHeight - baseHeight) / mapSize.y;
Vector3 color = (cells[cellId].type == Map::Cell::Type::WATER ? Vector3::VEC_K : Vector3::VEC_J);
*p = color.x * heightFactor * 255.f;