From 24977fcc0f9d7358f07be1d6de6ec3ffd8903ceb Mon Sep 17 00:00:00 2001 From: Nelsson Huotari Date: Sun, 29 Apr 2018 13:33:00 +0300 Subject: [PATCH] improve hit calculation accuracy for texture editing --- apps/opencs/view/render/terraintexturemode.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/opencs/view/render/terraintexturemode.cpp b/apps/opencs/view/render/terraintexturemode.cpp index 5e1b6afb8..97856c20c 100644 --- a/apps/opencs/view/render/terraintexturemode.cpp +++ b/apps/opencs/view/render/terraintexturemode.cpp @@ -307,8 +307,20 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe int cellY = cellCoordinates_pair.first.getY(); // The coordinates of hit in mCellId - int xHitInCell ((hit.worldPos.x() - (cellX* cellSize)) * landTextureSize / cellSize); - int yHitInCell ((hit.worldPos.y() - (cellY* cellSize)) * landTextureSize / cellSize); + int xHitInCell (float(((hit.worldPos.x() - (cellX* cellSize)) * landTextureSize / cellSize) - 0.5)); + int yHitInCell (float(((hit.worldPos.y() - (cellY* cellSize)) * landTextureSize / cellSize) + 0.5)); + if (xHitInCell < 0) + { + xHitInCell = xHitInCell + landTextureSize; + cellX = cellX - 1; + } + if (yHitInCell > 15) + { + yHitInCell = yHitInCell - landTextureSize; + cellY = cellY + 1; + } + + mCellId = "#" + std::to_string(cellX) + " " + std::to_string(cellY); std::string iteratedCellId;