diff --git a/apps/opencs/model/world/cellcoordinates.cpp b/apps/opencs/model/world/cellcoordinates.cpp index 55adc3eff..ce48b5a12 100644 --- a/apps/opencs/model/world/cellcoordinates.cpp +++ b/apps/opencs/model/world/cellcoordinates.cpp @@ -8,13 +8,6 @@ #include #include -namespace -{ - const int cellSize {ESM::Land::REAL_SIZE}; - const int landSize {ESM::Land::LAND_SIZE}; - const int landTextureSize {ESM::Land::LAND_TEXTURE_SIZE}; -} - CSMWorld::CellCoordinates::CellCoordinates() : mX (0), mY (0) {} CSMWorld::CellCoordinates::CellCoordinates (int x, int y) : mX (x), mY (y) {} @@ -76,10 +69,10 @@ std::pair CSMWorld::CellCoordinates::coordinatesToCellIndex (float x, return std::make_pair (std::floor (x / Constants::CellSizeInUnits), std::floor (y / Constants::CellSizeInUnits)); } -std::pair CSMWorld::CellCoordinates::toTextureCoords(osg::Vec3d worldPos) +std::pair CSMWorld::CellCoordinates::toTextureCoords(const osg::Vec3d& worldPos) { - const auto xd = static_cast(worldPos.x() * landTextureSize / cellSize - 0.25f); - const auto yd = static_cast(worldPos.y() * landTextureSize / cellSize + 0.25f); + const auto xd = static_cast(worldPos.x() * ESM::Land::LAND_TEXTURE_SIZE / ESM::Land::REAL_SIZE - 0.25f); + const auto yd = static_cast(worldPos.y() * ESM::Land::LAND_TEXTURE_SIZE / ESM::Land::REAL_SIZE + 0.25f); const auto x = static_cast(std::floor(xd)); const auto y = static_cast(std::floor(yd)); @@ -87,10 +80,10 @@ std::pair CSMWorld::CellCoordinates::toTextureCoords(osg::Vec3d worldP return std::make_pair(x, y); } -std::pair CSMWorld::CellCoordinates::toVertexCoords(osg::Vec3d worldPos) +std::pair CSMWorld::CellCoordinates::toVertexCoords(const osg::Vec3d& worldPos) { - const auto xd = static_cast(worldPos.x() * (landSize - 1) / cellSize + 0.5f); - const auto yd = static_cast(worldPos.y() * (landSize - 1) / cellSize + 0.5f); + const auto xd = static_cast(worldPos.x() * (ESM::Land::LAND_SIZE - 1) / ESM::Land::REAL_SIZE + 0.5f); + const auto yd = static_cast(worldPos.y() * (ESM::Land::LAND_SIZE - 1) / ESM::Land::REAL_SIZE + 0.5f); const auto x = static_cast(std::floor(xd)); const auto y = static_cast(std::floor(yd)); @@ -100,30 +93,30 @@ std::pair CSMWorld::CellCoordinates::toVertexCoords(osg::Vec3d worldPo float CSMWorld::CellCoordinates::textureSelectionToWorldCoords(int pos) { - return cellSize * static_cast(pos) / landTextureSize; + return ESM::Land::REAL_SIZE * static_cast(pos) / ESM::Land::LAND_TEXTURE_SIZE; } float CSMWorld::CellCoordinates::vertexSelectionToWorldCoords(int pos) { - return cellSize * static_cast(pos) / (landSize - 1); + return ESM::Land::REAL_SIZE * static_cast(pos) / (ESM::Land::LAND_SIZE - 1); } int CSMWorld::CellCoordinates::vertexSelectionToInCellCoords(int pos) { - return static_cast(pos - std::floor(static_cast(pos) / (landSize - 1)) * (landSize - 1)); + return static_cast(pos - std::floor(static_cast(pos) / (ESM::Land::LAND_SIZE - 1)) * (ESM::Land::LAND_SIZE - 1)); } -std::string CSMWorld::CellCoordinates::textureGlobalToCellId(std::pair textureGlobal) +std::string CSMWorld::CellCoordinates::textureGlobalToCellId(const std::pair& textureGlobal) { - int x = std::floor(static_cast(textureGlobal.first) / landTextureSize); - int y = std::floor(static_cast(textureGlobal.second) / landTextureSize); + int x = std::floor(static_cast(textureGlobal.first) / ESM::Land::LAND_TEXTURE_SIZE); + int y = std::floor(static_cast(textureGlobal.second) / ESM::Land::LAND_TEXTURE_SIZE); return generateId(x, y); } -std::string CSMWorld::CellCoordinates::vertexGlobalToCellId(std::pair vertexGlobal) +std::string CSMWorld::CellCoordinates::vertexGlobalToCellId(const std::pair& vertexGlobal) { - int x = std::floor(static_cast(vertexGlobal.first) / (landSize - 1)); - int y = std::floor(static_cast(vertexGlobal.second) / (landSize - 1)); + int x = std::floor(static_cast(vertexGlobal.first) / (ESM::Land::LAND_SIZE - 1)); + int y = std::floor(static_cast(vertexGlobal.second) / (ESM::Land::LAND_SIZE - 1)); return generateId(x, y); } diff --git a/apps/opencs/model/world/cellcoordinates.hpp b/apps/opencs/model/world/cellcoordinates.hpp index c6c2c7ccd..554aff32b 100644 --- a/apps/opencs/model/world/cellcoordinates.hpp +++ b/apps/opencs/model/world/cellcoordinates.hpp @@ -49,10 +49,10 @@ namespace CSMWorld static std::pair coordinatesToCellIndex (float x, float y); ///Converts worldspace coordinates to global texture selection, taking in account the texture offset. - static std::pair toTextureCoords(osg::Vec3d worldPos); + static std::pair toTextureCoords(const osg::Vec3d& worldPos); ///Converts worldspace coordinates to global vertex selection. - static std::pair toVertexCoords(osg::Vec3d worldPos); + static std::pair toVertexCoords(const osg::Vec3d& worldPos); ///Converts global texture coordinate to worldspace coordinate that is at the upper left corner of the selected texture. static float textureSelectionToWorldCoords(int); @@ -63,10 +63,10 @@ namespace CSMWorld ///Converts local cell's heightmap coordinates from the global vertex coordinate static int vertexSelectionToInCellCoords(int); - static std::string textureGlobalToCellId(std::pair); + static std::string textureGlobalToCellId(const std::pair&); ///Converts global vertex coordinates to cell id - static std::string vertexGlobalToCellId(std::pair); + static std::string vertexGlobalToCellId(const std::pair&); }; bool operator== (const CellCoordinates& left, const CellCoordinates& right); diff --git a/apps/opencs/view/render/terrainselection.cpp b/apps/opencs/view/render/terrainselection.cpp index 4a5deb4b0..93a904689 100644 --- a/apps/opencs/view/render/terrainselection.cpp +++ b/apps/opencs/view/render/terrainselection.cpp @@ -15,13 +15,6 @@ #include "cell.hpp" #include "worldspacewidget.hpp" -namespace -{ - const int cellSize {ESM::Land::REAL_SIZE}; - const int landSize {ESM::Land::LAND_SIZE}; - const int landTextureSize {ESM::Land::LAND_TEXTURE_SIZE}; -} - CSVRender::TerrainSelection::TerrainSelection(osg::Group* parentNode, WorldspaceWidget *worldspaceWidget, TerrainSelectionType type): mParentNode(parentNode), mWorldspaceWidget (worldspaceWidget), mDraggedOperationFlag(false), mSelectionType(type) { @@ -180,10 +173,10 @@ void CSVRender::TerrainSelection::drawTextureSelection(const osg::ref_ptr &localPos : mSelection) { @@ -203,8 +196,8 @@ void CSVRender::TerrainSelection::drawTextureSelection(const osg::ref_ptrpush_back(osg::Vec3f(drawPreviousX + nudgeOffset, CSMWorld::CellCoordinates::textureSelectionToWorldCoords(y + 1) - nudgeOffset, calculateLandHeight(x1+(i-1), y2)+2)); vertices->push_back(osg::Vec3f(drawCurrentX + nudgeOffset, CSMWorld::CellCoordinates::textureSelectionToWorldCoords(y + 1) - nudgeOffset, calculateLandHeight(x1+i, y2)+2)); } @@ -215,8 +208,8 @@ void CSVRender::TerrainSelection::drawTextureSelection(const osg::ref_ptrpush_back(osg::Vec3f(drawPreviousX + nudgeOffset, CSMWorld::CellCoordinates::textureSelectionToWorldCoords(y) - nudgeOffset, calculateLandHeight(x1+(i-1), y1)+2)); vertices->push_back(osg::Vec3f(drawCurrentX + nudgeOffset, CSMWorld::CellCoordinates::textureSelectionToWorldCoords(y) - nudgeOffset, calculateLandHeight(x1+i, y1)+2)); } @@ -227,8 +220,8 @@ void CSVRender::TerrainSelection::drawTextureSelection(const osg::ref_ptrpush_back(osg::Vec3f(CSMWorld::CellCoordinates::textureSelectionToWorldCoords(x + 1) + nudgeOffset, drawPreviousY - nudgeOffset, calculateLandHeight(x2, y1+(i-1))+2)); vertices->push_back(osg::Vec3f(CSMWorld::CellCoordinates::textureSelectionToWorldCoords(x + 1) + nudgeOffset, drawCurrentY - nudgeOffset, calculateLandHeight(x2, y1+i)+2)); } @@ -239,8 +232,8 @@ void CSVRender::TerrainSelection::drawTextureSelection(const osg::ref_ptrpush_back(osg::Vec3f(CSMWorld::CellCoordinates::textureSelectionToWorldCoords(x) + nudgeOffset, drawPreviousY - nudgeOffset, calculateLandHeight(x1, y1+(i-1))+2)); vertices->push_back(osg::Vec3f(CSMWorld::CellCoordinates::textureSelectionToWorldCoords(x) + nudgeOffset, drawCurrentY - nudgeOffset, calculateLandHeight(x1, y1+i)+2)); } @@ -251,10 +244,10 @@ void CSVRender::TerrainSelection::drawTextureSelection(const osg::ref_ptr(); - return mPointer[localY*landSize + localX]; + return mPointer[localY*ESM::Land::LAND_SIZE + localX]; } diff --git a/apps/opencs/view/render/terrainselection.hpp b/apps/opencs/view/render/terrainselection.hpp index ed4548fa7..cf2da2b8e 100644 --- a/apps/opencs/view/render/terrainselection.hpp +++ b/apps/opencs/view/render/terrainselection.hpp @@ -46,10 +46,6 @@ namespace CSVRender protected: - void addToSelection(osg::Vec3d worldPos); - void toggleSelection(osg::Vec3d worldPos); - void deselect(); - void update(); void drawShapeSelection(const osg::ref_ptr vertices); diff --git a/apps/opencs/view/render/terraintexturemode.cpp b/apps/opencs/view/render/terraintexturemode.cpp index dee60f2b3..08a437b37 100644 --- a/apps/opencs/view/render/terraintexturemode.cpp +++ b/apps/opencs/view/render/terraintexturemode.cpp @@ -492,7 +492,7 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe } } -bool CSVRender::TerrainTextureMode::isInCellSelection(const int& globalSelectionX, const int& globalSelectionY) +bool CSVRender::TerrainTextureMode::isInCellSelection(int globalSelectionX, int globalSelectionY) { if (CSVRender::PagedWorldspaceWidget *paged = dynamic_cast (&getWorldspaceWidget())) { @@ -732,12 +732,12 @@ void CSVRender::TerrainTextureMode::setBrushShape(int brushShape) for(auto const& value: terrainSelection) { - selectionCenterX = selectionCenterX + value.first; - selectionCenterY = selectionCenterY + value.second; + selectionCenterX += value.first; + selectionCenterY += value.second; ++selectionAmount; } - selectionCenterX = selectionCenterX / selectionAmount; - selectionCenterY = selectionCenterY / selectionAmount; + selectionCenterX /= selectionAmount; + selectionCenterY /= selectionAmount; mCustomBrushShape.clear(); for (auto const& value: terrainSelection) diff --git a/apps/opencs/view/render/terraintexturemode.hpp b/apps/opencs/view/render/terraintexturemode.hpp index 392f1ce29..0d670d725 100644 --- a/apps/opencs/view/render/terraintexturemode.hpp +++ b/apps/opencs/view/render/terraintexturemode.hpp @@ -85,7 +85,7 @@ namespace CSVRender void editTerrainTextureGrid (const WorldspaceHitResult& hit); /// \brief Check if global selection coordinate belongs to cell in view - bool isInCellSelection(const int& globalSelectionX, const int& globalSelectionY); + bool isInCellSelection(int globalSelectionX, int globalSelectionY); /// \brief Handle brush mechanics for texture selection void selectTerrainTextures (const std::pair& texCoords, unsigned char selectMode, bool dragOperation);