I'm pretty new to C++ and DirectX9 and I want to Implement a Third Person Camera. After some reading about Quaternion-based Cameras I decided to try Implementing it. But it really blow my mind, so I ask here what is the easiest way to Implement a TP-Camera?
Here are the things the Camera should do:
Follow coordinates stored in a 3DVector (x, y, z)
Rotate around the Object (Smooth)
Maybe some type of 'spring' = Slowly moving back to the normal Pos behind the Object after Rotating
Apologise for my bad english: I'm german and still in school!
Thanks in Advance!
EDIT:
After some trying I've got it.
The biggest problem I considered was the right extracting of the "direction" Vector from the World-Matrix.
During my research I've found mostly something like this:
D3DXVECTOR3 direction;
direction.x = worldMatrix->_13;
direction.y = worldMatrix->_23;
direction.z = worldMatrix->_33;
D3DXVec3Normalize(&direction, &direction);
That does NOT work for me! Instead I did this:
D3DXVECTOR3 direction;
direction.x = worldMatrix->_13;
// Consider the .y after the .z!
direction.z = worldMatrix->_23;
direction.y = worldMatrix->_33;
D3DXVec3Normalize(&direction, &direction);
For scaling:
// The tenfold of the average distance
D3DXVec3Scale(&direction, &direction, 10.0f);
Setting the Positions:
cameraPos = targetPos - direction;
// For a top-view
cameraPos.y = targetPos.y + 5;
For Rotations you should create a temporary world-Matrix (from the position of the target) and rotate it how you want and extract the direction.
The Smoothing of the Rotation really depends on YOUR game!
This sort of 3rd Person Camera is really easy to make and it does it's job!
Really GREAT thanks to "jheriko" who gave me the right answer!