What I'm doing
In my engine, I'm trying to implement a camera that will follow a target object, such as a player.
I wanted to avoid just simply using the inverse of the target's transformation, because the camera may end up "jerky", so instead I interpolate between the current and target orientation over time, this way the camera's rotation eases in on the desired rotation:
quat targetQuat = target->getOrientation(); quat currentQuat = getOrientation(); quat slerpQuat = glm::slerp(currentQuat, targetQuat, 0.05f); setOrientation(slerpQuat);
Where my problem begins:
Since I'm just interpolating between quaternions, it is possible that the target may spin faster than the camera can catch up, and may wind up falling behind.
I want to somehow impose a quaternion rotation cap, or somehow determine which of the two is larger so I can min/max 2 quaternions. For example:
quat targetQuat = target->getOrientation(); quat currentQuat = getOrientation(); quat slerpQuat = glm::slerp(currentQuat, targetQuat, 0.05f); quat maximumQuat = targetQuat*quat(0.707, 0, -0.3535, 0); quat desiredQuat = min(slerpQuat, maximumQuat); setOrientation(desiredQuat);
How can I determine which of two quaternions rotates/deviates the furthest? Are there any better alternatives methods? The general idea I had was just to min/max the quat such that it always falls within the bounds I need.
I know that I can calculate a delta quaternion, or rather multiply q0 by inverse q1, but even so I don't know what I would do with it or how it could inform me which of the two is the largest one.