1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2026-01-03 20:43:08 +00:00

Merge branch 'scaledselection' into 'master'

Editor: Account for pixel ratio in instance mode mouse coordinates conversion (#6573)

Closes #6573

See merge request OpenMW/openmw!4587
This commit is contained in:
psi29a 2025-07-01 21:34:40 +00:00
commit 149587dda4

View file

@ -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;