使用 C# 和 WPF 进行任意光线测试
我想知道来自任意点的射线是否会击中多边形。了解空间中发生相交的点以及对该多边形的引用将很有用。我正在使用 System.Windows.Media.Media3D 库,并已完成光线跟踪测试,但尚未从 VisualTreeHelper.HitTest 返回的 HitTestResult 对象中破解我想要的任何信息。
我是不是找错地方了?
是否有不同的方法来测试任意交叉点?
代码:
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 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.
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道 System.Windows.Media.Media3D,但是:
我知道有点模糊的反应,但我希望它无论如何对你有帮助。
I don't know the System.Windows.Media.Media3D, but:
A little vague response I know, but I hope it will be helpfull to you anyways.
您可以将
HitTestResult
向下转换为RayHitTestResult
?其中有您需要的信息吗?Can you downcast the
HitTestResult
to aRayHitTestResult
? Does that have the information you need?