From af434cffba97965cfb28d1f90a4dc739d10ff2d9 Mon Sep 17 00:00:00 2001 From: Nelsson Huotari Date: Wed, 4 Mar 2020 16:49:37 +0200 Subject: [PATCH] fix numeric limits min() to lowest(), fix correct drop height --- apps/opencs/view/render/instancemode.cpp | 32 ++++++++++++++---------- apps/opencs/view/render/instancemode.hpp | 10 ++++---- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/apps/opencs/view/render/instancemode.cpp b/apps/opencs/view/render/instancemode.cpp index 6f0ed01a0..d7ab59b53 100644 --- a/apps/opencs/view/render/instancemode.cpp +++ b/apps/opencs/view/render/instancemode.cpp @@ -110,13 +110,13 @@ CSVRender::InstanceMode::InstanceMode (WorldspaceWidget *worldspaceWidget, osg: // Following classes could be simplified by using QSignalMapper, which is obsolete in Qt5.10, but not in Qt4.8 and Qt5.14 CSMPrefs::Shortcut* dropToCollisionShortcut = new CSMPrefs::Shortcut("scene-instance-drop-collision", worldspaceWidget); - connect(dropToCollisionShortcut, SIGNAL(activated(bool)), this, SLOT(dropSelectedInstancesToCollision(bool))); + connect(dropToCollisionShortcut, SIGNAL(activated()), this, SLOT(dropSelectedInstancesToCollision())); CSMPrefs::Shortcut* dropToTerrainLevelShortcut = new CSMPrefs::Shortcut("scene-instance-drop-terrain", worldspaceWidget); - connect(dropToTerrainLevelShortcut, SIGNAL(activated(bool)), this, SLOT(dropSelectedInstancesToTerrain(bool))); + connect(dropToTerrainLevelShortcut, SIGNAL(activated()), this, SLOT(dropSelectedInstancesToTerrain())); CSMPrefs::Shortcut* dropToCollisionShortcut2 = new CSMPrefs::Shortcut("scene-instance-drop-collision-separately", worldspaceWidget); - connect(dropToCollisionShortcut2, SIGNAL(activated(bool)), this, SLOT(dropSelectedInstancesToCollisionSeparately(bool))); + connect(dropToCollisionShortcut2, SIGNAL(activated()), this, SLOT(dropSelectedInstancesToCollisionSeparately())); CSMPrefs::Shortcut* dropToTerrainLevelShortcut2 = new CSMPrefs::Shortcut("scene-instance-drop-terrain-separately", worldspaceWidget); - connect(dropToTerrainLevelShortcut2, SIGNAL(activated(bool)), this, SLOT(dropSelectedInstancesToTerrainSeparately(bool))); + connect(dropToTerrainLevelShortcut2, SIGNAL(activated()), this, SLOT(dropSelectedInstancesToTerrainSeparately())); } void CSVRender::InstanceMode::activate (CSVWidget::SceneToolbar *toolbar) @@ -699,13 +699,14 @@ void CSVRender::InstanceMode::deleteSelectedInstances(bool active) getWorldspaceWidget().clearSelection (SceneUtil::Mask_EditorReference); } -void CSVRender::InstanceMode::dropInstance(DropMode dropMode, CSVRender::Object* object) +void CSVRender::InstanceMode::dropInstance(DropMode dropMode, CSVRender::Object* object, float objectHeight) { const osg::Vec3d& point = object->getPosition().asVec3(); osg::Vec3d start = point; + start.z() += objectHeight; osg::Vec3d end = point; - end.z() = std::numeric_limits::min(); + end.z() = std::numeric_limits::lowest(); osg::ref_ptr intersector (new osgUtil::LineSegmentIntersector( osgUtil::Intersector::MODEL, start, end) ); @@ -723,7 +724,7 @@ void CSVRender::InstanceMode::dropInstance(DropMode dropMode, CSVRender::Object* osgUtil::LineSegmentIntersector::Intersection intersection = *it; ESM::Position position = object->getPosition(); object->setEdited (Object::Override_Position); - position.pos[2] = intersection.getWorldIntersectPoint().z(); + position.pos[2] = intersection.getWorldIntersectPoint().z() + objectHeight; object->setPosition(position.pos); return; @@ -735,8 +736,9 @@ float CSVRender::InstanceMode::getDropHeight(DropMode dropMode, CSVRender::Objec const osg::Vec3d& point = object->getPosition().asVec3(); osg::Vec3d start = point; + start.z() += objectHeight; osg::Vec3d end = point; - end.z() = std::numeric_limits::min(); + end.z() = std::numeric_limits::lowest(); osg::ref_ptr intersector (new osgUtil::LineSegmentIntersector( osgUtil::Intersector::MODEL, start, end) ); @@ -759,22 +761,22 @@ float CSVRender::InstanceMode::getDropHeight(DropMode dropMode, CSVRender::Objec return 0.0f; } -void CSVRender::InstanceMode::dropSelectedInstancesToCollision(bool active) +void CSVRender::InstanceMode::dropSelectedInstancesToCollision() { handleDropMethod(Collision, "Drop instances to next collision"); } -void CSVRender::InstanceMode::dropSelectedInstancesToTerrain(bool active) +void CSVRender::InstanceMode::dropSelectedInstancesToTerrain() { handleDropMethod(Terrain, "Drop instances to terrain level"); } -void CSVRender::InstanceMode::dropSelectedInstancesToCollisionSeparately(bool active) +void CSVRender::InstanceMode::dropSelectedInstancesToCollisionSeparately() { handleDropMethod(Terrain_sep, "Drop instances to next collision level separately"); } -void CSVRender::InstanceMode::dropSelectedInstancesToTerrainSeparately(bool active) +void CSVRender::InstanceMode::dropSelectedInstancesToTerrainSeparately() { handleDropMethod(Collision_sep, "Drop instances to terrain level separately"); } @@ -842,12 +844,16 @@ void CSVRender::InstanceMode::handleDropMethod(DropMode dropMode, QString comman case Terrain_sep: case Collision_sep: + { + int counter = 0; for(osg::ref_ptr tag: selection) if (CSVRender::ObjectTag *objectTag = dynamic_cast (tag.get())) { - dropInstance(dropMode, objectTag->mObject); + dropInstance(dropMode, objectTag->mObject, objectHeights[counter]); objectTag->mObject->apply (macro); + counter++; } + } break; default: break; diff --git a/apps/opencs/view/render/instancemode.hpp b/apps/opencs/view/render/instancemode.hpp index 38280dd6f..de7004f4f 100644 --- a/apps/opencs/view/render/instancemode.hpp +++ b/apps/opencs/view/render/instancemode.hpp @@ -57,7 +57,7 @@ namespace CSVRender osg::Vec3f getSelectionCenter(const std::vector >& selection) const; osg::Vec3f getScreenCoords(const osg::Vec3f& pos); - void dropInstance(DropMode dropMode, CSVRender::Object* object); + void dropInstance(DropMode dropMode, CSVRender::Object* object, float objectHeight); float getDropHeight(DropMode dropMode, CSVRender::Object* object, float objectHeight); public: @@ -108,10 +108,10 @@ namespace CSVRender void subModeChanged (const std::string& id); void deleteSelectedInstances(bool active); - void dropSelectedInstancesToCollision(bool active); - void dropSelectedInstancesToTerrain(bool active); - void dropSelectedInstancesToCollisionSeparately(bool active); - void dropSelectedInstancesToTerrainSeparately(bool active); + void dropSelectedInstancesToCollision(); + void dropSelectedInstancesToTerrain(); + void dropSelectedInstancesToCollisionSeparately(); + void dropSelectedInstancesToTerrainSeparately(); void handleDropMethod(DropMode dropMode, QString commandMsg); }; }