@@ -70,13 +70,42 @@ bool AABB::intersects(AABB &other)
7070
7171AABB::SIDE AABB::intersectsRay (GLFix x, GLFix y, GLFix z, GLFix dx, GLFix dy, GLFix dz, GLFix &dist)
7272{
73- // TODO: Div / 0!
74- GLFix t_min_x = (low_x - x) / dx;
75- GLFix t_max_x = (high_x - x) / dx;
76- GLFix t_min_y = (low_y - y) / dy;
77- GLFix t_max_y = (high_y - y) / dy;
78- GLFix t_min_z = (low_z - z) / dz;
79- GLFix t_max_z = (high_z - z) / dz;
73+ GLFix t_min_x = 0 , t_max_x = GLFix::maxValue (),
74+ t_min_y = 0 , t_max_y = GLFix::maxValue (),
75+ t_min_z = 0 , t_max_z = GLFix::maxValue ();
76+
77+ if (dx == GLFix (0 ))
78+ {
79+ if (x < low_x || x > high_x)
80+ return NONE;
81+ }
82+ else
83+ {
84+ t_min_x = (low_x - x) / dx;
85+ t_max_x = (high_x - x) / dx;
86+ }
87+
88+ if (dy == GLFix (0 ))
89+ {
90+ if (y < low_y || y > high_y)
91+ return NONE;
92+ }
93+ else
94+ {
95+ t_min_y = (low_y - y) / dy;
96+ t_max_y = (high_y - y) / dy;
97+ }
98+
99+ if (dz == GLFix (0 ))
100+ {
101+ if (z < low_z || z > high_z)
102+ return NONE;
103+ }
104+ else
105+ {
106+ t_min_z = (low_z - z) / dz;
107+ t_max_z = (high_z - z) / dz;
108+ }
80109
81110 GLFix min = std::max (std::max (std::min (t_min_x, t_max_x), std::min (t_min_y, t_max_y)), std::min (t_min_z, t_max_z));
82111 GLFix max = std::min (std::min (std::max (t_min_x, t_max_x), std::max (t_min_y, t_max_y)), std::max (t_min_z, t_max_z));
0 commit comments