Original Post
Hi, I have working with camera for my game and try to lock it to the char and rotate it around him when he moves. Let me show what I have done so far. I have this Vectors. Vector3 mPos; Vector3 mView; Vector3 mUp; Vector3 mPlayer; the Rotate function is done like this. and Move fuction. How can I lock the camera this to the character using this functions? and also rotate around him when I move the character forwards. I have try do like this. A set camera function. to Set the camera to a point, then I do like this. SetCamera(player.x, player.z); player.x += 0.005f * m_timer.elapsed; player.z += 0.005f * m_timer.elapsed; Rotate_Position(0.05f * m_timer.elapsed); Now it rotates around the camera point not the players point. Im going crasy soon, maybe I need more math to do this.
void CCamera::Rotate_Position(float speed)
{
Vector3 vVector = mPos - mView;
mRotate.z = (float)(mView.z + sin(speed)*vVector.x + cos(speed)*vVector.z);
mRotate.x = (float)(mView.x + cos(speed)*vVector.x - sin(speed)*vVector.z);
}
void CCamera::Move_Camera(float speed)
{
Vector3 vVector = mView - mPos;
mPos.x = mPos.x + vVector.x * speed;
mPos.z = mPos.z + vVector.z * speed;
mView.x = mView.x + vVector.x * speed;
mView.z = mView.z + vVector.z * speed;
}
void CCamera::SetCamera(float xPos, float zPos)
{
mView.x += xPos-mPos.x;
mView.z += zPos-mPos.z;
mPos.x = xPos;
mPos.z = zPos;
}