I have a 3rd person camera that doesn't look directly at the player but somewhere in front of him.
When the user enter shooting mode, I want the camera to turn around the player to face the target.
In the image above. "O" is the player (Origin), "L" is the lookat, "C" is the camera position and "T" is the target. I want to rotate the lookat line C->L so that it passes by T (C'->L'->T') around the Origin ("O").
Basically I need to find the angle alpha that I put in red in the picture.
I store my camera position in a structure like such :
struct CameraTarget {
Quaternion absoluteRotation;
Vec3 absolutePosition;
Vec3 cameraOffset;
Vec3 lookatOffset;
float FOV;
}
So if I could find the angle I'm looking for I could do something like :
cam->absoluteRotation = cam->absoluteRotation * alpha;
To get the player to always look at the target.
If the lookat was passing by the Origin I could simply do
Vec3 origDir = cam->lookAtOffset - cam->absolutePosition;
origDir.normalize();
Vec3 newDir = cam->target - cam->absolutePosition;
newDir.normalize();
Quaternion q(origDir, newDir); // from->to
cam->absoluteRotation = cam->absoluteRotation * q;
However in the diagram above this doesn't quite work since the rotation is offset from the Origin.