# rotating aabb's

My aabb works but i couldn’t find much info about what happens if your object was to be rotated.

I’m assuming a rotation transformation.

would you have to find min max again by applying the transformation to the objects vertices in object space then looking for min and max again.

or Should I just apply the transformation directly to min and max.

I’m trying to visual represent the bounding box at least when I rotate the object.

You need to follow an algorithm posted in Graphics Gems I, I think, here’s some code for cr-aabb:

/////////////////////////////////////////////////////////////////////////////
template <class M, class U1, class U2>
inline void tr_cr_aabb_aabba(M const& matrix, AABB<U1, U2> const& aabba,
AABB<U1, U2>& aabbb)
{
BOOST_STATIC_ASSERT(M::Rows == M::Cols);

for (unsigned char i(0); i != M::Rows - 1; ++i)
{
aabbb.a(i) = matrix(i, M::Cols - 1);
aabbb.b(i) = 0;

``````for (unsigned char j(0); j != M::Cols - 1; ++j)
{
aabbb.a(i) += matrix(i, j) * aabba.a(j);
aabbb.b(i) += std::abs(matrix(i, j)) * aabba.b(j);
}
``````

}
}

The idea behind the algorithm is, that all AABB’s vertices can be formed by choosing components from min and max, i.e. 2^3 possibilies = 8 points. For radius you choose the component producing the greatest radius, you have a + or - component to choose from and you choose the one producing the greatest aabb radius (which is equivalent to std::abs()-ing all matrix components before multiplying with the radius vector b). The min-max transformation is similar, but usually runs more slowly than the cr transformation.

sorry internet went weird on me. anyway thanks for the info. I eventually did get it work correctly. I was doing it by using the get the corners from min-max. It’s good to know this way and will use it when I need too but for now the min-max is good.

thanks

Here’s the min-max for you, but check the Graphics Gems I, just to be sure:

//////////////////////////////////////////////////////////////////////////////
template <class M, class U1, class U2>
inline void tr_mm_aabb_aabba(M const& matrix, AABB<U1, U2> const& aabba,
AABB<U1, U2>& aabbb)
{
for (unsigned char i(0); i != M::Rows - 1; ++i)
{
aabbb.a(i) = aabbb.b(i) = matrix(i, 3);

``````for (unsigned char j(0); j != M::Cols - 1; ++j)
{
typename U1::value_type e(matrix(i, j) * aabba.a(j));
typename U2::value_type f(matrix(i, j) * aabba.b(j));

if (e &lt; f)
{
aabbb.a(i) += e;
aabbb.b(i) += f;
}
else
{
aabbb.a(i) += f;
aabbb.b(i) += e;
}
}
``````

}
}