Linetest Oriented Bounding Box
Rays and Line segments are similar. The slab test for raycasting and the slap test to see if a Line and OBB intersect are almost the same. The only thing a linetest does different from a Raycast is it normalizes the result of the t value to the length of the line segment.
Because the two tests are so similar, we are going to build the linetest using the existing Raycast against the OBB function. Comparing the squared value of t against the squared length of the line segment is more efficient than normalizing t to the length of the Line.
Getting ready
We are going to implement a function to check if a Line segment and an OBB intersect. This function will return a Boolean result. The linetest function is going to build a ray out of the line and use the existing Raycast against the OBB function.
How to do it…
Follow these steps to implement line testing against an OBB:
- Declare the
Linetest
function inGeometry3D.h
:bool Linetest(const OBB& obb, const Line...