How to create a (center & extent/radius) AABB of an AABB rotated a quaternion?
I'm currently using the code below, from the Real-Time Collision Detection book, which seems to work correctly but use a 3x3 matrix. Is there a way to avoid the matrix conversion and rotate the AABB directly using the glm::quat
?
aabb rotate (const aabb& a, const glm::quat& rotation) {
const auto m = glm::mat3_cast(rotation);
aabb b{};
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
b.center[i] += m[j][i] * a.center[j];
b.radius[i] += std::abs(m[j][i]) * a.radius[j];
}
}
return b;
}