diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index a225b4e11..943d09f1a 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -487,10 +487,8 @@ namespace MWGui { MyGUI::IntPoint mousePos = MyGUI::InputManager::getInstance ().getLastPressedPosition (MyGUI::MouseButton::Left); MyGUI::IntPoint relPos = mousePos - mAvatarImage->getAbsolutePosition (); - int realX = int(float(relPos.left) / float(mAvatarImage->getSize().width) * 512.f ); - int realY = int(float(relPos.top) / float(mAvatarImage->getSize().height) * 1024.f ); - MWWorld::Ptr itemSelected = getAvatarSelectedItem (realX, realY); + MWWorld::Ptr itemSelected = getAvatarSelectedItem (relPos.left, relPos.top); if (itemSelected.isEmpty ()) return; @@ -508,6 +506,8 @@ namespace MWGui MWWorld::Ptr InventoryWindow::getAvatarSelectedItem(int x, int y) { + // convert to OpenGL lower-left origin + y = (mAvatarImage->getHeight()-1) - y; int slot = mPreview->getSlotSelected (x, y); if (slot == -1) diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 14eed0e10..f423142e0 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -200,9 +200,7 @@ namespace MWGui { MyGUI::IntCoord avatarPos = focus->getAbsoluteCoord(); MyGUI::IntPoint relMousePos = MyGUI::InputManager::getInstance ().getMousePosition () - MyGUI::IntPoint(avatarPos.left, avatarPos.top); - int realX = int(float(relMousePos.left) / float(avatarPos.width) * 512.f ); - int realY = int(float(relMousePos.top) / float(avatarPos.height) * 1024.f ); - MWWorld::Ptr item = MWBase::Environment::get().getWindowManager()->getInventoryWindow ()->getAvatarSelectedItem (realX, realY); + MWWorld::Ptr item = MWBase::Environment::get().getWindowManager()->getInventoryWindow ()->getAvatarSelectedItem (relMousePos.left, relMousePos.top); mFocusObject = item; if (!mFocusObject.isEmpty ()) diff --git a/apps/openmw/mwrender/characterpreview.cpp b/apps/openmw/mwrender/characterpreview.cpp index 1a7b4ea39..cc6b4a9bb 100644 --- a/apps/openmw/mwrender/characterpreview.cpp +++ b/apps/openmw/mwrender/characterpreview.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include @@ -253,8 +255,21 @@ namespace MWRender int InventoryPreview::getSlotSelected (int posX, int posY) { - // TODO: implement - return 0; + osg::ref_ptr intersector (new osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, posX, posY)); + intersector->setIntersectionLimit(osgUtil::LineSegmentIntersector::LIMIT_ONE); + osgUtil::IntersectionVisitor visitor(intersector); + + osg::Node::NodeMask nodeMask = mCamera->getNodeMask(); + mCamera->setNodeMask(~0); + mCamera->accept(visitor); + mCamera->setNodeMask(nodeMask); + + if (intersector->containsIntersections()) + { + osgUtil::LineSegmentIntersector::Intersection intersection = intersector->getFirstIntersection(); + return mAnimation->getSlot(intersection.nodePath); + } + return -1; } void InventoryPreview::updatePtr(const MWWorld::Ptr &ptr) diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 2bb1b66fd..932da30b9 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -235,6 +235,21 @@ void NpcAnimation::rebuild() MWBase::Environment::get().getMechanicsManager()->forceStateUpdate(mPtr); } +int NpcAnimation::getSlot(const osg::NodePath &path) const +{ + for (int i=0; igetNode().get()) != path.end()) + { + return mPartslots[i]; + } + } + return -1; +} + void NpcAnimation::updateNpcBase() { clearAnimSources(); diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index a58f0fdf3..7ebc42784 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -174,6 +174,9 @@ public: /// Rebuilds the NPC, updating their root model, animation sources, and equipment. void rebuild(); + /// Get the inventory slot that the given node path leads into, or -1 if not found. + int getSlot(const osg::NodePath& path) const; + /// Make the NPC only partially visible virtual void setAlpha(float alpha); diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index c0eb00ea4..5ece10dc1 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -139,6 +139,8 @@ namespace MWRender mViewer->getCamera()->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR); mViewer->getCamera()->setCullingMode(cullingMode); + mViewer->getCamera()->setCullMask(~(Mask_UpdateVisitor)); + mViewDistance = Settings::Manager::getFloat("viewing distance", "Viewing distance"); mFieldOfView = Settings::Manager::getFloat("field of view", "General"); updateProjectionMatrix();