From 34a5eb7512f2dae1efe3e818875fc51ef1f5a32a Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Thu, 13 Mar 2025 18:42:55 +0300 Subject: [PATCH] Editor: Account for pixel ratio in instance mode mouse coordinates conversion (#6573) --- apps/opencs/view/render/instancemode.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/opencs/view/render/instancemode.cpp b/apps/opencs/view/render/instancemode.cpp index fb085f075a..03872a3d6c 100644 --- a/apps/opencs/view/render/instancemode.cpp +++ b/apps/opencs/view/render/instancemode.cpp @@ -171,16 +171,18 @@ osg::Vec3f CSVRender::InstanceMode::getProjectionSpaceCoords(const osg::Vec3f& p osg::Vec3f CSVRender::InstanceMode::getMousePlaneCoords(const QPoint& point, const osg::Vec3d& dragStart) { - osg::Matrix viewMatrix; - viewMatrix.invert(getWorldspaceWidget().getCamera()->getViewMatrix()); - osg::Matrix projMatrix; - projMatrix.invert(getWorldspaceWidget().getCamera()->getProjectionMatrix()); - osg::Matrix combined = projMatrix * viewMatrix; + const osg::Matrix viewMatrix = getWorldspaceWidget().getCamera()->getViewMatrix(); + const osg::Matrix projMatrix = getWorldspaceWidget().getCamera()->getProjectionMatrix(); + const osg::Matrix combined = osg::Matrix::inverse(viewMatrix * projMatrix); /* calculate viewport normalized coordinates note: is there a reason to use getCamera()->getViewport()->computeWindowMatrix() instead? */ - float x = (point.x() * 2) / getWorldspaceWidget().getCamera()->getViewport()->width() - 1.0f; - float y = 1.0f - (point.y() * 2) / getWorldspaceWidget().getCamera()->getViewport()->height(); + const float scale = getWorldspaceWidget().devicePixelRatioF(); + const osg::Viewport* viewport = getWorldspaceWidget().getCamera()->getViewport(); + float x = point.x() * scale / viewport->width(); + float y = point.y() * scale / viewport->height(); + x = x * 2.0f - 1.0f; + y = 1.0f - y * 2.0f; osg::Vec3f mousePlanePoint = osg::Vec3f(x, y, dragStart.z()) * combined;