Ray / Box Intersection

Share your ZGE-development tips and techniques here!

Moderator: Moderators

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

Ray / Box Intersection

Post by diki »

written pretty straightforward after this article, using kjells matrix library.

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
usecase.gif (8.39 KiB) Viewed 32812 times
ray box intersect v38.zgeproj
(17.29 KiB) Downloaded 909 times
Last edited by diki on Thu Mar 11, 2010 10:43 pm, edited 3 times in total.
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

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
User avatar
diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:

Post by diki »

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).
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

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
User avatar
diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:

Post by diki »

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.
User avatar
diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:

Post by diki »

'diploma-mode' is obviously still engaged :P new version up.
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

Wow, that is impressive! Great work, diki :)
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

:)

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 :roll: 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
User avatar
diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:

Post by diki »

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 :)
User avatar
Lupo
Posts: 76
Joined: Wed Sep 09, 2009 6:21 pm
Location: Montevideo, Uruguay

Stunts clone

Post by Lupo »

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.
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

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
User avatar
diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:

Post by diki »

updated the original post with a new version that is a lot more usable thanks to Kjells suggestions :)
User avatar
y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm
Location: BC, Canada

Post by y offs et »

Newbie Fix :

onUpdate / Keypress

set repeatDelay to 0.1 :wink:
"great expectations"
User avatar
diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:

Post by diki »

hehe, that property is new to me, indeed :P
Post Reply