80 DirFraction.X = (1.0f / Direction.X);
81 DirFraction.Y = (1.0f / Direction.Y);
82 DirFraction.Z = (1.0f / Direction.Z);
84 const LVector& LeftBottom = AABB.Min;
85 const LVector& RightTop = AABB.Max;
87 const float t1 = (LeftBottom.X - Origin.X) * DirFraction.X;
88 const float t2 = (RightTop.X - Origin.X) * DirFraction.X;
90 const float t3 = (LeftBottom.Y - Origin.Y) * DirFraction.Y;
91 const float t4 = (RightTop.Y - Origin.Y) * DirFraction.Y;
93 const float t5 = (LeftBottom.Z - Origin.Z) * DirFraction.Z;
94 const float t6 = (RightTop.Z - Origin.Z) * DirFraction.Z;
97 const float tmin = glm::max(
98 glm::max(glm::min(t1, t2), glm::min(t3, t4)),
103 const float tmax = glm::min(
104 glm::min(glm::max(t1, t2), glm::max(t3, t4)),
135 FORCEINLINE
bool IntersectsTriangle(
const glm::vec3& A,
const glm::vec3& B,
const glm::vec3& C,
float& t)
const
137 const glm::vec3 E1 = B - A;
138 const glm::vec3 E2 = C - A;
140 const glm::vec3 N = cross(E1, E2);
141 const float Det = -glm::dot(glm::vec3(Direction.X, Direction.Y, Direction.Z), N);
143 const float InvDet = 1.0f / Det;
145 const glm::vec3 AO = Origin.As<glm::vec3>() - A;
146 const glm::vec3 DAO = glm::cross(AO, Direction.As<glm::vec3>());
147 const float u = glm::dot(E2, DAO) * InvDet;
148 const float v = -glm::dot(E1, DAO) * InvDet;
150 t = glm::dot(AO, N) * InvDet;
152 return ((Det >= 1e-6f)
156 && ((u + v) <= 1.0f));