forked from teamnwah/openmw-tes3coop
Add ability to get cell, pathgrid, and ability to add nodes.
Also missing include.
This commit is contained in:
parent
9f7c8d559c
commit
6fbc10dbba
10 changed files with 111 additions and 0 deletions
|
@ -123,6 +123,11 @@ CSVRender::Cell::~Cell()
|
|||
mCellNode->getParent(0)->removeChild(mCellNode);
|
||||
}
|
||||
|
||||
CSVRender::Pathgrid* CSVRender::Cell::getPathgrid() const
|
||||
{
|
||||
return mPathgrid.get();
|
||||
}
|
||||
|
||||
bool CSVRender::Cell::referenceableDataChanged (const QModelIndex& topLeft,
|
||||
const QModelIndex& bottomRight)
|
||||
{
|
||||
|
|
|
@ -87,6 +87,9 @@ namespace CSVRender
|
|||
|
||||
~Cell();
|
||||
|
||||
/// \note Returns the pathgrid representation which will exist as long as the cell exists
|
||||
Pathgrid* getPathgrid() const;
|
||||
|
||||
/// \return Did this call result in a modification of the visual representation of
|
||||
/// this cell?
|
||||
bool referenceableDataChanged (const QModelIndex& topLeft,
|
||||
|
|
|
@ -644,6 +644,21 @@ std::string CSVRender::PagedWorldspaceWidget::getCellId (const osg::Vec3f& point
|
|||
return cellCoordinates.getId (mWorldspace);
|
||||
}
|
||||
|
||||
CSVRender::Cell* CSVRender::PagedWorldspaceWidget::getCell(const osg::Vec3d& point) const
|
||||
{
|
||||
const int cellSize = 8192;
|
||||
|
||||
CSMWorld::CellCoordinates coords(
|
||||
static_cast<int> (std::floor (point.x()/cellSize)),
|
||||
static_cast<int> (std::floor (point.y()/cellSize)));
|
||||
|
||||
std::map<CSMWorld::CellCoordinates, Cell*>::const_iterator searchResult = mCells.find(coords);
|
||||
if (searchResult != mCells.end())
|
||||
return searchResult->second;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<osg::ref_ptr<CSVRender::TagBase> > CSVRender::PagedWorldspaceWidget::getSelection (
|
||||
unsigned int elementMask) const
|
||||
{
|
||||
|
|
|
@ -121,6 +121,8 @@ namespace CSVRender
|
|||
|
||||
virtual std::string getCellId (const osg::Vec3f& point) const;
|
||||
|
||||
virtual Cell* getCell(const osg::Vec3d& point) const;
|
||||
|
||||
virtual std::vector<osg::ref_ptr<TagBase> > getSelection (unsigned int elementMask)
|
||||
const;
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "../../model/world/commands.hpp"
|
||||
#include "../../model/world/commandmacro.hpp"
|
||||
#include "../../model/world/data.hpp"
|
||||
#include "../../model/world/idtree.hpp"
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
|
@ -165,6 +166,47 @@ namespace CSVRender
|
|||
mSelectedNode->setPosition(osg::Vec3f(0,0,0));
|
||||
}
|
||||
|
||||
void Pathgrid::applyPoint(CSMWorld::CommandMacro& commands, const osg::Vec3d& worldPos)
|
||||
{
|
||||
const CSMWorld::Pathgrid* source = getPathgridSource();
|
||||
if (source)
|
||||
{
|
||||
osg::Vec3d localCoords = worldPos - mBaseNode->getPosition();
|
||||
|
||||
int posX = static_cast<int>(localCoords.x());
|
||||
int posY = static_cast<int>(localCoords.y());
|
||||
int posZ = static_cast<int>(localCoords.z());
|
||||
|
||||
CSMWorld::IdTree* model = dynamic_cast<CSMWorld::IdTree*>(mData.getTableModel(
|
||||
CSMWorld::UniversalId::Type_Pathgrids));
|
||||
|
||||
int recordIndex = mPathgridCollection.getIndex (mId);
|
||||
int parentColumn = mPathgridCollection.findColumnIndex(CSMWorld::Columns::ColumnId_PathgridPoints);
|
||||
|
||||
int posXColumn = mPathgridCollection.searchNestedColumnIndex(parentColumn,
|
||||
CSMWorld::Columns::ColumnId_PathgridPosX);
|
||||
|
||||
int posYColumn = mPathgridCollection.searchNestedColumnIndex(parentColumn,
|
||||
CSMWorld::Columns::ColumnId_PathgridPosY);
|
||||
|
||||
int posZColumn = mPathgridCollection.searchNestedColumnIndex(parentColumn,
|
||||
CSMWorld::Columns::ColumnId_PathgridPosZ);
|
||||
|
||||
QModelIndex parent = model->index(recordIndex, parentColumn);
|
||||
int row = static_cast<int>(source->mPoints.size());
|
||||
|
||||
// Add node
|
||||
commands.push (new CSMWorld::AddNestedCommand(*model, mId, row, parentColumn));
|
||||
commands.push (new CSMWorld::ModifyCommand(*model, model->index(row, posXColumn, parent), posX));
|
||||
commands.push (new CSMWorld::ModifyCommand(*model, model->index(row, posYColumn, parent), posY));
|
||||
commands.push (new CSMWorld::ModifyCommand(*model, model->index(row, posZColumn, parent), posZ));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create pathgrid TODO
|
||||
}
|
||||
}
|
||||
|
||||
void Pathgrid::applyPosition(CSMWorld::CommandMacro& commands)
|
||||
{
|
||||
const CSMWorld::Pathgrid* source = getPathgridSource();
|
||||
|
|
|
@ -71,6 +71,7 @@ namespace CSVRender
|
|||
void moveSelected(const osg::Vec3d& offset);
|
||||
void resetMove();
|
||||
|
||||
void applyPoint(CSMWorld::CommandMacro& commands, const osg::Vec3d& worldPos);
|
||||
void applyPosition(CSMWorld::CommandMacro& commands);
|
||||
void applyEdge(CSMWorld::CommandMacro& commands, unsigned short node1, unsigned short node2);
|
||||
void applyEdges(CSMWorld::CommandMacro& commands, unsigned short node);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "../../model/world/idtable.hpp"
|
||||
#include "../../model/world/idtree.hpp"
|
||||
|
||||
#include "cell.hpp"
|
||||
#include "mask.hpp"
|
||||
#include "pathgrid.hpp"
|
||||
#include "worldspacewidget.hpp"
|
||||
|
@ -66,6 +67,37 @@ namespace CSVRender
|
|||
}
|
||||
|
||||
void PathgridMode::primaryEditPressed(const WorldspaceHitResult& hitResult)
|
||||
{
|
||||
// Determine placement
|
||||
osg::Vec3d position;
|
||||
|
||||
if (hitResult.hit)
|
||||
{
|
||||
position = hitResult.worldPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
const double DefaultDistance = 500.f;
|
||||
|
||||
osg::Vec3d eye, center, up, offset;
|
||||
getWorldspaceWidget().getCamera()->getViewMatrix().getLookAt (eye, center, up);
|
||||
|
||||
osg::Vec3d direction = center - eye;
|
||||
direction.normalize();
|
||||
position = eye + direction * DefaultDistance;
|
||||
}
|
||||
|
||||
// Get pathgrid cell
|
||||
Cell* cell = getWorldspaceWidget().getCell (position);
|
||||
if (cell)
|
||||
{
|
||||
// Add node
|
||||
QUndoStack& undoStack = getWorldspaceWidget().getDocument().getUndoStack();
|
||||
QString description = "Connect node to selected nodes";
|
||||
|
||||
CSMWorld::CommandMacro macro(undoStack, description);
|
||||
cell->getPathgrid()->applyPoint(macro, position);
|
||||
}
|
||||
}
|
||||
|
||||
void PathgridMode::secondaryEditPressed(const WorldspaceHitResult& hit)
|
||||
|
|
|
@ -127,6 +127,11 @@ std::string CSVRender::UnpagedWorldspaceWidget::getCellId (const osg::Vec3f& poi
|
|||
return mCellId;
|
||||
}
|
||||
|
||||
CSVRender::Cell* CSVRender::UnpagedWorldspaceWidget::getCell(const osg::Vec3d& point) const
|
||||
{
|
||||
return mCell.get();
|
||||
}
|
||||
|
||||
std::vector<osg::ref_ptr<CSVRender::TagBase> > CSVRender::UnpagedWorldspaceWidget::getSelection (
|
||||
unsigned int elementMask) const
|
||||
{
|
||||
|
|
|
@ -61,6 +61,8 @@ namespace CSVRender
|
|||
|
||||
virtual std::string getCellId (const osg::Vec3f& point) const;
|
||||
|
||||
virtual Cell* getCell(const osg::Vec3d& point) const;
|
||||
|
||||
virtual std::vector<osg::ref_ptr<TagBase> > getSelection (unsigned int elementMask)
|
||||
const;
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace CSVWidget
|
|||
namespace CSVRender
|
||||
{
|
||||
class TagBase;
|
||||
class Cell;
|
||||
class CellArrow;
|
||||
class EditMode;
|
||||
|
||||
|
@ -161,6 +162,9 @@ namespace CSVRender
|
|||
|
||||
virtual std::string getCellId (const osg::Vec3f& point) const = 0;
|
||||
|
||||
/// \note Returns the cell if it exists, otherwise a null pointer
|
||||
virtual Cell* getCell(const osg::Vec3d& point) const = 0;
|
||||
|
||||
virtual std::vector<osg::ref_ptr<TagBase> > getSelection (unsigned int elementMask)
|
||||
const = 0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue