DirectX11 [桌面| UWP]在透视3D内部进行HIT测试 [英] DirectX11 [Desktop|UWP] HIT-Test inside Perspective 3D

查看:77
本文介绍了DirectX11 [桌面| UWP]在透视3D内部进行HIT测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Direct X应用程序,我需要进行命中测试。在我的应用程序中,它就像总是2相机。第一个叫做Ortho2D,第二个叫做Perspective3D。


Ortho2D(锁定,无Z缓冲区)



  • 眼睛(0,0,10,0)
  • At(0,0,0,0)
  • 向上(0,1,0,0)

Perspective3D (免费)



  • 眼睛(0,300,1000,0)
  • 在(0,0,0,0)
  • 向上(0,1,0,0)

当前HitTest在Ortho2D中工作得很好,但是我遇到了一些问题关于Perspective3D ......我确信这是关于FOVy,nearClipping,FarClipping和纵横比。但之前,有HitTest函数的历史。


  1. 我开始用三角形区域测试我的生命值来创建我的函数(

    https: //math.stackexchange.com/questions/4322/check-whether-a-point-is-within-a-3d-triangle
    )。起初,它似乎只在Ortho2D中运行良好...但是,等一下,这个计算只有在点击方向三角形时才有效。
  2. 然后我决定只用基本平面投影得到z。好吧,它解决了Ortho2D故障,但它对于Perspective3D来说是不精确的。
  3. 好的,现在我已经解决投影与摄像机对齐了。它在Ortho2D中运行良好,但对于Perspective3D,我仍然有偏移精度

我在Mathematica中传输的基本计算。

(*变量*)
P1 = {-150,0,-150}
P2 = {150,0,-150}
P3 = {150,0,150}
HP = {122,36,0}
Cam = {0,300,1000}
CamAt = {0,0,0}
CamUp = {0,1,0}
FOVy = 70
NearClipping = 0.1
FarClipping = 2000
宽度= 1920
高度= 1080


(*计算*)
U = P2 - P1;
V = P3 - P1;
UVNorm =交叉[U,V]

Dir = CamAt - Cam
W0 = HP - P1
a = -Dot [UVNorm,W0]
b = Dot [UVNorm,Dir]
r = a / b

HP2 = HP + r * Dir

(*应用带三角区域的HitPoint2 *)

通过此计算,HitPoint(122,36,0)的结果为HitPoint2(122,0,-120)。但实际上,我已经确定了三角形的第二个点,并且HitPoint2必须最接近(150,0,-150)。屏幕上第三个三角点的坐标是(160,-42)


现在,如何计算由视锥体视图创建的推导?


我是否必须在投影之前或投影期间或之后申请?


我是否可以申请HitPoint或我必须绝对适用于每个三角形 点?



谢谢。


解决方案


感谢您在此处发帖。


>>现在,如何计算由视锥体视图创建的派生?


我必须在投影之前或投影期间或之后申请吗?


我是否可以在HitPoint上申请,或者我必须绝对适用于每个三角形 点?


请提供有关您的申请的更多信息。它的类型是什么?桌面或UWP?


如果是UWP应用程序,请发布在
UWP
论坛获得更好的支持。或者这里有一个示例可能对您有帮助。


https://code.msdn.microsoft.com/windowsapps/Touch-Hit-Testing-sample-5e35c690


如果是桌面应用程序,您可以关注下面的这个文档可以获得有关Direct 3D中视口的更多信息。


https://msdn.microsoft.com/en-us/library/windows/desktop/bb206341%28v=vs.85%29.aspx ?f = 255& MSPPError = -2147217396


希望这可以帮到你。


最好的问候,


Baron Bi





I developing a Direct X application and I need to made a Hit Test. Inside my application, it's like have always 2 Camera. The first one was called Ortho2D and the second Called Perspective3D.

Ortho2D (Locked, no Z-Buffer)

  • Eye (0, 0, 10, 0)
  • At (0, 0, 0, 0)
  • Up (0, 1, 0, 0)

Perspective3D (Free)

  • Eye (0, 300, 1000, 0)
  • At (0, 0, 0, 0)
  • Up (0, 1, 0, 0)

The Current HitTest work pretty well in Ortho2D, but I get some problem about Perspective3D... I'm sure it's about FOVy, nearClipping, FarClipping and aspect ratio. But before, There is the history of HitTest function.

  1. I begin to create my function by testing my hit point with the area of the triangle ( https://math.stackexchange.com/questions/4322/check-whether-a-point-is-within-a-3d-triangle) . At first, it's seem working well only in Ortho2D... but, wait a minute, this calculation was only valid if hit point respect triangle.
  2. Then I decided to getting only z with a basic planar projection. OK, it's resolve Ortho2D glitch, but it's non-precise for Perspective3D.
  3. OK, Now that I've resolve projection to align with camera. It's really work well in Ortho2D, but for the Perspective3D I still have offset precision

There is the basic calculation that I've transfer inside Mathematica.

(* Variables *)
P1 = {-150, 0, -150}
P2 = {150, 0, -150}
P3 = {150, 0, 150}
HP = {122,36,0}
Cam = {0, 300, 1000}
CamAt = {0, 0, 0}
CamUp = {0, 1, 0}
FOVy = 70
NearClipping = 0.1
FarClipping = 2000
Width = 1920
Height = 1080

(* Calculation *)
U = P2 - P1;
V = P3 - P1;
UVNorm = Cross[U, V]

Dir = CamAt - Cam
W0 = HP - P1
a = -Dot[UVNorm, W0]
b = Dot[UVNorm, Dir]
r = a/b

HP2 = HP + r* Dir

(* Apply HitPoint2 with Triangle Area *)

With this calculation the HitPoint(122, 36, 0) result to HitPoint2(122, 0, -120). But in reality, I have target the second point of the triangle and the HitPoint2 must be nearest (150, 0, -150). The Coord of Third Triangle Point on Screen was (160, -42)

Now, how calculate the derivation create by the frustum view?

Does I must apply before projection on HitPoint or during the projection or after?

Does I can apply on HitPoint or I must absolutely apply on every triangle  point?

Thanks.

解决方案

Hi,

thanks for posting here.

>>Now, how calculate the derivation create by the frustum view?

Does I must apply before projection on HitPoint or during the projection or after?

Does I can apply on HitPoint or I must absolutely apply on every triangle  point?

Please provide more information about your application. What's the type of it? Desktop or UWP?

If it's an UWP application, please post on UWP forum for better support. Or here is a sample may could be help of you.

https://code.msdn.microsoft.com/windowsapps/Touch-Hit-Testing-sample-5e35c690

If it's a desktop application, you could follow this document below to get more information about viewports in Direct 3D.

https://msdn.microsoft.com/en-us/library/windows/desktop/bb206341%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

Hope this could be help of you.

Best Regards,

Baron Bi


这篇关于DirectX11 [桌面| UWP]在透视3D内部进行HIT测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆