PickRay Intersection z-coordinate

Mar 18, 2011 at 4:01 PM

I am working on an app that measures the distance between two arbitrary points in the Viewport using standard units.  X, Y are determined by the mouse click but Z is determined by the Node intersection.  I haven't been able to find the Z value.  If I use pickRay.Intersects(transformedSphere).Value I always get 0;

Mar 21, 2011 at 2:32 PM

I'm not sure why you are getting zero, but keep in mind there has been a small bug in Balder that causes the
distance in the pick ray to be incorrect with perspective cameras.  Once you create your pickRay, you'll need
to test against all mesh data in your scene. You can call the Geometry.Intersects method and pass in your pick ray.
This method will return a double, which is the distance to any face that has been hit.  You can also get the face
that has been hit, along with the UV values on the triangle.  But keep in mind that this distance is slightly off with
perspective cameras.

It might be close enough for your purposes.  Good luck!

Mar 21, 2011 at 9:56 PM

Xersoft : Is it the accuracy problem with regards to the hit-testing for Orthographic cameras that was introduced or is this something thats been around for a while? 

I'll be specializing the RayPicking for the different types of views to remove inaccuracies introduced with the ortho picking. 

Mar 21, 2011 at 10:37 PM

You are correct Adept, I was talking about the small bug created when Ortho was fixed. 

StaticInt:  I have no doubt this will get fixed.  Adept has been very on top of errors since I've started working with this great platform.  But as a quick way to get you up and running you might want to go and grab the old method for Game.ViewPort.GetPickRay and copy it into your code.  The method works for the perspective camera in an older version of Balder.  (see http://balder.codeplex.com/discussions/247009) I think 968f4248ed84 Jan 29 at 6:12 AM  has the correct version for the perspective camera.  I just copied that older method into the code, named it GetPickRayOld, and contined working.  I wish my math background was a bit stronger!  I'd love to help out fixing these sort of things.

Hope this helps StaticInt!


Mar 23, 2011 at 8:35 PM

Just pushed a fix for this to the repo. It is now using one technique for perspective cameras and one for ortho for creating a PickRay - accuracy is now optimal in both scenarios.

Apr 26, 2011 at 6:06 AM

Perfect,  works.

Apr 26, 2011 at 6:07 AM

Perfect,  works.