Original Post
Hi, I have been trying to get my camera work a long time now, And I have some questions about it. The camera will have to follow the character and have the ability to rotate around the character. I have get the rotation around a point to work, but the problem is how to add the pos vector with the rotate vector if you know what I mean. Like this: first i lock the cameraPos to the character pos like this. SetCamera(m_player.x + 20.0f, m_player.z + 20.0f); Now I have the character in fron of the camera. But the problem is my rotate function mPos is the camera pos, and when I lock the camera to the character the mPos cant be change, and I need to change to get the ability to rotate around it.. here is the code to rotate: so my question is how can I add the rotate pos with the mPos? Hope anyone can help me with this, Im not good at explain things so I hope you understand what I mean. The camera will be created for an single-player rpg game. thanks.
void CCamera::Rotate_Position(float rot, float x, float y, float z)
{
Vector3 vNewPosition;
Vector3 vPos = mPos - mView;
float cosTheta = (float)cos(rot);
float sinTheta = (float)sin(rot);
vNewPosition.x = (cosTheta + (1 - cosTheta) * x * x) * vPos.x;
vNewPosition.x += ((1 - cosTheta) * x * y - z * sinTheta) * vPos.y;
vNewPosition.x += ((1 - cosTheta) * x * z + y * sinTheta) * vPos.z;
vNewPosition.y = ((1 - cosTheta) * x * y + z * sinTheta) * vPos.x;
vNewPosition.y += (cosTheta + (1 - cosTheta) * y * y) * vPos.y;
vNewPosition.y += ((1 - cosTheta) * y * z - x * sinTheta) * vPos.z;
vNewPosition.z = ((1 - cosTheta) * x * z - y * sinTheta) * vPos.x;
vNewPosition.z += ((1 - cosTheta) * y * z + x * sinTheta) * vPos.y;
vNewPosition.z += (cosTheta + (1 - cosTheta) * z * z) * vPos.z;
mPos.x = mView.x + vNewPosition.x;
mPos.z = mView.z + vNewPosition.z;
}