diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index c9be3bdcb..c18fa9dd2 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -668,6 +668,7 @@ namespace MWRender { RenderingManager::RayResult result; result.mHit = false; + result.mRatio = 0; if (intersector->containsIntersections()) { result.mHit = true; @@ -675,6 +676,7 @@ namespace MWRender result.mHitPointWorld = intersection.getWorldIntersectPoint(); result.mHitNormalWorld = intersection.getWorldIntersectNormal(); + result.mRatio = intersection.ratio; PtrHolder* ptrHolder = NULL; for (osg::NodePath::const_iterator it = intersection.nodePath.begin(); it != intersection.nodePath.end(); ++it) @@ -738,9 +740,7 @@ namespace MWRender mViewer->getCamera()->accept(*createIntersectionVisitor(intersector, ignorePlayer, ignoreActors)); - RayResult result = getIntersectionResult(intersector); - result.mDistanceToFirstIntersection = maxDistance * intersector->getFirstIntersection().ratio; - return result; + return getIntersectionResult(intersector); } void RenderingManager::updatePtr(const MWWorld::Ptr &old, const MWWorld::Ptr &updated) diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 3345d121f..d2adbd31f 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -120,7 +120,7 @@ namespace MWRender osg::Vec3f mHitNormalWorld; osg::Vec3f mHitPointWorld; MWWorld::Ptr mHitObject; - float mDistanceToFirstIntersection; + float mRatio; }; RayResult castRay(const osg::Vec3f& origin, const osg::Vec3f& dest, bool ignorePlayer, bool ignoreActors=false); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index f1cee80f1..35749049d 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1730,7 +1730,7 @@ namespace MWWorld MWRender::RenderingManager::RayResult rayToObject = mRendering->castCameraToViewportRay(x, y, maxDistance, ignorePlayer); facedObject = rayToObject.mHitObject; if (!facedObject.isEmpty()) - distance = rayToObject.mDistanceToFirstIntersection; + distance = rayToObject.mRatio * maxDistance; return facedObject; } else @@ -1738,7 +1738,7 @@ namespace MWWorld MWRender::RenderingManager::RayResult rayToObject = mRendering->castCameraToViewportRay(0.5f, 0.5f, maxDistance, ignorePlayer); facedObject = rayToObject.mHitObject; if (!facedObject.isEmpty()) - distance = rayToObject.mDistanceToFirstIntersection; + distance = rayToObject.mRatio * maxDistance; return facedObject; } }