Advertisement

Rotated AABB using quaternion

Started by September 26, 2020 08:17 PM
0 comments, last by ballzak 4 years, 3 months ago

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;
}

This topic is closed to new replies.

Advertisement