What is the best way of writing box-box ray collision detection in three.js?
The objects in this experiment are moving around randomly: http://deeplogic.info/project/webGL/
What is the best way of writing a box-box ray collision detection for t开发者_如何学Pythonhis using the three.js library?
If you're using raytracing:
For both boxes, check it's 12 edges against the other box's 6 faces. If none of them intersect, you can be sure that there is no collision.
To check one box's edge against another box's face: Define an infinite ray that goes directly along the edge. Define an infinite plane that lies on the other box's face. Use ray-plane intersection to find the intersection point of the infinite plane and the infinite ray. Check that the intersection point: a) lies on the edge of your box, and b) lies within the other box's face. If so, you have an intersection!
As for what to do with that intersection once you know it's happened, that's a whole new topic.
精彩评论