This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline bool intersect_ray_aabb(const glm::vec3 &origin, const glm::vec3 &dir, | |
const AABB &aabb) { | |
glm::vec3 dir_inv = 1.f / dir; | |
float t1 = (aabb.min().x - origin.x) * dir.x; | |
float t2 = (aabb.max().x - origin.x) * dir.x; | |
float tmin = glm::min(t1, t2); | |
float tmax = glm::max(t1, t2); | |
for (int i = 1; i < 3; ++i) { | |
t1 = (aabb.min()[i] - origin[i]) * dir_inv[i]; | |
t2 = (aabb.max()[i] - origin[i]) * dir_inv[i]; | |
tmin = glm::max(tmin, glm::min(t1, t2)); | |
tmax = glm::min(tmax, glm::max(t1, t2)); | |
} | |
return tmax > glm::max(tmin, 0.f); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment