Skip to main content
GameDev.net gamedev.net
🔒 Locked

Quick Question on this code

Started by Pyroclastic Flow Apr 20, 2010 at 7:58 AM 1 replies 650+ views
Original Post
Pyroclastic Flow
Pyroclastic Flow
I'm trying to figure out the use of this AABB intersection algorithm. But can't seem to figure out what the variables txMin, txMax ... and ddx, ddy are doing. Some advice would be highly approciated.

Local txmin#,txmax#,tymin#,tymax#

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

End Function


This code was used from here: http://www.blitzbasic.com/codearcs/codearcs.php?code=1029 but there is not commenting at all and the variable names lack what they do. Thanks in advance guys!
Zakwayda
Zakwayda
It's a little hard to read, but it looks like a slab-based ray-AABB intersection test (the 'min' and 'max' variables are parametric values corresponding to the points at which the ray enters and leaves the three 'slabs' - one for each dimension - that make up the box).

This test has been discussed frequently here in the past, so if you search the archives for (e.g.) 'ray aabb intersection', you'll probably be able to find some discussion of the algorithm and/or other implementations that you can check this code against.
Pyroclastic Flow
Pyroclastic Flow
Quote:
Original post by jyk
It's a little hard to read, but it looks like a slab-based ray-AABB intersection test (the 'min' and 'max' variables are parametric values corresponding to the points at which the ray enters and leaves the three 'slabs' - one for each dimension - that make up the box).

This test has been discussed frequently here in the past, so if you search the archives for (e.g.) 'ray aabb intersection', you'll probably be able to find some discussion of the algorithm and/or other implementations that you can check this code against.


Thanks jyk!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.