Ray / Box Intersection
Moderator: Moderators
Ray / Box Intersection
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.
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 37694 times
-
- ray box intersect v38.zgeproj
- (17.29 KiB) Downloaded 1357 times
Last edited by diki on Thu Mar 11, 2010 10:43 pm, edited 3 times in total.
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
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
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).
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
- Location: Canada
- 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
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
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!
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
- Location: Canada
- 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
Lupo - not sure if it will help, but I looked at this recently; http://www.gamedev.net/reference/articl ... le2729.asp
iterationGAMES.com