mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-25 09:39:42 +00:00
Allow adding or dragging pathgrid points over objects as well as terrain.
This commit is contained in:
parent
89eb30054b
commit
1f73fae6ef
5 changed files with 57 additions and 34 deletions
|
@ -315,8 +315,7 @@ float CSVRender::Cell::getTerrainHeightAt(const Ogre::Vector3 &pos) const
|
||||||
|
|
||||||
// FIXME:
|
// FIXME:
|
||||||
// - updating indicies
|
// - updating indicies
|
||||||
// - add pathgrid point above an object
|
// - adding edges (need the ability to select a pathgrid and highlight)
|
||||||
// - adding edges
|
|
||||||
// - save to document & signals
|
// - save to document & signals
|
||||||
// - repainting edges while moving
|
// - repainting edges while moving
|
||||||
void CSVRender::Cell::loadPathgrid()
|
void CSVRender::Cell::loadPathgrid()
|
||||||
|
|
|
@ -234,8 +234,9 @@ namespace CSVRender
|
||||||
// move pathgrid point, but don't save yet (need pathgrid
|
// move pathgrid point, but don't save yet (need pathgrid
|
||||||
// table feature & its data structure to be completed)
|
// table feature & its data structure to be completed)
|
||||||
// FIXME: need to signal PathgridPoint object of change
|
// FIXME: need to signal PathgridPoint object of change
|
||||||
|
// FIXME: shouldn't allow pathgrid points under the cursor
|
||||||
std::pair<std::string, Ogre::Vector3> result =
|
std::pair<std::string, Ogre::Vector3> result =
|
||||||
terrainUnderCursor(event->x(), event->y()); // FIXME: some pathgrid points are on objects
|
anyUnderCursor(event->x(), event->y());
|
||||||
if(result.first != "")
|
if(result.first != "")
|
||||||
{
|
{
|
||||||
// FIXME: rather than just updating at the end, should
|
// FIXME: rather than just updating at the end, should
|
||||||
|
@ -243,8 +244,6 @@ namespace CSVRender
|
||||||
// while dragging the pathgrid point (maybe check whether
|
// while dragging the pathgrid point (maybe check whether
|
||||||
// the object is a pathgrid point at the begging and set
|
// the object is a pathgrid point at the begging and set
|
||||||
// a flag?)
|
// a flag?)
|
||||||
// FIXME: this also disallows dragging over objects, so
|
|
||||||
// may need to use ignoreObjects while raycasting
|
|
||||||
placeObject(mGrabbedSceneNode, result.second);
|
placeObject(mGrabbedSceneNode, result.second);
|
||||||
mParent->pathgridMoved(referenceId, result.second);
|
mParent->pathgridMoved(referenceId, result.second);
|
||||||
}
|
}
|
||||||
|
@ -440,13 +439,7 @@ namespace CSVRender
|
||||||
|
|
||||||
std::pair<std::string, Ogre::Vector3> MouseState::terrainUnderCursor(const int mouseX, const int mouseY)
|
std::pair<std::string, Ogre::Vector3> MouseState::terrainUnderCursor(const int mouseX, const int mouseY)
|
||||||
{
|
{
|
||||||
if(!getViewport())
|
std::pair<std::string, Ogre::Vector3> result = anyUnderCursor(mouseX, mouseY);
|
||||||
return std::make_pair("", Ogre::Vector3());
|
|
||||||
|
|
||||||
float x = (float) mouseX / getViewport()->getActualWidth();
|
|
||||||
float y = (float) mouseY / getViewport()->getActualHeight();
|
|
||||||
|
|
||||||
std::pair<std::string, Ogre::Vector3> result = mPhysics->castRay(x, y, mSceneManager, getCamera());
|
|
||||||
if(result.first != "")
|
if(result.first != "")
|
||||||
{
|
{
|
||||||
// FIXME: is there a better way to distinguish terrain from objects?
|
// FIXME: is there a better way to distinguish terrain from objects?
|
||||||
|
@ -463,13 +456,7 @@ namespace CSVRender
|
||||||
// NOTE: also returns pathgrids
|
// NOTE: also returns pathgrids
|
||||||
std::pair<std::string, Ogre::Vector3> MouseState::objectUnderCursor(const int mouseX, const int mouseY)
|
std::pair<std::string, Ogre::Vector3> MouseState::objectUnderCursor(const int mouseX, const int mouseY)
|
||||||
{
|
{
|
||||||
if(!getViewport())
|
std::pair<std::string, Ogre::Vector3> result = anyUnderCursor(mouseX, mouseY);
|
||||||
return std::make_pair("", Ogre::Vector3());
|
|
||||||
|
|
||||||
float x = (float) mouseX / getViewport()->getActualWidth();
|
|
||||||
float y = (float) mouseY / getViewport()->getActualHeight();
|
|
||||||
|
|
||||||
std::pair<std::string, Ogre::Vector3> result = mPhysics->castRay(x, y, mSceneManager, getCamera());
|
|
||||||
if(result.first != "")
|
if(result.first != "")
|
||||||
{
|
{
|
||||||
// NOTE: anything not terrain is assumed to be an object, e.g pathgrid points
|
// NOTE: anything not terrain is assumed to be an object, e.g pathgrid points
|
||||||
|
@ -490,6 +477,23 @@ namespace CSVRender
|
||||||
return std::make_pair("", Ogre::Vector3());
|
return std::make_pair("", Ogre::Vector3());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::pair<std::string, Ogre::Vector3> MouseState::anyUnderCursor(const int mouseX, const int mouseY)
|
||||||
|
{
|
||||||
|
if(!getViewport())
|
||||||
|
return std::make_pair("", Ogre::Vector3());
|
||||||
|
|
||||||
|
float x = (float) mouseX / getViewport()->getActualWidth();
|
||||||
|
float y = (float) mouseY / getViewport()->getActualHeight();
|
||||||
|
|
||||||
|
std::pair<std::string, Ogre::Vector3> result = mPhysics->castRay(x, y, mSceneManager, getCamera());
|
||||||
|
if(result.first != "")
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::make_pair("", Ogre::Vector3());
|
||||||
|
}
|
||||||
|
|
||||||
void MouseState::updateSceneWidgets()
|
void MouseState::updateSceneWidgets()
|
||||||
{
|
{
|
||||||
std::map<Ogre::SceneManager*, CSVRender::SceneWidget *> sceneWidgets = mPhysics->sceneWidgets();
|
std::map<Ogre::SceneManager*, CSVRender::SceneWidget *> sceneWidgets = mPhysics->sceneWidgets();
|
||||||
|
|
|
@ -72,13 +72,14 @@ namespace CSVRender
|
||||||
void mouseDoubleClickEvent (QMouseEvent *event);
|
void mouseDoubleClickEvent (QMouseEvent *event);
|
||||||
bool wheelEvent (QWheelEvent *event);
|
bool wheelEvent (QWheelEvent *event);
|
||||||
std::pair<std::string, Ogre::Vector3> pgPointUnderCursor(const int mouseX, const int mouseY);
|
std::pair<std::string, Ogre::Vector3> pgPointUnderCursor(const int mouseX, const int mouseY);
|
||||||
std::pair<std::string, Ogre::Vector3> terrainUnderCursor(const int mouseX, const int mouseY);
|
std::pair<std::string, Ogre::Vector3> anyUnderCursor(const int mouseX, const int mouseY);
|
||||||
|
|
||||||
void cancelDrag();
|
void cancelDrag();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::pair<bool, Ogre::Vector3> mousePositionOnPlane(const QPoint &pos, const Ogre::Plane &plane);
|
std::pair<bool, Ogre::Vector3> mousePositionOnPlane(const QPoint &pos, const Ogre::Plane &plane);
|
||||||
|
std::pair<std::string, Ogre::Vector3> terrainUnderCursor(const int mouseX, const int mouseY);
|
||||||
std::pair<std::string, Ogre::Vector3> objectUnderCursor(const int mouseX, const int mouseY);
|
std::pair<std::string, Ogre::Vector3> objectUnderCursor(const int mouseX, const int mouseY);
|
||||||
std::pair<Ogre::Vector3, Ogre::Vector3> planeAxis();
|
std::pair<Ogre::Vector3, Ogre::Vector3> planeAxis();
|
||||||
void updateSceneWidgets();
|
void updateSceneWidgets();
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "../../model/world/idtable.hpp"
|
#include "../../model/world/idtable.hpp"
|
||||||
|
|
||||||
#include "../widget/scenetooltoggle.hpp"
|
#include "../widget/scenetooltoggle.hpp"
|
||||||
|
#include "../world/physicssystem.hpp"
|
||||||
|
|
||||||
#include "pathgridpoint.hpp"
|
#include "pathgridpoint.hpp"
|
||||||
#include "elements.hpp"
|
#include "elements.hpp"
|
||||||
|
@ -332,26 +333,44 @@ CSVRender::Cell *CSVRender::PagedWorldspaceWidget::findCell(const std::string &c
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: pathgrid may be inserted above an object, the parsing needs to change
|
// NOTE: allow placing pathgrid points above objects and terrain
|
||||||
void CSVRender::PagedWorldspaceWidget::pathgridInserted (const std::string &terrain, const Ogre::Vector3 &pos)
|
void CSVRender::PagedWorldspaceWidget::pathgridInserted (const std::string &name, const Ogre::Vector3 &pos)
|
||||||
{
|
{
|
||||||
// decode name
|
QString id = QString(name.c_str());
|
||||||
QString id = QString(terrain.c_str());
|
std::string referenceId = getPhysics()->sceneNodeToRefId(name); // FIXME: move back
|
||||||
QRegExp terrainRe("^HeightField_([\\d-]+)_([\\d-]+)$");
|
|
||||||
|
|
||||||
if (id.isEmpty() || !id.startsWith("HeightField_"))
|
bool terrain = id.startsWith("HeightField_");
|
||||||
|
bool object = QString(referenceId.c_str()).startsWith("ref#");
|
||||||
|
// don't allow placing another one on top of a pathgrid point
|
||||||
|
if (id.isEmpty() || (!terrain && !object))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (terrainRe.indexIn(id) == -1)
|
std::string cellId;
|
||||||
return;
|
if(terrain)
|
||||||
|
{
|
||||||
|
QRegExp nameRe("^HeightField_([\\d-]+)_([\\d-]+)$");
|
||||||
|
if (nameRe.indexIn(id) == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
int cellX = terrainRe.cap(1).toInt();
|
int cellX = nameRe.cap(1).toInt();
|
||||||
int cellY = terrainRe.cap(2).toInt();
|
int cellY = nameRe.cap(2).toInt();
|
||||||
|
|
||||||
std::ostringstream stream;
|
std::ostringstream stream;
|
||||||
stream << "#" << cellX << " " << cellY;
|
stream << "#" << cellX << " " << cellY;
|
||||||
|
cellId = stream.str();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const CSMWorld::RefCollection& references = mDocument.getData().getReferences();
|
||||||
|
int index = references.searchId(referenceId);
|
||||||
|
if(index == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
Cell *cell = findCell(stream.str());
|
cellId = references.getData(index, references.findColumnIndex(CSMWorld::Columns::ColumnId_Cell))
|
||||||
|
.toString().toUtf8().constData();
|
||||||
|
}
|
||||||
|
|
||||||
|
Cell *cell = findCell(cellId);
|
||||||
if(cell)
|
if(cell)
|
||||||
{
|
{
|
||||||
cell->pathgridPointAdded(pos);
|
cell->pathgridPointAdded(pos);
|
||||||
|
|
|
@ -422,7 +422,7 @@ void CSVRender::WorldspaceWidget::keyPressEvent (QKeyEvent *event)
|
||||||
else if(event->key() == Qt::Key_Insert)
|
else if(event->key() == Qt::Key_Insert)
|
||||||
{
|
{
|
||||||
QPoint p = this->mapFromGlobal(QCursor::pos());
|
QPoint p = this->mapFromGlobal(QCursor::pos());
|
||||||
std::pair<std::string, Ogre::Vector3> result = mMouse->terrainUnderCursor(p.x(), p.y());
|
std::pair<std::string, Ogre::Vector3> result = mMouse->anyUnderCursor(p.x(), p.y());
|
||||||
if(result.first != "")
|
if(result.first != "")
|
||||||
{
|
{
|
||||||
pathgridInserted(result.first, result.second);
|
pathgridInserted(result.first, result.second);
|
||||||
|
|
Loading…
Reference in a new issue