From d2d22e2f237e2c4619566144c941a330ba119939 Mon Sep 17 00:00:00 2001 From: Aesylwinn Date: Mon, 16 May 2016 19:03:40 -0400 Subject: [PATCH] Clamp node positions in exterior cells. --- apps/opencs/view/render/pathgrid.cpp | 35 +++++++++++++++++++++++----- apps/opencs/view/render/pathgrid.hpp | 3 +++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/apps/opencs/view/render/pathgrid.cpp b/apps/opencs/view/render/pathgrid.cpp index 7807525ef..2e4ec6a1a 100644 --- a/apps/opencs/view/render/pathgrid.cpp +++ b/apps/opencs/view/render/pathgrid.cpp @@ -10,6 +10,7 @@ #include +#include "../../model/world/cell.hpp" #include "../../model/world/commands.hpp" #include "../../model/world/commandmacro.hpp" #include "../../model/world/data.hpp" @@ -45,6 +46,7 @@ namespace CSVRender , mPathgridCollection(mData.getPathgrids()) , mId(pathgridId) , mCoords(coordinates) + , mInterior(false) , mConnectionIndicator(false) , mConnectionNode(0) , mParent(parent) @@ -70,6 +72,13 @@ namespace CSVRender mSelectedNode->addChild(mSelectedGeode); recreateGeometry(); + + int index = mData.getCells().searchId(mId); + if (index != -1) + { + const CSMWorld::Cell& cell = mData.getCells().getRecord(index).get(); + mInterior = cell.mData.mFlags & ESM::Cell::Interior; + } } Pathgrid::~Pathgrid() @@ -187,9 +196,9 @@ namespace CSVRender { osg::Vec3d localCoords = worldPos - mBaseNode->getPosition(); - int posX = static_cast(localCoords.x()); - int posY = static_cast(localCoords.y()); - int posZ = static_cast(localCoords.z()); + int posX = clampToCell(static_cast(localCoords.x())); + int posY = clampToCell(static_cast(localCoords.y())); + int posZ = clampToCell(static_cast(localCoords.z())); CSMWorld::IdTree* model = dynamic_cast(mData.getTableModel( CSMWorld::UniversalId::Type_Pathgrids)); @@ -254,13 +263,13 @@ namespace CSVRender int row = static_cast(mSelected[i]); commands.push(new CSMWorld::ModifyCommand(*model, model->index(row, posXColumn, parent), - point.mX + offsetX)); + clampToCell(point.mX + offsetX))); commands.push(new CSMWorld::ModifyCommand(*model, model->index(row, posYColumn, parent), - point.mY + offsetY)); + clampToCell(point.mY + offsetY))); commands.push(new CSMWorld::ModifyCommand(*model, model->index(row, posZColumn, parent), - point.mZ + offsetZ)); + clampToCell(point.mZ + offsetZ))); } } } @@ -481,4 +490,18 @@ namespace CSVRender commands.push(new CSMWorld::ModifyCommand(*model, model->index(row, edge1Column, parent), node1)); } } + + int Pathgrid::clampToCell(int v) + { + const int CellExtent = ESM::Land::REAL_SIZE; + + if (mInterior) + return v; + else if (v > CellExtent) + return CellExtent; + else if (v < 0) + return 0; + else + return v; + } } diff --git a/apps/opencs/view/render/pathgrid.hpp b/apps/opencs/view/render/pathgrid.hpp index 62ecef4d6..3a83716d8 100644 --- a/apps/opencs/view/render/pathgrid.hpp +++ b/apps/opencs/view/render/pathgrid.hpp @@ -90,6 +90,7 @@ namespace CSVRender CSMWorld::SubCellCollection& mPathgridCollection; std::string mId; CSMWorld::CellCoordinates mCoords; + bool mInterior; NodeList mSelected; bool mConnectionIndicator; @@ -117,6 +118,8 @@ namespace CSVRender unsigned short node2); void removeEdge(CSMWorld::CommandMacro& commands, const CSMWorld::Pathgrid& source, unsigned short node1, unsigned short node2); + + int clampToCell(int v); }; }