From a13edbdb428b26d9cb79e698a66e71ca262307fd Mon Sep 17 00:00:00 2001 From: Nelsson Huotari Date: Tue, 22 Oct 2019 20:58:23 +0300 Subject: [PATCH] Bump shape calculation to function --- apps/opencs/view/render/terrainshapemode.cpp | 15 ++++++++++----- apps/opencs/view/render/terrainshapemode.hpp | 3 +++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/opencs/view/render/terrainshapemode.cpp b/apps/opencs/view/render/terrainshapemode.cpp index 174a7beb24..8bdd96ad8f 100644 --- a/apps/opencs/view/render/terrainshapemode.cpp +++ b/apps/opencs/view/render/terrainshapemode.cpp @@ -391,6 +391,12 @@ void CSVRender::TerrainShapeMode::applyTerrainEditChanges() mAlteredCells.clear(); } +float CSVRender::TerrainShapeMode::calculateBumpShape(const float& distance, int radius, const float& height) +{ + float distancePerRadius = distance / radius; + return height - height * (3 * distancePerRadius * distancePerRadius - 2 * distancePerRadius * distancePerRadius * distancePerRadius); +} + void CSVRender::TerrainShapeMode::editTerrainShapeGrid(const std::pair& vertexCoords, bool dragOperation) { int r = mBrushSize / 2; @@ -451,15 +457,14 @@ void CSVRender::TerrainShapeMode::editTerrainShapeGrid(const std::pair { cellId = CSMWorld::CellCoordinates::vertexGlobalToCellId(std::make_pair(i, j)); cellCoords = CSMWorld::CellCoordinates::fromId(cellId).first; + int x = CSMWorld::CellCoordinates::vertexGlobalToInCellCoords(i); + int y = CSMWorld::CellCoordinates::vertexGlobalToInCellCoords(j); int distanceX = abs(i - vertexCoords.first); int distanceY = abs(j - vertexCoords.second); float distance = sqrt(pow(distanceX, 2)+pow(distanceY, 2)); - int x = CSMWorld::CellCoordinates::vertexGlobalToInCellCoords(i); - int y = CSMWorld::CellCoordinates::vertexGlobalToInCellCoords(j); - float distancePerRadius = 1.0f * distance / r; float smoothedByDistance = 0.0f; - if (mShapeEditTool == ShapeEditTool_Drag) smoothedByDistance = mTotalDiffY - mTotalDiffY * (3 * distancePerRadius * distancePerRadius - 2 * distancePerRadius * distancePerRadius * distancePerRadius); - if (mShapeEditTool == ShapeEditTool_PaintToRaise || mShapeEditTool == ShapeEditTool_PaintToLower) smoothedByDistance = (r + mShapeEditToolStrength) - (r + mShapeEditToolStrength) * (3 * distancePerRadius * distancePerRadius - 2 * distancePerRadius * distancePerRadius * distancePerRadius); + if (mShapeEditTool == ShapeEditTool_Drag) smoothedByDistance = calculateBumpShape(distance, r, mTotalDiffY); + if (mShapeEditTool == ShapeEditTool_PaintToRaise || mShapeEditTool == ShapeEditTool_PaintToLower) smoothedByDistance = calculateBumpShape(distance, r, r + mShapeEditToolStrength); if (distance <= r) { if (mShapeEditTool == ShapeEditTool_Drag) alterHeight(cellCoords, x, y, smoothedByDistance); diff --git a/apps/opencs/view/render/terrainshapemode.hpp b/apps/opencs/view/render/terrainshapemode.hpp index 0f987c88b6..6e6589c86b 100644 --- a/apps/opencs/view/render/terrainshapemode.hpp +++ b/apps/opencs/view/render/terrainshapemode.hpp @@ -101,6 +101,9 @@ namespace CSVRender /// Handle brush mechanics for shape editing void editTerrainShapeGrid (const std::pair& vertexCoords, bool dragOperation); + /// Calculate height, when aiming for bump-shaped terrain change + float calculateBumpShape(const float& distance, int radius, const float& height); + /// set the target height for flatten tool void setFlattenToolTargetHeight(const WorldspaceHitResult& hit);