Hello guys, I am moving my camera along surface of a sphere. Camera is always looking towards center of the sphere:
forward = center - pointOnSphere
I am having problem with right and up axes of camera flipping when phi is in range [k * PI, k+1 * PI], k element {1, 3, 5, ..., inf} as it can be seen in geogebra example.
I am trying to solve flipping issue by multiplying "right" and "up" vectors of camera by "-1" in case m_phi is in that range in which flipping occurs. This did not resolve the issue. Can anyone spot what I am missing? I've also recorded how it looks in my application (2nd video).
This is the code:
void Camera::calculatePointOnSphere(const double& startingX, const double& startingY, const double& currentX, const double& currentY)
{
mXOffset += (currentX - startingX);
mYOffset += currentY - startingY;
m_theta = mXOffset / mWidth * glm::radians(360.0f) * mSensitivity;
m_phi = mYOffset / mHeight * glm::radians(180.0f) * mSensitivity;
mPointOnSphere.x = mSphereRadius * glm::cos(m_theta) * glm::sin(m_phi);
mPointOnSphere.y = mSphereRadius * glm::cos(m_phi);
mPointOnSphere.z = mSphereRadius * glm::sin(m_theta) * glm::sin(m_phi);
}
void Camera::updateCameraAxis()
{
float k = std::abs(m_phi / glm::pi<float>());
float direction = ((int)std::floor(k) % 2 == 1 && (int)std::ceil(k) % 2 == 0) ? -1 : 1;
mForward = glm::normalize(-mPointOnSphere);
mRight = glm::normalize(glm::cross(mForward, mWorldUp)) * direction;
mUp = glm::normalize(glm::cross(mRight, mForward)); // doesn't work even when multiplying with -1
