Page 1 of 1

Ray / Box Intersection

Posted: Tue Feb 02, 2010 11:41 pm
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.

Posted: Wed Feb 03, 2010 1:28 pm
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

Posted: Wed Feb 03, 2010 3:14 pm
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).

Posted: Wed Feb 03, 2010 5:18 pm
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.

Posted: Wed Feb 03, 2010 6:29 pm
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.

Posted: Wed Feb 03, 2010 8:09 pm
by diki
'diploma-mode' is obviously still engaged :P new version up.

Posted: Wed Feb 03, 2010 8:22 pm
by VilleK
Wow, that is impressive! Great work, diki :)

Posted: Wed Feb 03, 2010 10:00 pm
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

Posted: Wed Feb 03, 2010 10:47 pm
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 :)

Stunts clone

Posted: Sat Feb 06, 2010 11:39 am
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!

Posted: Sat Feb 06, 2010 3:18 pm
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

Posted: Thu Mar 11, 2010 10:45 pm
by diki
updated the original post with a new version that is a lot more usable thanks to Kjells suggestions :)

Posted: Thu Mar 11, 2010 11:39 pm
by y offs et
Newbie Fix :

onUpdate / Keypress

set repeatDelay to 0.1 :wink:

Posted: Fri Mar 12, 2010 6:44 pm
by diki
hehe, that property is new to me, indeed :P