Hey... would this work?
Hey, I''ve been looking for a way to do fast tests for collision between a ray and an AABB (Axis Aligned Bounding Box), and I think I''ve found something. First you find the center of the bounding cube. Then, you test to see if the x component of the vector is other than zero. If it is, you divide the difference between the x component of the origin of the ray, and the center of the AABB, by the x component of the vector. Else, just skip the x component entirely and move on to the Y, performing the same operations. Then, take the product of the box center y and the origin y, multiply it by the above mentioned quotient do the same for z. So you should have by this point(pun not intended, hehe,)
(box center x - ray origin x,
(box y - ray origin y)*(box center x - ray origin x)/vector x),
(box z - ray origin z)*(box center x - ray origin x)/vector x))
you then (making sure, in this case, that the y component of the vector is not equal to zero,) get,
((box x - ray origin x)*(box center y - ray origin y)/vector y),
box y - ray origin y,
(box z - ray origin z)*(box center y - ray origin y)/vector y))
and (still not forgetting, just as with the y and x components, that the z component of the vector cannot equal zero or this segment should be skipped.)
((box x - ray origin x)*(box center z - ray origin z)/vector z),
(box y - ray origin y*(box center z - ray origin z)/vector z),
box z - ray origin z)
if any of these points are in the box in question, then you have collision. Does this make sense? I''ve tried it on paper but not in my engine yet. Hope to hear many constructive comments Klaus
i dont know this stuff at all, but i say give it a try and find out, thats how i do these things
What do you mean by "bounding cube?" And you mention "the x component of the vector" a lot, I assume you''re referring to the x component of the centre of the bounding cube but it''s unclear.
If it works, use it.
If it works, use it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement