## Ray / Box Intersection

Share your ZGE-development tips and techniques here!

Moderator: Moderators

diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:

### Ray / Box Intersection

use space to randomize the boxes.

edit 2010-02-03a: now works for rotated boxes, too.
edit 2010-02-03b: now works for multiple boxes & rays.
edit 2010-03-11: refactored for usability.
Attachments
usecase.gif (8.39 KiB) Viewed 14274 times
ray box intersect v38.zgeproj
Last edited by diki on Thu Mar 11, 2010 10:43 pm, edited 3 times in total.

Kjell
Posts: 1724
Joined: Sat Feb 23, 2008 11:15 pm
Hi diki,

Multiplying the ray ( relative to the box center ) with the inverse rotation matrix of the box should work. But keep in mind that matrix calculations are non-cummutative, so it matters what order you use.

What are you going to be using this for? A broad collision pass for bullets?

I'll have a look at your source tonight.

K

diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:
hey kjell,

thanks for reminding me - of course, for an inverse rotation, the multiplication order had to reversed, too. fixed above & working now :D

yes, collision with bullets was mostly the intention. though for my means, this would already qualify as the 'fine' pass ;) i have no intentions (and no idea, really) of more accurate intersection testing (besides trying to understand your ray/triangle trick).

jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Contact:
Well that look quite promising,. I would have to take some time to figure out how to work these functions,. and see what I can do with them. I am perhaps too easily frustraded with abstract maths,. but when I do need some, to achive some goal, I can sometimes muddle through it. I see the utility of this, however it does look daunting.
iterationGAMES.com

diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:
i'll try to work on making them a bit more usable (for my own comfort, too). but you know how it is when something finally works and wants out ;) ... also: 'release early, release often' is a nice thing to do.

diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:
'diploma-mode' is obviously still engaged :P new version up.

VilleK
Posts: 2063
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:
Wow, that is impressive! Great work, diki

Kjell
Posts: 1724
Joined: Sat Feb 23, 2008 11:15 pm

Good work diki. Some minor suggestions ..

- Check whether a Box has been rotated before calling localizeRay.
- Try to wrap everything in one function. That way you can use local variables that won't have to be initialized.
- Instead of always calling testSlab 3 times ( for all dimensions ) in doesIntersect, test whether the result is 0 each loop, and break ( by using return ) out of the loop when that's the case, or use a while statement instead.
- When a Ray doesn't "move" over one of the axes, you can skip the axis entirely. So for example when only the X axis != 0, skip Y and Z.
- Personally I'd try to refrain from using Arrays as substitutes for passing arguments, and use them for returning values only instead ( since there's no alternative at the moment ).

And finally one "bigger" suggestion Bullets generally have a speed that is lower then infinite, so you'd want to deal with a line-segment instead of a infinite ray that you clip at a constant depth ..

Keep it up ~
K

diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:
thank you! :)

kjell: those are really good suggestions to speed things up & make it more usable in general. i'll see what i can do :)

Lupo
Posts: 71
Joined: Wed Sep 09, 2009 6:21 pm
Location: Montevideo, Uruguay

### Stunts clone

Great Diki!

I can start making this Stunts clone!!!
I already made the track with sections of streched/rotated 3d boxes but i cannot make to work a correct way to implement collission with the track and car wheels...

Thanks!
Close, but not there yet.

jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Contact:
Wow, tihs is getting more intersting,. . I still need to take the time to try some hacking with it,. I will probably have questions then.

Lupo - not sure if it will help, but I looked at this recently; http://www.gamedev.net/reference/articl ... le2729.asp
iterationGAMES.com

diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:
updated the original post with a new version that is a lot more usable thanks to Kjells suggestions :)

y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm