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:
parent
83c86cd1be
commit
3409d8a922
3 changed files with 68 additions and 88 deletions
|
@ -55,14 +55,13 @@ namespace CSVRender
|
|||
, mId(pathgridId)
|
||||
, mCoords(coordinates)
|
||||
, mInterior(false)
|
||||
, mConnectionIndicator(false)
|
||||
, mConnectionNode(0)
|
||||
, mDragOrigin(0)
|
||||
, mChangeGeometry(true)
|
||||
, mRemoveGeometry(false)
|
||||
, mUseOffset(true)
|
||||
, mParent(parent)
|
||||
, mPathgridGeometry(0)
|
||||
, mSelectedGeometry(0)
|
||||
, mConnectionGeometry(0)
|
||||
, mDragGeometry(0)
|
||||
, mTag(new PathgridTag(this))
|
||||
{
|
||||
const float CoordScalar = ESM::Land::REAL_SIZE;
|
||||
|
@ -74,15 +73,9 @@ namespace CSVRender
|
|||
mBaseNode->setNodeMask(Mask_Pathgrid);
|
||||
mParent->addChild(mBaseNode);
|
||||
|
||||
mSelectedNode = new osg::PositionAttitudeTransform();
|
||||
mBaseNode->addChild(mSelectedNode);
|
||||
|
||||
mPathgridGeode = new osg::Geode();
|
||||
mBaseNode->addChild(mPathgridGeode);
|
||||
|
||||
mSelectedGeode = new osg::Geode();
|
||||
mSelectedNode->addChild(mSelectedGeode);
|
||||
|
||||
recreateGeometry();
|
||||
|
||||
int index = mData.getCells().searchId(mId);
|
||||
|
@ -181,67 +174,56 @@ namespace CSVRender
|
|||
|
||||
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;
|
||||
mConnectionNode = node;
|
||||
createSelectedGeometry();
|
||||
mDragOrigin = node;
|
||||
}
|
||||
|
||||
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();
|
||||
if (source)
|
||||
{
|
||||
const CSMWorld::Pathgrid::Point& pointA = source->mPoints[mConnectionNode];
|
||||
const CSMWorld::Pathgrid::Point& pointB = source->mPoints[node];
|
||||
const CSMWorld::Pathgrid::Point& pointA = source->mPoints[mDragOrigin];
|
||||
const CSMWorld::Pathgrid::Point& pointB = source->mPoints[node];
|
||||
|
||||
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 start = osg::Vec3f(pointA.mX, pointA.mY, pointA.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();
|
||||
if (source)
|
||||
{
|
||||
const CSMWorld::Pathgrid::Point& point = source->mPoints[mConnectionNode];
|
||||
const CSMWorld::Pathgrid::Point& point = source->mPoints[mDragOrigin];
|
||||
|
||||
osg::Vec3f start = osg::Vec3f(point.mX, point.mY, point.mZ + SceneUtil::DiamondHalfHeight);
|
||||
osg::Vec3f end = pos - mBaseNode->getPosition();
|
||||
createConnectionGeometry(start, end, false);
|
||||
}
|
||||
osg::Vec3f start = osg::Vec3f(point.mX, point.mY, point.mZ + SceneUtil::DiamondHalfHeight);
|
||||
osg::Vec3f end = pos - mBaseNode->getPosition();
|
||||
createDragGeometry(start, end, false);
|
||||
}
|
||||
}
|
||||
|
||||
void Pathgrid::resetIndicators()
|
||||
{
|
||||
mSelectedNode->setPosition(osg::Vec3f(0,0,0));
|
||||
if (mConnectionIndicator)
|
||||
{
|
||||
mConnectionIndicator = false;
|
||||
mUseOffset = false;
|
||||
mMoveOffset.set(0, 0, 0);
|
||||
|
||||
mPathgridGeode->removeDrawable(mConnectionGeometry);
|
||||
mConnectionGeometry = 0;
|
||||
|
||||
createSelectedGeometry();
|
||||
}
|
||||
mPathgridGeode->removeDrawable(mDragGeometry);
|
||||
mDragGeometry = 0;
|
||||
}
|
||||
|
||||
void Pathgrid::applyPoint(CSMWorld::CommandMacro& commands, const osg::Vec3d& worldPos)
|
||||
{
|
||||
|
||||
CSMWorld::IdTree* model = dynamic_cast<CSMWorld::IdTree*>(mData.getTableModel(
|
||||
CSMWorld::UniversalId::Type_Pathgrids));
|
||||
|
||||
|
@ -310,7 +292,7 @@ namespace CSVRender
|
|||
const CSMWorld::Pathgrid* source = getPathgridSource();
|
||||
if (source)
|
||||
{
|
||||
osg::Vec3d localCoords = mSelectedNode->getPosition();
|
||||
osg::Vec3d localCoords = mMoveOffset;
|
||||
|
||||
int offsetX = static_cast<int>(localCoords.x());
|
||||
int offsetY = static_cast<int>(localCoords.y());
|
||||
|
@ -525,6 +507,21 @@ namespace CSVRender
|
|||
const CSMWorld::Pathgrid* source = getPathgridSource();
|
||||
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();
|
||||
mPathgridGeometry = SceneUtil::createPathgridGeometry(*source);
|
||||
mPathgridGeode->addDrawable(mPathgridGeometry);
|
||||
|
@ -555,24 +552,8 @@ namespace CSVRender
|
|||
{
|
||||
removeSelectedGeometry();
|
||||
|
||||
if (mConnectionIndicator)
|
||||
{
|
||||
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);
|
||||
}
|
||||
mSelectedGeometry = SceneUtil::createPathgridSelectedWireframe(source, mSelected);
|
||||
mPathgridGeode->addDrawable(mSelectedGeometry);
|
||||
}
|
||||
|
||||
void Pathgrid::removePathgridGeometry()
|
||||
|
@ -588,17 +569,17 @@ namespace CSVRender
|
|||
{
|
||||
if (mSelectedGeometry)
|
||||
{
|
||||
mSelectedGeode->removeDrawable(mSelectedGeometry);
|
||||
mPathgridGeode->removeDrawable(mSelectedGeometry);
|
||||
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)
|
||||
mPathgridGeode->removeDrawable(mConnectionGeometry);
|
||||
if (mDragGeometry)
|
||||
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::Vec4Array> colors = new osg::Vec4Array(1);
|
||||
|
@ -619,12 +600,12 @@ namespace CSVRender
|
|||
indices->setElement(0, 0);
|
||||
indices->setElement(1, 1);
|
||||
|
||||
mConnectionGeometry->setVertexArray(vertices);
|
||||
mConnectionGeometry->setColorArray(colors, osg::Array::BIND_OVERALL);
|
||||
mConnectionGeometry->addPrimitiveSet(indices);
|
||||
mConnectionGeometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
|
||||
mDragGeometry->setVertexArray(vertices);
|
||||
mDragGeometry->setColorArray(colors, osg::Array::BIND_OVERALL);
|
||||
mDragGeometry->addPrimitiveSet(indices);
|
||||
mDragGeometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
|
||||
|
||||
mPathgridGeode->addDrawable(mConnectionGeometry);
|
||||
mPathgridGeode->addDrawable(mDragGeometry);
|
||||
}
|
||||
|
||||
const CSMWorld::Pathgrid* Pathgrid::getPathgridSource()
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <QString>
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/Vec3d>
|
||||
|
||||
#include "../../model/world/cellcoordinates.hpp"
|
||||
#include "../../model/world/idcollection.hpp"
|
||||
|
@ -18,7 +19,6 @@ namespace osg
|
|||
class Geometry;
|
||||
class Group;
|
||||
class PositionAttitudeTransform;
|
||||
class Vec3d;
|
||||
}
|
||||
|
||||
namespace CSMWorld
|
||||
|
@ -69,9 +69,9 @@ namespace CSVRender
|
|||
void clearSelected();
|
||||
|
||||
void moveSelected(const osg::Vec3d& offset);
|
||||
void setupConnectionIndicator(unsigned short node);
|
||||
void adjustConnectionIndicator(unsigned short node);
|
||||
void adjustConnectionIndicator(const osg::Vec3d& pos);
|
||||
void setDragOrigin(unsigned short node);
|
||||
void setDragEndpoint(unsigned short node);
|
||||
void setDragEndpoint(const osg::Vec3d& pos);
|
||||
|
||||
void resetIndicators();
|
||||
|
||||
|
@ -98,20 +98,19 @@ namespace CSVRender
|
|||
bool mInterior;
|
||||
|
||||
NodeList mSelected;
|
||||
bool mConnectionIndicator;
|
||||
unsigned short mConnectionNode;
|
||||
osg::Vec3d mMoveOffset;
|
||||
unsigned short mDragOrigin;
|
||||
|
||||
bool mChangeGeometry;
|
||||
bool mRemoveGeometry;
|
||||
bool mUseOffset;
|
||||
|
||||
osg::Group* mParent;
|
||||
osg::ref_ptr<osg::PositionAttitudeTransform> mBaseNode;
|
||||
osg::ref_ptr<osg::PositionAttitudeTransform> mSelectedNode;
|
||||
osg::ref_ptr<osg::Geode> mPathgridGeode;
|
||||
osg::ref_ptr<osg::Geode> mSelectedGeode;
|
||||
osg::ref_ptr<osg::Geometry> mPathgridGeometry;
|
||||
osg::ref_ptr<osg::Geometry> mSelectedGeometry;
|
||||
osg::ref_ptr<osg::Geometry> mConnectionGeometry;
|
||||
osg::ref_ptr<osg::Geometry> mDragGeometry;
|
||||
|
||||
osg::ref_ptr<PathgridTag> mTag;
|
||||
|
||||
|
@ -121,7 +120,7 @@ namespace CSVRender
|
|||
void removePathgridGeometry();
|
||||
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();
|
||||
|
||||
|
|
|
@ -163,7 +163,7 @@ namespace CSVRender
|
|||
mEdgeId = tag->getPathgrid()->getId();
|
||||
mFromNode = SceneUtil::getPathgridNode(static_cast<unsigned short>(hit.index0));
|
||||
|
||||
tag->getPathgrid()->setupConnectionIndicator(mFromNode);
|
||||
tag->getPathgrid()->setDragOrigin(mFromNode);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -201,11 +201,11 @@ namespace CSVRender
|
|||
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));
|
||||
cell->getPathgrid()->adjustConnectionIndicator(node);
|
||||
cell->getPathgrid()->setDragEndpoint(node);
|
||||
}
|
||||
else
|
||||
{
|
||||
cell->getPathgrid()->adjustConnectionIndicator(hit.worldPos);
|
||||
cell->getPathgrid()->setDragEndpoint(hit.worldPos);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue