Original Post
Hi, I made a function, that makes a camera to look at a certain point. For rotation representation I am using quaternions. It works fine, but, when y coordinate of a view vector of a camera (vView.y) is positive, my camera flips upside down. Of course this happens only when I make camera look to a new direction. For example new target is (0.0f, 2.0f, 0.0f), and when camera (position) goes under a plane y = 2.0f, camera flips upside down. What my problem could be? Thank you in advance.
void CCamera::LookAt( vec3 pTarget )
{
vTarget = pTarget;
vTarget.x *= -1.0f; //I don't know, what do I need it for, but without it x coordinate flips.
vView = vTarget - vPos;
vec3 vViewProjected = vView;
vViewProjected.y = 0.0f;
vRight = vView * vViewProjected;
vUp = vRight * vView;
vView.normalize();
vRight.normalize();
vUp.normalize();
camMatrix.values[0] = vRight.x;
camMatrix.values[4] = vRight.y;
camMatrix.values[8] = vRight.z;
camMatrix.values[1] = vUp.x;
camMatrix.values[5] = vUp.y;
camMatrix.values[9] = vUp.z;
camMatrix.values[2] = -vView.x; //Why is this reversed(x, y and z)? I don't understand, what do I need it for.
camMatrix.values[6] = -vView.y;
camMatrix.values[10] = -vView.z;
qCurrent = CreateFromMatrix(camMatrix);
}