Hi,
I'm looking for a really efficient ray-box intersection algorithm. The "ray" here is a particle like a bullet, represented by a point and a movement vector. And by "box" I mean an 8 by 8 background tile. I need to know exactly (or close enough) where the particle hits on the edge of the tile. And of course, since it's on the Genesis, it needs to be real fast. Any ideas?
Thanks!
DJCC
Fast ray-box intersection algorithm?
Moderator: BigEvilCorporation
-
- Very interested
- Posts: 710
- Joined: Sat Feb 18, 2012 2:44 am
I don't know exactly what you're trying to do, but wouldn't something like this work:
Whenever you move the bullets you can check if they hit something solid in the background. I.e. something like:
And for all other objects (sprites) that are hittable you can begin by checking if the ray's endpoint and the object are located within the same 8x8 cell, and then whether the endpoint is actually within the object's bounding box (a few IFs).
To find out exactly where the ray hit you could do e.g.:
Whenever you move the bullets you can check if they hit something solid in the background. I.e. something like:
Code: Select all
if (map[FIX2INT(ry) >> 3][FIX2INT(rx) >> 3].type == SOLID)
To find out exactly where the ray hit you could do e.g.:
Code: Select all
if (FIX2INT(rx) > obj.x1)
s = FIX2INT(rx) - obj.x1 // hit from left
else
s = obj.x2 - FIX2INT(rx) // hit from right
hitx = rx - s*dx
// ..and likewise for y
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm