What do the ddx and ddy values do in this AABB ray intersect algorithm?
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
(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.
精彩评论