Hi,
Each entity in my game world has an orientation vector, and the quaternians i use for rotating the orientation vector clockwise/anticlockwise work properly.
Each entity is represented as an OBB. When applying those same quaternians to transform the OBB, the centre of mass changes. How do I prevent the centre of mass from changing i.e I'd like the OBB to rotate about the vertical axis.
I'm using MathGeoLib for math, more specifically the following function:
http://clb.demon.fi/MathGeoLib/nightly/docs/OBB_Transform.php
Any help will be greatly appreciated.
rotation of arbitrarily oriented bounding box?
A rotation maps a couple of points onto themselves. These points in space are named the axis of rotation. While there are infinitely many possible axes in 3D, all of them pass through [0 0 0 1]t, because for any rotation matrix R
R * [0 0 0 1]t = [0 0 0 1]t
So if you want a specific point p to be mapped onto itself, you must make it a point of the rotation axis. This means you can perform the rotation in a "temporary" space where p is at [0 0 0 1]t (it can be anywhere on the axis, but [0 0 0 1]t is the simplest one to get). This is done by wrapping the rotation R with the translation T by p like so (here shown using column vectors):
T( p ) * R * T-1( p ) == T( p ) * R * T( -p )
because of
T( p ) * R * T( -p ) * p = T( p ) * R * [0 0 0 1]t = T( p ) * [0 0 0 1]t = p
In your example, p is the center of mass as is given in the space that is valid on the right hand side.
Furthermore, if you want to rotate around a specific axis, you have to define R accordingly to the rules of matrix rotation / quaternion rotation.
I've already calculated a quaternian earlier that represents the anticlockwise rotation of 3.6 degrees around the vertical axis. Could I modify it so that it preserves the centre of mass of the box?
I'm pretty new to rotating things with matrices/quaternians, it looks like working with quaternians would be easier than the transformation matrix.
I've already calculated a quaternian earlier that represents the anticlockwise rotation of 3.6 degrees around the vertical axis. Could I modify it so that it preserves the centre of mass of the box?
A quaternion (to be precise: a unit-quaternion) represents a pure rotation. There is nothing in a quaternion that allows for a linear translation as is required in the given use case (AFAIK). You need to (1) translate so that the center of mass is on the rotation axis, preferably at the origin as shown above, (2) rotate as usual, (3) translate back so that the center of mass is at the same position as before. It is a three step process that can be baked into a single transform matrix.
I'm pretty new to rotating things with matrices/quaternians, it looks like working with quaternians would be easier than the transformation matrix.
Only in specific circumstances, namely when doing interpolation (because of the easier math) or accumulation (because of the higher robustness). However, when it comes to compose transforms then matrices are better. If you look further into the documentation you've already cited, you'll see that OBB::Transform(const Quat &transform) is just a stub for its matrix variant.