1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-30 15:45:31 +00:00

Change pathgrid node movement to be visually consistent, some

renaming
This commit is contained in:
Aesylwinn 2016-06-04 12:38:17 -04:00
parent 83c86cd1be
commit 3409d8a922
3 changed files with 68 additions and 88 deletions

View file

@ -55,14 +55,13 @@ namespace CSVRender
, mId(pathgridId) , mId(pathgridId)
, mCoords(coordinates) , mCoords(coordinates)
, mInterior(false) , mInterior(false)
, mConnectionIndicator(false) , mDragOrigin(0)
, mConnectionNode(0)
, mChangeGeometry(true) , mChangeGeometry(true)
, mRemoveGeometry(false) , mRemoveGeometry(false)
, mUseOffset(true)
, mParent(parent) , mParent(parent)
, mPathgridGeometry(0) , mPathgridGeometry(0)
, mSelectedGeometry(0) , mDragGeometry(0)
, mConnectionGeometry(0)
, mTag(new PathgridTag(this)) , mTag(new PathgridTag(this))
{ {
const float CoordScalar = ESM::Land::REAL_SIZE; const float CoordScalar = ESM::Land::REAL_SIZE;
@ -74,15 +73,9 @@ namespace CSVRender
mBaseNode->setNodeMask(Mask_Pathgrid); mBaseNode->setNodeMask(Mask_Pathgrid);
mParent->addChild(mBaseNode); mParent->addChild(mBaseNode);
mSelectedNode = new osg::PositionAttitudeTransform();
mBaseNode->addChild(mSelectedNode);
mPathgridGeode = new osg::Geode(); mPathgridGeode = new osg::Geode();
mBaseNode->addChild(mPathgridGeode); mBaseNode->addChild(mPathgridGeode);
mSelectedGeode = new osg::Geode();
mSelectedNode->addChild(mSelectedGeode);
recreateGeometry(); recreateGeometry();
int index = mData.getCells().searchId(mId); int index = mData.getCells().searchId(mId);
@ -181,67 +174,56 @@ namespace CSVRender
void Pathgrid::moveSelected(const osg::Vec3d& offset) void Pathgrid::moveSelected(const osg::Vec3d& offset)
{ {
mSelectedNode->setPosition(mSelectedNode->getPosition() + offset); mUseOffset = true;
mMoveOffset += offset;
recreateGeometry();
} }
void Pathgrid::setupConnectionIndicator(unsigned short node) void Pathgrid::setDragOrigin(unsigned short node)
{ {
mConnectionIndicator = true; mDragOrigin = node;
mConnectionNode = node;
createSelectedGeometry();
} }
void Pathgrid::adjustConnectionIndicator(unsigned short node) void Pathgrid::setDragEndpoint(unsigned short node)
{ {
if (mConnectionIndicator) const CSMWorld::Pathgrid* source = getPathgridSource();
if (source)
{ {
const CSMWorld::Pathgrid* source = getPathgridSource(); const CSMWorld::Pathgrid::Point& pointA = source->mPoints[mDragOrigin];
if (source) const CSMWorld::Pathgrid::Point& pointB = source->mPoints[node];
{
const CSMWorld::Pathgrid::Point& pointA = source->mPoints[mConnectionNode];
const CSMWorld::Pathgrid::Point& pointB = source->mPoints[node];
osg::Vec3f start = osg::Vec3f(pointA.mX, pointA.mY, pointA.mZ + SceneUtil::DiamondHalfHeight); osg::Vec3f start = osg::Vec3f(pointA.mX, pointA.mY, pointA.mZ + SceneUtil::DiamondHalfHeight);
osg::Vec3f end = osg::Vec3f(pointB.mX, pointB.mY, pointB.mZ + SceneUtil::DiamondHalfHeight); osg::Vec3f end = osg::Vec3f(pointB.mX, pointB.mY, pointB.mZ + SceneUtil::DiamondHalfHeight);
createConnectionGeometry(start, end, true); createDragGeometry(start, end, true);
}
} }
} }
void Pathgrid::adjustConnectionIndicator(const osg::Vec3d& pos) void Pathgrid::setDragEndpoint(const osg::Vec3d& pos)
{ {
if (mConnectionIndicator) const CSMWorld::Pathgrid* source = getPathgridSource();
if (source)
{ {
const CSMWorld::Pathgrid* source = getPathgridSource(); const CSMWorld::Pathgrid::Point& point = source->mPoints[mDragOrigin];
if (source)
{
const CSMWorld::Pathgrid::Point& point = source->mPoints[mConnectionNode];
osg::Vec3f start = osg::Vec3f(point.mX, point.mY, point.mZ + SceneUtil::DiamondHalfHeight); osg::Vec3f start = osg::Vec3f(point.mX, point.mY, point.mZ + SceneUtil::DiamondHalfHeight);
osg::Vec3f end = pos - mBaseNode->getPosition(); osg::Vec3f end = pos - mBaseNode->getPosition();
createConnectionGeometry(start, end, false); createDragGeometry(start, end, false);
}
} }
} }
void Pathgrid::resetIndicators() void Pathgrid::resetIndicators()
{ {
mSelectedNode->setPosition(osg::Vec3f(0,0,0)); mUseOffset = false;
if (mConnectionIndicator) mMoveOffset.set(0, 0, 0);
{
mConnectionIndicator = false;
mPathgridGeode->removeDrawable(mConnectionGeometry); mPathgridGeode->removeDrawable(mDragGeometry);
mConnectionGeometry = 0; mDragGeometry = 0;
createSelectedGeometry();
}
} }
void Pathgrid::applyPoint(CSMWorld::CommandMacro& commands, const osg::Vec3d& worldPos) void Pathgrid::applyPoint(CSMWorld::CommandMacro& commands, const osg::Vec3d& worldPos)
{ {
CSMWorld::IdTree* model = dynamic_cast<CSMWorld::IdTree*>(mData.getTableModel( CSMWorld::IdTree* model = dynamic_cast<CSMWorld::IdTree*>(mData.getTableModel(
CSMWorld::UniversalId::Type_Pathgrids)); CSMWorld::UniversalId::Type_Pathgrids));
@ -310,7 +292,7 @@ namespace CSVRender
const CSMWorld::Pathgrid* source = getPathgridSource(); const CSMWorld::Pathgrid* source = getPathgridSource();
if (source) if (source)
{ {
osg::Vec3d localCoords = mSelectedNode->getPosition(); osg::Vec3d localCoords = mMoveOffset;
int offsetX = static_cast<int>(localCoords.x()); int offsetX = static_cast<int>(localCoords.x());
int offsetY = static_cast<int>(localCoords.y()); int offsetY = static_cast<int>(localCoords.y());
@ -525,6 +507,21 @@ namespace CSVRender
const CSMWorld::Pathgrid* source = getPathgridSource(); const CSMWorld::Pathgrid* source = getPathgridSource();
if (source) if (source)
{ {
CSMWorld::Pathgrid temp;
if (mUseOffset)
{
temp = *source;
for (NodeList::iterator it = mSelected.begin(); it != mSelected.end(); ++it)
{
temp.mPoints[*it].mX += mMoveOffset.x();
temp.mPoints[*it].mY += mMoveOffset.y();
temp.mPoints[*it].mZ += mMoveOffset.z();
}
source = &temp;
}
removePathgridGeometry(); removePathgridGeometry();
mPathgridGeometry = SceneUtil::createPathgridGeometry(*source); mPathgridGeometry = SceneUtil::createPathgridGeometry(*source);
mPathgridGeode->addDrawable(mPathgridGeometry); mPathgridGeode->addDrawable(mPathgridGeometry);
@ -555,24 +552,8 @@ namespace CSVRender
{ {
removeSelectedGeometry(); removeSelectedGeometry();
if (mConnectionIndicator) mSelectedGeometry = SceneUtil::createPathgridSelectedWireframe(source, mSelected);
{ mPathgridGeode->addDrawable(mSelectedGeometry);
NodeList tempList = NodeList(mSelected);
NodeList::iterator searchResult = std::find(tempList.begin(), tempList.end(), mConnectionNode);
if (searchResult != tempList.end())
tempList.erase(searchResult);
tempList.push_back(mConnectionNode);
mSelectedGeometry = SceneUtil::createPathgridSelectedWireframe(source, tempList);
mSelectedGeode->addDrawable(mSelectedGeometry);
}
else
{
mSelectedGeometry = SceneUtil::createPathgridSelectedWireframe(source, mSelected);
mSelectedGeode->addDrawable(mSelectedGeometry);
}
} }
void Pathgrid::removePathgridGeometry() void Pathgrid::removePathgridGeometry()
@ -588,17 +569,17 @@ namespace CSVRender
{ {
if (mSelectedGeometry) if (mSelectedGeometry)
{ {
mSelectedGeode->removeDrawable(mSelectedGeometry); mPathgridGeode->removeDrawable(mSelectedGeometry);
mSelectedGeometry = 0; mSelectedGeometry = 0;
} }
} }
void Pathgrid::createConnectionGeometry(const osg::Vec3f& start, const osg::Vec3f& end, bool valid) void Pathgrid::createDragGeometry(const osg::Vec3f& start, const osg::Vec3f& end, bool valid)
{ {
if (mConnectionGeometry) if (mDragGeometry)
mPathgridGeode->removeDrawable(mConnectionGeometry); mPathgridGeode->removeDrawable(mDragGeometry);
mConnectionGeometry = new osg::Geometry(); mDragGeometry = new osg::Geometry();
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array(2); osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array(2);
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array(1); osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array(1);
@ -619,12 +600,12 @@ namespace CSVRender
indices->setElement(0, 0); indices->setElement(0, 0);
indices->setElement(1, 1); indices->setElement(1, 1);
mConnectionGeometry->setVertexArray(vertices); mDragGeometry->setVertexArray(vertices);
mConnectionGeometry->setColorArray(colors, osg::Array::BIND_OVERALL); mDragGeometry->setColorArray(colors, osg::Array::BIND_OVERALL);
mConnectionGeometry->addPrimitiveSet(indices); mDragGeometry->addPrimitiveSet(indices);
mConnectionGeometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); mDragGeometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
mPathgridGeode->addDrawable(mConnectionGeometry); mPathgridGeode->addDrawable(mDragGeometry);
} }
const CSMWorld::Pathgrid* Pathgrid::getPathgridSource() const CSMWorld::Pathgrid* Pathgrid::getPathgridSource()

View file

@ -5,6 +5,7 @@
#include <QString> #include <QString>
#include <osg/ref_ptr> #include <osg/ref_ptr>
#include <osg/Vec3d>
#include "../../model/world/cellcoordinates.hpp" #include "../../model/world/cellcoordinates.hpp"
#include "../../model/world/idcollection.hpp" #include "../../model/world/idcollection.hpp"
@ -18,7 +19,6 @@ namespace osg
class Geometry; class Geometry;
class Group; class Group;
class PositionAttitudeTransform; class PositionAttitudeTransform;
class Vec3d;
} }
namespace CSMWorld namespace CSMWorld
@ -69,9 +69,9 @@ namespace CSVRender
void clearSelected(); void clearSelected();
void moveSelected(const osg::Vec3d& offset); void moveSelected(const osg::Vec3d& offset);
void setupConnectionIndicator(unsigned short node); void setDragOrigin(unsigned short node);
void adjustConnectionIndicator(unsigned short node); void setDragEndpoint(unsigned short node);
void adjustConnectionIndicator(const osg::Vec3d& pos); void setDragEndpoint(const osg::Vec3d& pos);
void resetIndicators(); void resetIndicators();
@ -98,20 +98,19 @@ namespace CSVRender
bool mInterior; bool mInterior;
NodeList mSelected; NodeList mSelected;
bool mConnectionIndicator; osg::Vec3d mMoveOffset;
unsigned short mConnectionNode; unsigned short mDragOrigin;
bool mChangeGeometry; bool mChangeGeometry;
bool mRemoveGeometry; bool mRemoveGeometry;
bool mUseOffset;
osg::Group* mParent; osg::Group* mParent;
osg::ref_ptr<osg::PositionAttitudeTransform> mBaseNode; osg::ref_ptr<osg::PositionAttitudeTransform> mBaseNode;
osg::ref_ptr<osg::PositionAttitudeTransform> mSelectedNode;
osg::ref_ptr<osg::Geode> mPathgridGeode; osg::ref_ptr<osg::Geode> mPathgridGeode;
osg::ref_ptr<osg::Geode> mSelectedGeode;
osg::ref_ptr<osg::Geometry> mPathgridGeometry; osg::ref_ptr<osg::Geometry> mPathgridGeometry;
osg::ref_ptr<osg::Geometry> mSelectedGeometry; osg::ref_ptr<osg::Geometry> mSelectedGeometry;
osg::ref_ptr<osg::Geometry> mConnectionGeometry; osg::ref_ptr<osg::Geometry> mDragGeometry;
osg::ref_ptr<PathgridTag> mTag; osg::ref_ptr<PathgridTag> mTag;
@ -121,7 +120,7 @@ namespace CSVRender
void removePathgridGeometry(); void removePathgridGeometry();
void removeSelectedGeometry(); void removeSelectedGeometry();
void createConnectionGeometry(const osg::Vec3f& start, const osg::Vec3f& end, bool valid); void createDragGeometry(const osg::Vec3f& start, const osg::Vec3f& end, bool valid);
const CSMWorld::Pathgrid* getPathgridSource(); const CSMWorld::Pathgrid* getPathgridSource();

View file

@ -163,7 +163,7 @@ namespace CSVRender
mEdgeId = tag->getPathgrid()->getId(); mEdgeId = tag->getPathgrid()->getId();
mFromNode = SceneUtil::getPathgridNode(static_cast<unsigned short>(hit.index0)); mFromNode = SceneUtil::getPathgridNode(static_cast<unsigned short>(hit.index0));
tag->getPathgrid()->setupConnectionIndicator(mFromNode); tag->getPathgrid()->setDragOrigin(mFromNode);
return true; return true;
} }
} }
@ -201,11 +201,11 @@ namespace CSVRender
if (hit.tag && (tag = dynamic_cast<PathgridTag*>(hit.tag.get())) && tag->getPathgrid()->getId() == mEdgeId) if (hit.tag && (tag = dynamic_cast<PathgridTag*>(hit.tag.get())) && tag->getPathgrid()->getId() == mEdgeId)
{ {
unsigned short node = SceneUtil::getPathgridNode(static_cast<unsigned short>(hit.index0)); unsigned short node = SceneUtil::getPathgridNode(static_cast<unsigned short>(hit.index0));
cell->getPathgrid()->adjustConnectionIndicator(node); cell->getPathgrid()->setDragEndpoint(node);
} }
else else
{ {
cell->getPathgrid()->adjustConnectionIndicator(hit.worldPos); cell->getPathgrid()->setDragEndpoint(hit.worldPos);
} }
} }