Filtering results of scene query

Dec 1, 2012 at 12:22 PM
Edited Dec 1, 2012 at 12:22 PM


I'm using the following code to pick Box objects in a scene:


var camera = scene.FindName("Cam");
var pickRay = GraphicsDevice.Viewport.CreatePickRay(e.X, e.Y, camera.View, camera.Projection);

var result = new List();
scene.FindAll(ref pickRay, box => box.Visible, result);

How can I filter the results to get the only the item closest to the camera?


Dec 1, 2012 at 1:24 PM

Take a look at 'IPickable' there you can get if the ray is hitting the target and where in world position.

Dec 2, 2012 at 11:09 PM

If I understand correctly I will need to create my own class class and implement the IPickable members? I was using the Box primitive so I was just checking to see if there was a built in way to handle it. I did try using GetDistanceToCamera() but it didn't seem to pick the object in front as I would expect.

If you have any sample code that would be helpful but it's not that urgent.
Dec 3, 2012 at 1:07 PM

Never mind I worked it out. I just used Intersects on the BoundingBox and it did what I needed.