diff --git a/apps/opencs/view/render/mousestate.cpp b/apps/opencs/view/render/mousestate.cpp index 65596b752d..e62a4b1ff8 100644 --- a/apps/opencs/view/render/mousestate.cpp +++ b/apps/opencs/view/render/mousestate.cpp @@ -237,7 +237,8 @@ namespace CSVRender // table feature & its data structure to be completed) // Also need to signal PathgridPoint object of change std::pair result = - mPhysics->distToClosest(pos, getCamera(), 600); // snap + mPhysics->distToClosest(pos, + getCamera()->getViewport()->getVisibilityMask(), 600); // snap if(result.first != "" && // don't allow pathgrid points under the cursor !QString(result.first.c_str()).contains(QRegExp("^Pathgrid"))) @@ -474,7 +475,20 @@ namespace CSVRender float x = (float) mouseX / getViewport()->getActualWidth(); float y = (float) mouseY / getViewport()->getActualHeight(); - return mPhysics->castRay(x, y, mSceneManager, getCamera(), elements); + std::pair result = mPhysics->castRay(x, y, mSceneManager, getCamera()); + + if(result.first != "" && + ((elements & (Ogre::uint32)CSVRender::Element_Terrain && + QString(result.first.c_str()).contains(QRegExp("^Height"))) || + (elements & (Ogre::uint32)CSVRender::Element_Reference && + QString(result.first.c_str()).contains(QRegExp("^ref#"))) || + (elements & (Ogre::uint32)CSVRender::Element_Pathgrid && + QString(result.first.c_str()).contains(QRegExp("^Pathgrid"))))) + { + return result; + } + else + return std::make_pair("", Ogre::Vector3()); } void MouseState::updateSceneWidgets() diff --git a/apps/opencs/view/render/mousestate.hpp b/apps/opencs/view/render/mousestate.hpp index d55d5f6c30..cde53f2c58 100644 --- a/apps/opencs/view/render/mousestate.hpp +++ b/apps/opencs/view/render/mousestate.hpp @@ -73,7 +73,7 @@ namespace CSVRender bool wheelEvent (QWheelEvent *event); std::pair underCursor(const int mouseX, - const int mouseY, Ogre::uint32 elements); + const int mouseY, Ogre::uint32 elements = 0xFFFFFFFF); void cancelDrag(); diff --git a/apps/opencs/view/world/physicssystem.cpp b/apps/opencs/view/world/physicssystem.cpp index 9012a06c2c..6450b5cf6c 100644 --- a/apps/opencs/view/world/physicssystem.cpp +++ b/apps/opencs/view/world/physicssystem.cpp @@ -214,8 +214,7 @@ namespace CSVWorld // WARNING: far clip distance is a global setting, if it changes in future // this method will need to be updated std::pair PhysicsSystem::castRay(float mouseX, - float mouseY, Ogre::SceneManager *sceneMgr, Ogre::Camera *camera, - Ogre::uint32 elements) + float mouseY, Ogre::SceneManager *sceneMgr, Ogre::Camera *camera) { // NOTE: there could be more than one camera for the scene manager // TODO: check whether camera belongs to sceneMgr @@ -261,28 +260,19 @@ namespace CSVWorld } // result.first is the object's referenceId - if(result.first != "" && - ((elements & (Ogre::uint32)CSVRender::Element_Terrain && - QString(result.first.c_str()).contains(QRegExp("^Height"))) || - (elements & (Ogre::uint32)CSVRender::Element_Reference && - QString(result.first.c_str()).contains(QRegExp("^ref#"))) || - (elements & (Ogre::uint32)CSVRender::Element_Pathgrid && - QString(result.first.c_str()).contains(QRegExp("^Pathgrid"))))) - { - return std::make_pair(result.first, ray.getPoint(farClipDist*result.second)); - } - else + if(result.first == "") return std::make_pair("", Ogre::Vector3()); + else + return std::make_pair(result.first, ray.getPoint(farClipDist*result.second)); } std::pair PhysicsSystem::distToGround(const Ogre::Vector3 &position, - Ogre::Camera *camera, const float limit, bool ignorePgPoint) + Ogre::uint32 visibilityMask, const float limit, bool ignorePgPoint) { btVector3 _from, _to; _from = btVector3(position.x, position.y, position.z); _to = btVector3(position.x, position.y, position.z-limit); - Ogre::uint32 visibilityMask = camera->getViewport()->getVisibilityMask(); bool ignoreHeightMap = !(visibilityMask & (Ogre::uint32)CSVRender::Element_Terrain); bool ignoreObjects = !(visibilityMask & (Ogre::uint32)CSVRender::Element_Reference); bool ignorePathgrid = ignorePgPoint || @@ -315,13 +305,13 @@ namespace CSVWorld // tries to find the distance to the "top" of the closest object std::pair PhysicsSystem::distToClosest(const Ogre::Vector3 &position, - Ogre::Camera *camera, const float limit) + Ogre::uint32 visibilityMask, const float limit) { const float thickness = 50; // arbitrary number std::pair resDown = distToGround(Ogre::Vector3(position.x, position.y, position.z+thickness), - camera, limit+thickness, true); + visibilityMask, limit+thickness, true); if(resDown.first != "") return std::make_pair(resDown.first, resDown.second-thickness); diff --git a/apps/opencs/view/world/physicssystem.hpp b/apps/opencs/view/world/physicssystem.hpp index 5543c84b96..f71ab685c7 100644 --- a/apps/opencs/view/world/physicssystem.hpp +++ b/apps/opencs/view/world/physicssystem.hpp @@ -73,14 +73,13 @@ namespace CSVWorld // return the object's SceneNode name and position for the given SceneManager std::pair castRay(float mouseX, - float mouseY, Ogre::SceneManager *sceneMgr, Ogre::Camera *camera, - Ogre::uint32 elements = 0xFFFFFFFF); + float mouseY, Ogre::SceneManager *sceneMgr, Ogre::Camera *camera); std::pair distToGround(const Ogre::Vector3 &position, - Ogre::Camera *camera, const float limit = 300000, bool ignorePgPoint = false); + Ogre::uint32 visibilityMask, const float limit = 300000, bool ignorePgPoint = false); std::pair distToClosest(const Ogre::Vector3 &position, - Ogre::Camera *camera, const float limit = 100.0f); + Ogre::uint32 visibilityMask, const float limit = 100.0f); std::string refIdToSceneNode(std::string referenceId, Ogre::SceneManager *sceneMgr);