1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 18:35:20 +00:00

Fix deleting physics object when scene nodes were still referencing it. Remove unused code from MouseState. Items that do not change are fetched only once.

This commit is contained in:
cc9cii 2014-11-03 12:46:31 +11:00
parent 4556eb74fe
commit bf5ba41223
4 changed files with 36 additions and 77 deletions

View File

@ -59,7 +59,18 @@ namespace CSVRender
, mCurrentObj(""), mMouseState(Mouse_Default), mOldPos(0,0), mMouseEventTimer(0), mPlane(0) , mCurrentObj(""), mMouseState(Mouse_Default), mOldPos(0,0), mMouseEventTimer(0), mPlane(0)
, mGrabbedSceneNode(""), mOrigObjPos(Ogre::Vector3()), mOrigMousePos(Ogre::Vector3()) , mGrabbedSceneNode(""), mOrigObjPos(Ogre::Vector3()), mOrigMousePos(Ogre::Vector3())
, mCurrentMousePos(Ogre::Vector3()), mOffset(0.0f) , mCurrentMousePos(Ogre::Vector3()), mOffset(0.0f)
, mColIndexPosX(0), mColIndexPosY(0), mColIndexPosZ(0), mIdTableModel(0)
//, mModel(0)
{ {
const CSMWorld::RefCollection& references = mParent->mDocument.getData().getReferences();
mColIndexPosX = references.findColumnIndex(CSMWorld::Columns::ColumnId_PositionXPos);
mColIndexPosY = references.findColumnIndex(CSMWorld::Columns::ColumnId_PositionYPos);
mColIndexPosZ = references.findColumnIndex(CSMWorld::Columns::ColumnId_PositionZPos);
mIdTableModel = static_cast<CSMWorld::IdTable *>(
mParent->mDocument.getData().getTableModel(CSMWorld::UniversalId::Type_Reference));
mMouseEventTimer = new QElapsedTimer(); mMouseEventTimer = new QElapsedTimer();
mMouseEventTimer->invalidate(); mMouseEventTimer->invalidate();
@ -138,22 +149,6 @@ namespace CSVRender
case Mouse_Grab: case Mouse_Grab:
case Mouse_Drag: case Mouse_Drag:
{ {
if(0 /*event->buttons() & ~Qt::RightButton*/)
{
// cancel operation & return the object to the original position
placeObject(mGrabbedSceneNode, mOrigObjPos);
mMouseState = Mouse_Default;
// reset states
mCurrentMousePos = Ogre::Vector3();
mOrigMousePos = Ogre::Vector3();
mOrigObjPos = Ogre::Vector3();
mGrabbedSceneNode = "";
mCurrentObj = "";
mOldPos = QPoint(0, 0);
mMouseEventTimer->invalidate();
mOffset = 0.0f;
}
break; break;
} }
case Mouse_Edit: case Mouse_Edit:
@ -216,16 +211,9 @@ namespace CSVRender
{ {
std::string referenceId = mPhysics->sceneNodeToRefId(result.first); std::string referenceId = mPhysics->sceneNodeToRefId(result.first);
std::cout << "ReferenceId: " << referenceId << std::endl; std::cout << "ReferenceId: " << referenceId << std::endl;
const CSMWorld::RefCollection& references = mParent->mDocument.getData().getReferences(); std::cout << " hit pos "+ QString::number(result.second.x).toStdString()
int index = references.searchId(referenceId); + ", " + QString::number(result.second.y).toStdString()
if (index != -1) + ", " + QString::number(result.second.z).toStdString() << std::endl;
{
int columnIndex =
references.findColumnIndex(CSMWorld::Columns::ColumnId_ReferenceableId);
std::cout << " index: " + QString::number(index).toStdString()
+", column index: " + QString::number(columnIndex).toStdString()
<< std::endl;
}
} }
} }
break; break;
@ -240,35 +228,21 @@ namespace CSVRender
{ {
std::pair<Ogre::Vector3, Ogre::Vector3> planeRes = planeAxis(); std::pair<Ogre::Vector3, Ogre::Vector3> planeRes = planeAxis();
Ogre::Vector3 pos = mOrigObjPos+planeRes.first*mOffset+planeResult.second-mOrigMousePos; Ogre::Vector3 pos = mOrigObjPos+planeRes.first*mOffset+planeResult.second-mOrigMousePos;
//placeObject(mGrabbedSceneNode, pos); // FIXME: auto updated via signals
// use the saved scene node name since the physics model has not moved yet // use the saved scene node name since the physics model has not moved yet
std::string referenceId = mPhysics->sceneNodeToRefId(mGrabbedSceneNode); std::string referenceId = mPhysics->sceneNodeToRefId(mGrabbedSceneNode);
QAbstractItemModel *model = mParent->mDocument.getUndoStack().push(new CSMWorld::ModifyCommand(*mIdTableModel,
mParent->mDocument.getData().getTableModel(CSMWorld::UniversalId::Type_Reference); mIdTableModel->getModelIndex(referenceId, mColIndexPosX), pos.x));
const CSMWorld::RefCollection& references = mParent->mDocument.getUndoStack().push(new CSMWorld::ModifyCommand(*mIdTableModel,
mParent->mDocument.getData().getReferences(); mIdTableModel->getModelIndex(referenceId, mColIndexPosY), pos.y));
mParent->mDocument.getUndoStack().push(new CSMWorld::ModifyCommand(*mIdTableModel,
int columnIndexPosX = mIdTableModel->getModelIndex(referenceId, mColIndexPosZ), pos.z));
references.findColumnIndex(CSMWorld::Columns::ColumnId_PositionXPos);
mParent->mDocument.getUndoStack().push(new CSMWorld::ModifyCommand(*model,
static_cast<CSMWorld::IdTable *>(model)->getModelIndex(referenceId,
columnIndexPosX), pos.x));
int columnIndexPosY =
references.findColumnIndex(CSMWorld::Columns::ColumnId_PositionYPos);
mParent->mDocument.getUndoStack().push(new CSMWorld::ModifyCommand(*model,
static_cast<CSMWorld::IdTable *>(model)->getModelIndex(referenceId,
columnIndexPosY), pos.y));
int columnIndexPosZ =
references.findColumnIndex(CSMWorld::Columns::ColumnId_PositionZPos);
mParent->mDocument.getUndoStack().push(new CSMWorld::ModifyCommand(*model,
static_cast<CSMWorld::IdTable *>(model)->getModelIndex(referenceId,
columnIndexPosZ), pos.z));
// FIXME: highlight current object?
//mCurrentObj = mGrabbedSceneNode; // FIXME: doesn't work? //mCurrentObj = mGrabbedSceneNode; // FIXME: doesn't work?
mCurrentObj = ""; // whether the object is selected mCurrentObj = ""; // whether the object is selected
// on screen
mMouseState = Mouse_Edit;
// reset states // reset states
mCurrentMousePos = Ogre::Vector3(); // mouse pos to use in wheel event mCurrentMousePos = Ogre::Vector3(); // mouse pos to use in wheel event
@ -277,9 +251,6 @@ namespace CSVRender
mGrabbedSceneNode = ""; // id of the object mGrabbedSceneNode = ""; // id of the object
mOffset = 0.0f; // used for z-axis movement mOffset = 0.0f; // used for z-axis movement
mOldPos = QPoint(0, 0); // to calculate relative movement of mouse mOldPos = QPoint(0, 0); // to calculate relative movement of mouse
// FIXME: highlight current object?
mMouseState = Mouse_Edit;
} }
} }
break; break;
@ -456,25 +427,6 @@ namespace CSVRender
return std::make_pair("", Ogre::Vector3()); return std::make_pair("", Ogre::Vector3());
} }
void MouseState::placeObject(const std::string sceneNode, const Ogre::Vector3 &pos)
{
mSceneManager->getSceneNode(sceneNode)->setPosition(pos);
// update physics
std::string refId = mPhysics->sceneNodeToRefId(sceneNode);
const CSMWorld::CellRef& cellref = mParent->mDocument.getData().getReferences().getRecord (refId).get();
Ogre::Quaternion xr (Ogre::Radian (-cellref.mPos.rot[0]), Ogre::Vector3::UNIT_X);
Ogre::Quaternion yr (Ogre::Radian (-cellref.mPos.rot[1]), Ogre::Vector3::UNIT_Y);
Ogre::Quaternion zr (Ogre::Radian (-cellref.mPos.rot[2]), Ogre::Vector3::UNIT_Z);
// FIXME: adjustRigidBody() seems to lose objects, work around by deleting and recreating objects
//mPhysics->moveObject(sceneNode, pos, xr*yr*zr);
mPhysics->replaceObject(sceneNode, cellref.mScale, pos, xr*yr*zr);
// update all SceneWidgets and their SceneManagers
updateSceneWidgets();
}
void MouseState::updateSceneWidgets() void MouseState::updateSceneWidgets()
{ {
std::map<Ogre::SceneManager*, CSVRender::SceneWidget *> sceneWidgets = mPhysics->sceneWidgets(); std::map<Ogre::SceneManager*, CSVRender::SceneWidget *> sceneWidgets = mPhysics->sceneWidgets();

View File

@ -22,6 +22,11 @@ namespace CSVWorld
class PhysicsSystem; class PhysicsSystem;
} }
namespace CSMWorld
{
class IdTable;
}
namespace CSVRender namespace CSVRender
{ {
class WorldspaceWidget; class WorldspaceWidget;
@ -51,7 +56,10 @@ namespace CSVRender
Ogre::Vector3 mCurrentMousePos; Ogre::Vector3 mCurrentMousePos;
float mOffset; float mOffset;
std::map<std::string, std::vector<std::string> > mSelectedEntities; CSMWorld::IdTable *mIdTableModel;
int mColIndexPosX;
int mColIndexPosY;
int mColIndexPosZ;
public: public:
@ -67,10 +75,8 @@ namespace CSVRender
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);
void placeObject(const std::string sceneNode, const Ogre::Vector3 &pos);
std::pair<std::string, Ogre::Vector3> terrainUnderCursor(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> objectUnderCursor(const int mouseX, const int mouseY); std::pair<std::string, Ogre::Vector3> objectUnderCursor(const int mouseX, const int mouseY);
void updateSelectionHighlight(const std::string sceneNode, const Ogre::Vector3 &position);
std::pair<Ogre::Vector3, Ogre::Vector3> planeAxis(); std::pair<Ogre::Vector3, Ogre::Vector3> planeAxis();
void updateSceneWidgets(); void updateSceneWidgets();
bool isDebug(); bool isDebug();

View File

@ -33,9 +33,6 @@ void CSVRender::Object::clearSceneNode (Ogre::SceneNode *node)
void CSVRender::Object::clear() void CSVRender::Object::clear()
{ {
if(!mObject.isNull())
mPhysics->removePhysicsObject(mBase->getName());
mObject.setNull(); mObject.setNull();
clearSceneNode (mBase); clearSceneNode (mBase);
@ -43,6 +40,9 @@ void CSVRender::Object::clear()
void CSVRender::Object::update() void CSVRender::Object::update()
{ {
if(!mObject.isNull())
mPhysics->removePhysicsObject(mBase->getName());
clear(); clear();
std::string model; std::string model;

View File

@ -154,6 +154,7 @@ namespace CSVWorld
} }
} }
// FIXME: adjustRigidBody() seems to lose objects, work around by deleting and recreating objects
void PhysicsSystem::moveObject(const std::string &sceneNodeName, void PhysicsSystem::moveObject(const std::string &sceneNodeName,
const Ogre::Vector3 &position, const Ogre::Quaternion &rotation) const Ogre::Vector3 &position, const Ogre::Quaternion &rotation)
{ {