1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-04-17 20:42:29 +00:00

fix numeric limits min() to lowest(), fix correct drop height

This commit is contained in:
Nelsson Huotari 2020-03-04 16:49:37 +02:00
parent 035d5205d9
commit af434cffba
2 changed files with 24 additions and 18 deletions

View File

@ -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 // 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); 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); 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); 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); 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) void CSVRender::InstanceMode::activate (CSVWidget::SceneToolbar *toolbar)
@ -699,13 +699,14 @@ void CSVRender::InstanceMode::deleteSelectedInstances(bool active)
getWorldspaceWidget().clearSelection (SceneUtil::Mask_EditorReference); 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(); const osg::Vec3d& point = object->getPosition().asVec3();
osg::Vec3d start = point; osg::Vec3d start = point;
start.z() += objectHeight;
osg::Vec3d end = point; osg::Vec3d end = point;
end.z() = std::numeric_limits<float>::min(); end.z() = std::numeric_limits<float>::lowest();
osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector (new osgUtil::LineSegmentIntersector( osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector (new osgUtil::LineSegmentIntersector(
osgUtil::Intersector::MODEL, start, end) ); osgUtil::Intersector::MODEL, start, end) );
@ -723,7 +724,7 @@ void CSVRender::InstanceMode::dropInstance(DropMode dropMode, CSVRender::Object*
osgUtil::LineSegmentIntersector::Intersection intersection = *it; osgUtil::LineSegmentIntersector::Intersection intersection = *it;
ESM::Position position = object->getPosition(); ESM::Position position = object->getPosition();
object->setEdited (Object::Override_Position); object->setEdited (Object::Override_Position);
position.pos[2] = intersection.getWorldIntersectPoint().z(); position.pos[2] = intersection.getWorldIntersectPoint().z() + objectHeight;
object->setPosition(position.pos); object->setPosition(position.pos);
return; return;
@ -735,8 +736,9 @@ float CSVRender::InstanceMode::getDropHeight(DropMode dropMode, CSVRender::Objec
const osg::Vec3d& point = object->getPosition().asVec3(); const osg::Vec3d& point = object->getPosition().asVec3();
osg::Vec3d start = point; osg::Vec3d start = point;
start.z() += objectHeight;
osg::Vec3d end = point; osg::Vec3d end = point;
end.z() = std::numeric_limits<float>::min(); end.z() = std::numeric_limits<float>::lowest();
osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector (new osgUtil::LineSegmentIntersector( osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector (new osgUtil::LineSegmentIntersector(
osgUtil::Intersector::MODEL, start, end) ); osgUtil::Intersector::MODEL, start, end) );
@ -759,22 +761,22 @@ float CSVRender::InstanceMode::getDropHeight(DropMode dropMode, CSVRender::Objec
return 0.0f; return 0.0f;
} }
void CSVRender::InstanceMode::dropSelectedInstancesToCollision(bool active) void CSVRender::InstanceMode::dropSelectedInstancesToCollision()
{ {
handleDropMethod(Collision, "Drop instances to next collision"); handleDropMethod(Collision, "Drop instances to next collision");
} }
void CSVRender::InstanceMode::dropSelectedInstancesToTerrain(bool active) void CSVRender::InstanceMode::dropSelectedInstancesToTerrain()
{ {
handleDropMethod(Terrain, "Drop instances to terrain level"); 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"); 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"); handleDropMethod(Collision_sep, "Drop instances to terrain level separately");
} }
@ -842,11 +844,15 @@ void CSVRender::InstanceMode::handleDropMethod(DropMode dropMode, QString comman
case Terrain_sep: case Terrain_sep:
case Collision_sep: case Collision_sep:
{
int counter = 0;
for(osg::ref_ptr<TagBase> tag: selection) for(osg::ref_ptr<TagBase> tag: selection)
if (CSVRender::ObjectTag *objectTag = dynamic_cast<CSVRender::ObjectTag *> (tag.get())) if (CSVRender::ObjectTag *objectTag = dynamic_cast<CSVRender::ObjectTag *> (tag.get()))
{ {
dropInstance(dropMode, objectTag->mObject); dropInstance(dropMode, objectTag->mObject, objectHeights[counter]);
objectTag->mObject->apply (macro); objectTag->mObject->apply (macro);
counter++;
}
} }
break; break;
default: default:

View File

@ -57,7 +57,7 @@ namespace CSVRender
osg::Vec3f getSelectionCenter(const std::vector<osg::ref_ptr<TagBase> >& selection) const; osg::Vec3f getSelectionCenter(const std::vector<osg::ref_ptr<TagBase> >& selection) const;
osg::Vec3f getScreenCoords(const osg::Vec3f& pos); 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); float getDropHeight(DropMode dropMode, CSVRender::Object* object, float objectHeight);
public: public:
@ -108,10 +108,10 @@ namespace CSVRender
void subModeChanged (const std::string& id); void subModeChanged (const std::string& id);
void deleteSelectedInstances(bool active); void deleteSelectedInstances(bool active);
void dropSelectedInstancesToCollision(bool active); void dropSelectedInstancesToCollision();
void dropSelectedInstancesToTerrain(bool active); void dropSelectedInstancesToTerrain();
void dropSelectedInstancesToCollisionSeparately(bool active); void dropSelectedInstancesToCollisionSeparately();
void dropSelectedInstancesToTerrainSeparately(bool active); void dropSelectedInstancesToTerrainSeparately();
void handleDropMethod(DropMode dropMode, QString commandMsg); void handleDropMethod(DropMode dropMode, QString commandMsg);
}; };
} }