mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-21 07:09:42 +00:00
Drag indicator.
This commit is contained in:
parent
e8e915bcde
commit
1781aaaa27
6 changed files with 100 additions and 15 deletions
|
@ -433,5 +433,5 @@ void CSVRender::Cell::reset (unsigned int elementMask)
|
||||||
iter!=mObjects.end(); ++iter)
|
iter!=mObjects.end(); ++iter)
|
||||||
iter->second->reset();
|
iter->second->reset();
|
||||||
if (elementMask & Mask_Pathgrid)
|
if (elementMask & Mask_Pathgrid)
|
||||||
mPathgrid->resetMove();
|
mPathgrid->resetIndicators();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <osg/Array>
|
||||||
#include <osg/Geode>
|
#include <osg/Geode>
|
||||||
#include <osg/Geometry>
|
#include <osg/Geometry>
|
||||||
#include <osg/Group>
|
#include <osg/Group>
|
||||||
|
@ -61,6 +62,7 @@ namespace CSVRender
|
||||||
, mParent(parent)
|
, mParent(parent)
|
||||||
, mPathgridGeometry(0)
|
, mPathgridGeometry(0)
|
||||||
, mSelectedGeometry(0)
|
, mSelectedGeometry(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;
|
||||||
|
@ -189,12 +191,50 @@ namespace CSVRender
|
||||||
createSelectedGeometry();
|
createSelectedGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pathgrid::resetMove()
|
void Pathgrid::adjustConnectionIndicator(unsigned short node)
|
||||||
|
{
|
||||||
|
if (mConnectionIndicator)
|
||||||
|
{
|
||||||
|
const CSMWorld::Pathgrid* source = getPathgridSource();
|
||||||
|
if (source)
|
||||||
|
{
|
||||||
|
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 end = osg::Vec3f(pointB.mX, pointB.mY, pointB.mZ + SceneUtil::DiamondHalfHeight);
|
||||||
|
|
||||||
|
createConnectionGeometry(start, end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pathgrid::adjustConnectionIndicator(const osg::Vec3d& pos)
|
||||||
|
{
|
||||||
|
if (mConnectionIndicator)
|
||||||
|
{
|
||||||
|
const CSMWorld::Pathgrid* source = getPathgridSource();
|
||||||
|
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 end = pos - mBaseNode->getPosition();
|
||||||
|
createConnectionGeometry(start, end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pathgrid::resetIndicators()
|
||||||
{
|
{
|
||||||
mSelectedNode->setPosition(osg::Vec3f(0,0,0));
|
mSelectedNode->setPosition(osg::Vec3f(0,0,0));
|
||||||
if (mConnectionIndicator)
|
if (mConnectionIndicator)
|
||||||
{
|
{
|
||||||
mConnectionIndicator = false;
|
mConnectionIndicator = false;
|
||||||
|
|
||||||
|
mPathgridGeode->removeDrawable(mConnectionGeometry);
|
||||||
|
mConnectionGeometry = 0;
|
||||||
|
|
||||||
createSelectedGeometry();
|
createSelectedGeometry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -379,8 +419,6 @@ namespace CSVRender
|
||||||
void Pathgrid::removeGeometry()
|
void Pathgrid::removeGeometry()
|
||||||
{
|
{
|
||||||
mRemoveGeometry = true;
|
mRemoveGeometry = true;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pathgrid::update()
|
void Pathgrid::update()
|
||||||
|
@ -471,6 +509,31 @@ namespace CSVRender
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Pathgrid::createConnectionGeometry(const osg::Vec3f& start, const osg::Vec3f& end)
|
||||||
|
{
|
||||||
|
if (mConnectionGeometry)
|
||||||
|
mPathgridGeode->removeDrawable(mConnectionGeometry);
|
||||||
|
|
||||||
|
mConnectionGeometry = new osg::Geometry();
|
||||||
|
|
||||||
|
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array(2);
|
||||||
|
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array(1);
|
||||||
|
osg::ref_ptr<osg::DrawElementsUShort> indices = new osg::DrawElementsUShort(osg::PrimitiveSet::LINES, 2);
|
||||||
|
|
||||||
|
(*vertices)[0] = start;
|
||||||
|
(*vertices)[1] = end;
|
||||||
|
(*colors)[0] = osg::Vec4f(0.4f, 1.f, 0.4f, 1.f);
|
||||||
|
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);
|
||||||
|
|
||||||
|
mPathgridGeode->addDrawable(mConnectionGeometry);
|
||||||
|
}
|
||||||
|
|
||||||
const CSMWorld::Pathgrid* Pathgrid::getPathgridSource()
|
const CSMWorld::Pathgrid* Pathgrid::getPathgridSource()
|
||||||
{
|
{
|
||||||
int index = mPathgridCollection.searchId(mId);
|
int index = mPathgridCollection.searchId(mId);
|
||||||
|
|
|
@ -69,9 +69,11 @@ namespace CSVRender
|
||||||
void clearSelected();
|
void clearSelected();
|
||||||
|
|
||||||
void moveSelected(const osg::Vec3d& offset);
|
void moveSelected(const osg::Vec3d& offset);
|
||||||
void resetMove();
|
|
||||||
|
|
||||||
void setupConnectionIndicator(unsigned short node);
|
void setupConnectionIndicator(unsigned short node);
|
||||||
|
void adjustConnectionIndicator(unsigned short node);
|
||||||
|
void adjustConnectionIndicator(const osg::Vec3d& pos);
|
||||||
|
|
||||||
|
void resetIndicators();
|
||||||
|
|
||||||
void applyPoint(CSMWorld::CommandMacro& commands, const osg::Vec3d& worldPos);
|
void applyPoint(CSMWorld::CommandMacro& commands, const osg::Vec3d& worldPos);
|
||||||
void applyPosition(CSMWorld::CommandMacro& commands);
|
void applyPosition(CSMWorld::CommandMacro& commands);
|
||||||
|
@ -109,6 +111,7 @@ namespace CSVRender
|
||||||
osg::ref_ptr<osg::Geode> mSelectedGeode;
|
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<PathgridTag> mTag;
|
osg::ref_ptr<PathgridTag> mTag;
|
||||||
|
|
||||||
|
@ -118,6 +121,8 @@ namespace CSVRender
|
||||||
void removePathgridGeometry();
|
void removePathgridGeometry();
|
||||||
void removeSelectedGeometry();
|
void removeSelectedGeometry();
|
||||||
|
|
||||||
|
void createConnectionGeometry(const osg::Vec3f& start, const osg::Vec3f& end);
|
||||||
|
|
||||||
const CSMWorld::Pathgrid* getPathgridSource();
|
const CSMWorld::Pathgrid* getPathgridSource();
|
||||||
|
|
||||||
int edgeExists(const CSMWorld::Pathgrid& source, unsigned short node1, unsigned short node2);
|
int edgeExists(const CSMWorld::Pathgrid& source, unsigned short node1, unsigned short node2);
|
||||||
|
|
|
@ -156,13 +156,13 @@ namespace CSVRender
|
||||||
|
|
||||||
void PathgridMode::drag(const QPoint& pos, int diffX, int diffY, double speedFactor)
|
void PathgridMode::drag(const QPoint& pos, int diffX, int diffY, double speedFactor)
|
||||||
{
|
{
|
||||||
std::vector<osg::ref_ptr<TagBase> > selection = getWorldspaceWidget().getSelection (Mask_Pathgrid);
|
if (mDragMode == DragMode_Move)
|
||||||
|
|
||||||
for (std::vector<osg::ref_ptr<TagBase> >::iterator it = selection.begin(); it != selection.end(); ++it)
|
|
||||||
{
|
{
|
||||||
if (PathgridTag* tag = dynamic_cast<PathgridTag*>(it->get()))
|
std::vector<osg::ref_ptr<TagBase> > selection = getWorldspaceWidget().getSelection(Mask_Pathgrid);
|
||||||
|
|
||||||
|
for (std::vector<osg::ref_ptr<TagBase> >::iterator it = selection.begin(); it != selection.end(); ++it)
|
||||||
{
|
{
|
||||||
if (mDragMode == DragMode_Move)
|
if (PathgridTag* tag = dynamic_cast<PathgridTag*>(it->get()))
|
||||||
{
|
{
|
||||||
osg::Vec3d eye, center, up, offset;
|
osg::Vec3d eye, center, up, offset;
|
||||||
getWorldspaceWidget().getCamera()->getViewMatrix().getLookAt (eye, center, up);
|
getWorldspaceWidget().getCamera()->getViewMatrix().getLookAt (eye, center, up);
|
||||||
|
@ -171,10 +171,26 @@ namespace CSVRender
|
||||||
|
|
||||||
tag->getPathgrid()->moveSelected(offset);
|
tag->getPathgrid()->moveSelected(offset);
|
||||||
}
|
}
|
||||||
else if (mDragMode == DragMode_Edge)
|
}
|
||||||
|
}
|
||||||
|
else if (mDragMode == DragMode_Edge)
|
||||||
|
{
|
||||||
|
WorldspaceHitResult hit = getWorldspaceWidget().mousePick (pos, getWorldspaceWidget().getInteractionMask());
|
||||||
|
|
||||||
|
Cell* cell = getWorldspaceWidget().getCell(hit.worldPos);
|
||||||
|
if (cell)
|
||||||
|
{
|
||||||
|
PathgridTag* tag = 0;
|
||||||
|
if (hit.tag && (tag = dynamic_cast<PathgridTag*>(hit.tag.get())) && tag->getPathgrid()->getId() == mEdgeId)
|
||||||
{
|
{
|
||||||
// TODO Add indicator, need raytrace
|
unsigned short node = SceneUtil::getPathgridNode(static_cast<unsigned short>(hit.index0));
|
||||||
|
cell->getPathgrid()->adjustConnectionIndicator(node);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cell->getPathgrid()->adjustConnectionIndicator(hit.worldPos);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,6 @@ namespace SceneUtil
|
||||||
|
|
||||||
const unsigned short DiamondTotalVertexCount = DiamondVertexCount + DiamondConnectorVertexCount;
|
const unsigned short DiamondTotalVertexCount = DiamondVertexCount + DiamondConnectorVertexCount;
|
||||||
|
|
||||||
const float DiamondHalfHeight = 40.f;
|
|
||||||
const float DiamondHalfWidth = 16.f;
|
|
||||||
const float DiamondWireframeScalar = 1.1f;
|
const float DiamondWireframeScalar = 1.1f;
|
||||||
|
|
||||||
const osg::Vec3f DiamondPoints[DiamondVertexCount] =
|
const osg::Vec3f DiamondPoints[DiamondVertexCount] =
|
||||||
|
|
|
@ -11,6 +11,9 @@ namespace ESM
|
||||||
|
|
||||||
namespace SceneUtil
|
namespace SceneUtil
|
||||||
{
|
{
|
||||||
|
const float DiamondHalfHeight = 40.f;
|
||||||
|
const float DiamondHalfWidth = 16.f;
|
||||||
|
|
||||||
osg::ref_ptr<osg::Geometry> createPathgridGeometry(const ESM::Pathgrid& pathgrid);
|
osg::ref_ptr<osg::Geometry> createPathgridGeometry(const ESM::Pathgrid& pathgrid);
|
||||||
|
|
||||||
osg::ref_ptr<osg::Geometry> createPathgridSelectedWireframe(const ESM::Pathgrid& pathgrid,
|
osg::ref_ptr<osg::Geometry> createPathgridSelectedWireframe(const ESM::Pathgrid& pathgrid,
|
||||||
|
|
Loading…
Reference in a new issue