diff --git a/apps/opencs/view/render/mousestate.cpp b/apps/opencs/view/render/mousestate.cpp index f93442fae..5fda88637 100644 --- a/apps/opencs/view/render/mousestate.cpp +++ b/apps/opencs/view/render/mousestate.cpp @@ -59,7 +59,18 @@ namespace CSVRender , mCurrentObj(""), mMouseState(Mouse_Default), mOldPos(0,0), mMouseEventTimer(0), mPlane(0) , mGrabbedSceneNode(""), mOrigObjPos(Ogre::Vector3()), mOrigMousePos(Ogre::Vector3()) , 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( + mParent->mDocument.getData().getTableModel(CSMWorld::UniversalId::Type_Reference)); + mMouseEventTimer = new QElapsedTimer(); mMouseEventTimer->invalidate(); @@ -138,22 +149,6 @@ namespace CSVRender case Mouse_Grab: 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; } case Mouse_Edit: @@ -216,16 +211,9 @@ namespace CSVRender { std::string referenceId = mPhysics->sceneNodeToRefId(result.first); std::cout << "ReferenceId: " << referenceId << std::endl; - const CSMWorld::RefCollection& references = mParent->mDocument.getData().getReferences(); - int index = references.searchId(referenceId); - if (index != -1) - { - int columnIndex = - references.findColumnIndex(CSMWorld::Columns::ColumnId_ReferenceableId); - std::cout << " index: " + QString::number(index).toStdString() - +", column index: " + QString::number(columnIndex).toStdString() - << std::endl; - } + std::cout << " hit pos "+ QString::number(result.second.x).toStdString() + + ", " + QString::number(result.second.y).toStdString() + + ", " + QString::number(result.second.z).toStdString() << std::endl; } } break; @@ -240,35 +228,21 @@ namespace CSVRender { std::pair planeRes = planeAxis(); 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 std::string referenceId = mPhysics->sceneNodeToRefId(mGrabbedSceneNode); - QAbstractItemModel *model = - mParent->mDocument.getData().getTableModel(CSMWorld::UniversalId::Type_Reference); - const CSMWorld::RefCollection& references = - mParent->mDocument.getData().getReferences(); - - int columnIndexPosX = - references.findColumnIndex(CSMWorld::Columns::ColumnId_PositionXPos); - mParent->mDocument.getUndoStack().push(new CSMWorld::ModifyCommand(*model, - static_cast(model)->getModelIndex(referenceId, - columnIndexPosX), pos.x)); - int columnIndexPosY = - references.findColumnIndex(CSMWorld::Columns::ColumnId_PositionYPos); - mParent->mDocument.getUndoStack().push(new CSMWorld::ModifyCommand(*model, - static_cast(model)->getModelIndex(referenceId, - columnIndexPosY), pos.y)); - int columnIndexPosZ = - references.findColumnIndex(CSMWorld::Columns::ColumnId_PositionZPos); - mParent->mDocument.getUndoStack().push(new CSMWorld::ModifyCommand(*model, - static_cast(model)->getModelIndex(referenceId, - columnIndexPosZ), pos.z)); + mParent->mDocument.getUndoStack().push(new CSMWorld::ModifyCommand(*mIdTableModel, + mIdTableModel->getModelIndex(referenceId, mColIndexPosX), pos.x)); + mParent->mDocument.getUndoStack().push(new CSMWorld::ModifyCommand(*mIdTableModel, + mIdTableModel->getModelIndex(referenceId, mColIndexPosY), pos.y)); + mParent->mDocument.getUndoStack().push(new CSMWorld::ModifyCommand(*mIdTableModel, + mIdTableModel->getModelIndex(referenceId, mColIndexPosZ), pos.z)); + // FIXME: highlight current object? //mCurrentObj = mGrabbedSceneNode; // FIXME: doesn't work? mCurrentObj = ""; // whether the object is selected - // on screen + + mMouseState = Mouse_Edit; // reset states mCurrentMousePos = Ogre::Vector3(); // mouse pos to use in wheel event @@ -277,9 +251,6 @@ namespace CSVRender mGrabbedSceneNode = ""; // id of the object mOffset = 0.0f; // used for z-axis movement mOldPos = QPoint(0, 0); // to calculate relative movement of mouse - - // FIXME: highlight current object? - mMouseState = Mouse_Edit; } } break; @@ -456,25 +427,6 @@ namespace CSVRender 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() { std::map sceneWidgets = mPhysics->sceneWidgets(); diff --git a/apps/opencs/view/render/mousestate.hpp b/apps/opencs/view/render/mousestate.hpp index 498752db0..2493416ae 100644 --- a/apps/opencs/view/render/mousestate.hpp +++ b/apps/opencs/view/render/mousestate.hpp @@ -22,6 +22,11 @@ namespace CSVWorld class PhysicsSystem; } +namespace CSMWorld +{ + class IdTable; +} + namespace CSVRender { class WorldspaceWidget; @@ -51,7 +56,10 @@ namespace CSVRender Ogre::Vector3 mCurrentMousePos; float mOffset; - std::map > mSelectedEntities; + CSMWorld::IdTable *mIdTableModel; + int mColIndexPosX; + int mColIndexPosY; + int mColIndexPosZ; public: @@ -67,10 +75,8 @@ namespace CSVRender private: std::pair mousePositionOnPlane(const QPoint &pos, const Ogre::Plane &plane); - void placeObject(const std::string sceneNode, const Ogre::Vector3 &pos); std::pair terrainUnderCursor(const int mouseX, const int mouseY); std::pair objectUnderCursor(const int mouseX, const int mouseY); - void updateSelectionHighlight(const std::string sceneNode, const Ogre::Vector3 &position); std::pair planeAxis(); void updateSceneWidgets(); bool isDebug(); diff --git a/apps/opencs/view/render/object.cpp b/apps/opencs/view/render/object.cpp index f148bfe03..21219db8f 100644 --- a/apps/opencs/view/render/object.cpp +++ b/apps/opencs/view/render/object.cpp @@ -33,9 +33,6 @@ void CSVRender::Object::clearSceneNode (Ogre::SceneNode *node) void CSVRender::Object::clear() { - if(!mObject.isNull()) - mPhysics->removePhysicsObject(mBase->getName()); - mObject.setNull(); clearSceneNode (mBase); @@ -43,6 +40,9 @@ void CSVRender::Object::clear() void CSVRender::Object::update() { + if(!mObject.isNull()) + mPhysics->removePhysicsObject(mBase->getName()); + clear(); std::string model; diff --git a/apps/opencs/view/world/physicssystem.cpp b/apps/opencs/view/world/physicssystem.cpp index fc75d8d2c..73063b6be 100644 --- a/apps/opencs/view/world/physicssystem.cpp +++ b/apps/opencs/view/world/physicssystem.cpp @@ -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, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation) {