在此 AABB 射线相交算法中,ddx 和 ddy 值有何作用?
有谁知道 AABB 射线相交算法中 ddx 和 ddy 值的作用是什么?摘自以下网站 http://www.blitzbasic.com/codearcs/codearcs .php?code=1029(如下所示)。
Local txmin#,txmax#,tymin#,tymax#
// rox, rdx are the ray origin on the x axis, and ray delta on the x axis ... y-axis is roy and rdy
Local ddx# =1.0/(rox-rdx)
Local ddy# =1.0/(roy-rdy)
If ddx >= 0
txmin = (bminx - rox) * ddx
txmax = (bmaxx - rox) * ddx
Else
txmin = (bmaxx - rox) * ddx
txmax = (bminx - rox) * ddx
EndIf
If ddy >= 0
tymin = (bminy - roy) * ddy
tymax = (bmaxy - roy) * ddy
Else
tymin = (bmaxy - roy) * ddy
tymax = (bminy - roy) * ddy
EndIf
If ( (txmin > tymax) Or (tymin > txmax) ) Return 0
If (tymin > txmin) txmin = tymin
If (tymax < txmax) txmax = tymax
Local tzmin#,tzmax#
Local ddz# =1.0/(roz-rdz)
If ddz >= 0
tzmin = (bminz - roz) * ddz
tzmax = (bmaxz - roz) * ddz
Else
tzmin = (bmaxz - roz) * ddz
tzmax = (bminz - roz) * ddz
EndIf
If (txmin > tzmax) Or (tzmin > txmax) Return 0
Return 1
Does anyone know what the ddx and ddy values do in the AABB ray intersect algorithm? Taken from the following site http://www.blitzbasic.com/codearcs/codearcs.php?code=1029 (show below).
Local txmin#,txmax#,tymin#,tymax#
// rox, rdx are the ray origin on the x axis, and ray delta on the x axis ... y-axis is roy and rdy
Local ddx# =1.0/(rox-rdx)
Local ddy# =1.0/(roy-rdy)
If ddx >= 0
txmin = (bminx - rox) * ddx
txmax = (bmaxx - rox) * ddx
Else
txmin = (bmaxx - rox) * ddx
txmax = (bminx - rox) * ddx
EndIf
If ddy >= 0
tymin = (bminy - roy) * ddy
tymax = (bmaxy - roy) * ddy
Else
tymin = (bmaxy - roy) * ddy
tymax = (bminy - roy) * ddy
EndIf
If ( (txmin > tymax) Or (tymin > txmax) ) Return 0
If (tymin > txmin) txmin = tymin
If (tymax < txmax) txmax = tymax
Local tzmin#,tzmax#
Local ddz# =1.0/(roz-rdz)
If ddz >= 0
tzmin = (bminz - roz) * ddz
tzmax = (bmaxz - roz) * ddz
Else
tzmin = (bmaxz - roz) * ddz
tzmax = (bminz - roz) * ddz
EndIf
If (txmin > tzmax) Or (tzmin > txmax) Return 0
Return 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(rox-rdx, roy-rdy) 是从射线的目标点到原点的向量。 ddx 和 ddy 是这两个坐标的倒数。
反转被用作预计算,以便仅需要使用乘法(通过这些反转)而不是函数其余部分中的除法。计算机计算乘法的速度比计算除法的速度快。
(rox-rdx, roy-rdy) is the vector from the destination point to the origin point of the ray. ddx and ddy are the inverse of those 2 coordinates.
The inversion was used as a precomputation in order to only have to use a multiplication (by those inverses) instead of a division in the rest of the function. Computers compute multiplications faster than divisions.