1

I have a SphereMesh (inherits from MeshGeneratorBase as part of the Petzold.Media3D.dll) in my WPF 3D Scene. I also have thousands of ScreenSpaceLines3D objects on that sphere. I want to ignore everything in my scene except the SphereMesh and find out the X-Y-Z coordinate of where my mouse ray intersects with the sphere only. Even if there is another object X between the sphere and the mouse, I still want to know where the mouse would hit the sphere, as if object X didn't exist.

I've tried the below code using HitTest, but as I add thousands/millions of other objects in my scene/world, it becomes extremely slow. And the object obstruction issue is another problem I can't resolve.

What do you recommend?

Current code:

Point mousePos = new Point(x, y);
PointHitTestParameters hitParams = new PointHitTestParameters(mousePos);
VisualTreeHelper.HitTest(
    viewPort,null,
    delegate(HitTestResult hr)
    {
        RayMeshGeometry3DHitTestResult rayHit = hr as RayMeshGeometry3DHitTestResult;
    if(rayHit != null)
    {
        // Mouse hits something
        Console.WriteLine("Point: " + rayHit.PointHit);
    }
    return HitTestResultBehavior.Continue;
}, hitParams);

Any help?

Thanks.

Ryan R
  • 167
  • 7
  • If you could get the hit-test ray information (a point and direction vector) wouldn't it be easier just to calculate the intersection yourself? – Govert Jun 03 '12 at 21:58
  • How would I get the point and direction vector? I have already written a method that calculates the intersection of a sphere and a vector... – Ryan R Jun 03 '12 at 22:05
  • Here's one way (though it's a bit sneaky - using Reflection) http://grokys.blogspot.com/2010/08/wpf-3d-translating-2d-point-into-3d.html. – Govert Jun 03 '12 at 23:17
  • And I always recommend the fantastic Helix 3D Toolkit (http://helixtoolkit.codeplex.com) for anyone dealing with WPF 3D. – Govert Jun 03 '12 at 23:19

0 Answers0