Created
July 31, 2011 00:57
-
-
Save iamgreaser/1116213 to your computer and use it in GitHub Desktop.
raycastery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
note: | |
dx/y/z = distance to grid boundary in coordinate direction | |
cx/y/z = current cell | |
vx/y/z = ray velocities (absolute value of each coordinate) | |
gx/y/z = direction each ray is going | |
tx/y/z = time it takes to hit a boundary, or something like that | |
tc = time covered when firing a ray (initialised to 0) | |
cell_size = size of a cell | |
dx = vx*t | |
dy = vy*t | |
dz = vz*t | |
tx = dx/vx | |
ty = dy/vy | |
tz = dz/vz | |
compare like so: | |
if dx*vy < dy*vx then tx < ty | |
if dx*vz < dz*vx then tx < tz | |
if dy*vz < dz*vy then ty < tz | |
(afaik multiply tends to be more accurate than divide) | |
then work out what the smallest of them is. | |
this would be the case where tx is 0 OR tx is the smallest: | |
cx += gx | |
dy -= (vy*dx)/vx | |
dz -= (vz*dx)/vx | |
tc += (cell_size*dx)/vx | |
dx = cell_size | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment