1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-04-10 06:44:29 +00:00

Store object origins and move difference

This commit is contained in:
unelsson 2021-09-01 00:15:10 +03:00
parent 0d511da615
commit 840e7615f5
2 changed files with 18 additions and 7 deletions

View File

@ -297,6 +297,8 @@ bool CSVRender::InstanceMode::primaryEditStartDrag (const QPoint& pos)
return false; return false;
} }
mObjectsAtDragStart.clear();
for (std::vector<osg::ref_ptr<TagBase> >::iterator iter (selection.begin()); for (std::vector<osg::ref_ptr<TagBase> >::iterator iter (selection.begin());
iter!=selection.end(); ++iter) iter!=selection.end(); ++iter)
{ {
@ -305,9 +307,12 @@ bool CSVRender::InstanceMode::primaryEditStartDrag (const QPoint& pos)
if (mSubModeId == "move") if (mSubModeId == "move")
{ {
objectTag->mObject->setEdited (Object::Override_Position); objectTag->mObject->setEdited (Object::Override_Position);
mDragStart.x() = objectTag->mObject->getPosition().pos[0]; double x = objectTag->mObject->getPosition().pos[0];
mDragStart.y() = objectTag->mObject->getPosition().pos[1]; double y = objectTag->mObject->getPosition().pos[1];
mDragStart.z() = objectTag->mObject->getPosition().pos[2]; double z = objectTag->mObject->getPosition().pos[2];
osg::Vec3d thisPoint(x, y, z);
mDragStart = getMousePlaneCoords(pos, getProjectionSpaceCoords(thisPoint));
mObjectsAtDragStart.emplace_back(thisPoint);
mDragMode = DragMode_Move; mDragMode = DragMode_Move;
} }
else if (mSubModeId == "rotate") else if (mSubModeId == "rotate")
@ -495,8 +500,10 @@ void CSVRender::InstanceMode::drag (const QPoint& pos, int diffX, int diffY, dou
return; return;
} }
int i = 0;
// Apply // Apply
for (std::vector<osg::ref_ptr<TagBase> >::iterator iter (selection.begin()); iter!=selection.end(); ++iter) for (std::vector<osg::ref_ptr<TagBase> >::iterator iter (selection.begin()); iter!=selection.end(); ++iter, i++)
{ {
if (CSVRender::ObjectTag *objectTag = dynamic_cast<CSVRender::ObjectTag *> (iter->get())) if (CSVRender::ObjectTag *objectTag = dynamic_cast<CSVRender::ObjectTag *> (iter->get()))
{ {
@ -504,9 +511,12 @@ void CSVRender::InstanceMode::drag (const QPoint& pos, int diffX, int diffY, dou
{ {
ESM::Position position = objectTag->mObject->getPosition(); ESM::Position position = objectTag->mObject->getPosition();
osg::Vec3d mousePos = getMousePlaneCoords(pos, getProjectionSpaceCoords(mDragStart)); osg::Vec3d mousePos = getMousePlaneCoords(pos, getProjectionSpaceCoords(mDragStart));
position.pos[0] = mousePos.x(); float addToX = mousePos.x() - mDragStart.x();
position.pos[1] = mousePos.y(); float addToY = mousePos.y() - mDragStart.y();
position.pos[2] = mousePos.z(); float addToZ = mousePos.z() - mDragStart.z();
position.pos[0] = mObjectsAtDragStart[i].x() + addToX;
position.pos[1] = mObjectsAtDragStart[i].y() + addToY;
position.pos[2] = mObjectsAtDragStart[i].z() + addToZ;
objectTag->mObject->setPosition(position.pos); objectTag->mObject->setPosition(position.pos);
} }

View File

@ -46,6 +46,7 @@ namespace CSVRender
float mUnitScaleDist; float mUnitScaleDist;
osg::ref_ptr<osg::Group> mParentNode; osg::ref_ptr<osg::Group> mParentNode;
osg::Vec3d mDragStart; osg::Vec3d mDragStart;
std::vector<osg::Vec3d> mObjectsAtDragStart;
int getSubModeFromId (const std::string& id) const; int getSubModeFromId (const std::string& id) const;