Fix character preview item selection

pull/245/head
scrawl 8 years ago
parent c9f8a220dc
commit 5c11266a46

@ -256,7 +256,8 @@ namespace MWRender
// NB Camera::setViewport has threading issues // NB Camera::setViewport has threading issues
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet; osg::ref_ptr<osg::StateSet> 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); mCamera->setStateSet(stateset);
redraw(); redraw();
@ -334,8 +335,10 @@ namespace MWRender
int InventoryPreview::getSlotSelected (int posX, int posY) int InventoryPreview::getSlotSelected (int posX, int posY)
{ {
float projX = (posX / mCamera->getViewport()->width()) * 2 - 1.f; if (!mViewport)
float projY = (posY / mCamera->getViewport()->height()) * 2 - 1.f; 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 // 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. // 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 // Using Intersector::PROJECTION results in better precision because the start/end points and the model matrices

@ -17,6 +17,7 @@ namespace osg
class Texture2D; class Texture2D;
class Camera; class Camera;
class Group; class Group;
class Viewport;
} }
namespace MWRender namespace MWRender
@ -83,6 +84,8 @@ namespace MWRender
int getSlotSelected(int posX, int posY); int getSlotSelected(int posX, int posY);
protected: protected:
osg::ref_ptr<osg::Viewport> mViewport;
virtual void onSetup(); virtual void onSetup();
}; };

Loading…
Cancel
Save