From 5c11266a4621e5a6368d40380d985e0686a50a33 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 22 Jul 2017 00:06:43 +0200 Subject: [PATCH] Fix character preview item selection --- apps/openmw/mwrender/characterpreview.cpp | 9 ++++++--- apps/openmw/mwrender/characterpreview.hpp | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwrender/characterpreview.cpp b/apps/openmw/mwrender/characterpreview.cpp index 877c35bba..217a0d1fb 100644 --- a/apps/openmw/mwrender/characterpreview.cpp +++ b/apps/openmw/mwrender/characterpreview.cpp @@ -256,7 +256,8 @@ namespace MWRender // NB Camera::setViewport has threading issues osg::ref_ptr stateset = new osg::StateSet; - stateset->setAttributeAndModes(new osg::Viewport(0, mSizeY-sizeY, std::min(mSizeX, sizeX), std::min(mSizeY, sizeY))); + mViewport = new osg::Viewport(0, mSizeY-sizeY, std::min(mSizeX, sizeX), std::min(mSizeY, sizeY)); + stateset->setAttributeAndModes(mViewport); mCamera->setStateSet(stateset); redraw(); @@ -334,8 +335,10 @@ namespace MWRender int InventoryPreview::getSlotSelected (int posX, int posY) { - float projX = (posX / mCamera->getViewport()->width()) * 2 - 1.f; - float projY = (posY / mCamera->getViewport()->height()) * 2 - 1.f; + if (!mViewport) + return -1; + float projX = (posX / mViewport->width()) * 2 - 1.f; + float projY = (posY / mViewport->height()) * 2 - 1.f; // With Intersector::WINDOW, the intersection ratios are slightly inaccurate. Seems to be a // precision issue - compiling with OSG_USE_FLOAT_MATRIX=0, Intersector::WINDOW works ok. // Using Intersector::PROJECTION results in better precision because the start/end points and the model matrices diff --git a/apps/openmw/mwrender/characterpreview.hpp b/apps/openmw/mwrender/characterpreview.hpp index f0d5ad0c9..b71bffb62 100644 --- a/apps/openmw/mwrender/characterpreview.hpp +++ b/apps/openmw/mwrender/characterpreview.hpp @@ -17,6 +17,7 @@ namespace osg class Texture2D; class Camera; class Group; + class Viewport; } namespace MWRender @@ -83,6 +84,8 @@ namespace MWRender int getSlotSelected(int posX, int posY); protected: + osg::ref_ptr mViewport; + virtual void onSetup(); };