-
Book Overview & Buying
-
Table Of Contents
Game Physics Cookbook
By :
We can extend the same slab method used for raycasting against an AABB to also work with an OBB. The key difference is how we find the values of
and
.
We are going to implement a function that finds the entry and exit points of a Raycast against an OBB. This function will only return the entry point. The function returns a scalar value t. This scalar value is the time along the ray at which the intersection happened. If the intersection is invalid, a negative number is returned.
Follow these steps to implement raycasting against an OBB:
Declare the Raycast function in Geometry3D.h:
float Raycast(const OBB& obb, const Ray& ray);
Start implementing the Raycast function in Geometry3D.cpp by declaring a few local variables to keep the code readable. We want to store the half extents of the box as a linear array, and each axis of the OBBs rotation frame as a vector:
float Raycast(const OBB& obb, const Ray& ray) {
const float...