开发者

Arbitrary ray test using C# and WPF

开发者 https://www.devze.com 2023-01-23 00:41 出处:网络
I want to know if a ray from an arbitrary point will strike a polygon. It would be开发者_如何学运维 useful to know the point in space that intersection occurs and also a reference to that polygon. I\'

I want to know if a ray from an arbitrary point will strike a polygon. It would be开发者_如何学运维 useful to know the point in space that intersection occurs and also a reference to that polygon. I'm using the System.Windows.Media.Media3D library and have done a ray trace test but have yet to crack any of teh information i want out of the HitTestResult object returned by VisualTreeHelper.HitTest.

Am i looking in the wrong place?

Is there a different approach to test for arbitrary intersection?

The Codez:

private void MainViewport_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
    // Retrieve the coordinate of the mouse position.
    Point pt = e.GetPosition((UIElement)sender);

    // Perform the hit test against a given portion of the visual object tree.
    HitTestResult result = VisualTreeHelper.HitTest(MainViewport, pt);

    if (result != null)
    {
        // Perform action on hit visual object.
    }
}


I don't know the System.Windows.Media.Media3D, but:

  1. I guess you should create the ray direction by constructing a vector from the "eye coordinate" to the mouse-coordinate on the view-plane
  2. If the polygon is planar, you could solve for the intersection of the plane and the ray to get the hit-coordinate in that plane, then figure out if that point is within the polygon

A little vague response I know, but I hope it will be helpfull to you anyways.


Can you downcast the HitTestResult to a RayHitTestResult? Does that have the information you need?

0

精彩评论

暂无评论...
验证码 换一张
取 消