I have a perfectly working fine Arcball implementation. Usually in opengl the standard camera is facing -Z, meaning XY plane is parallel to the viewing plane.
glm::vec3 Arcball::_plane2sphere(glm::vec2 &v)
{
glm::vec2 f = v;
glm::vec3 r;
double lenSquared;
double len;
f /= _radius;
lenSquared = f.x * f.x + f.y * f.y;
len = sqrt(lenSquared);
if (lenSquared > 1.0)
{
r = glm::vec3(f.x / len,f.y / len, 0.0f );
}
else
{
double fz = sqrt(1 - lenSquared);
r = glm::vec3(f.x, f.y, fz);
}
return r;
}
Now if I change my camera to face -Y, meaning XZ is parallel to the viewing plane, the same arcball implementation doesnt hold good. I had to change my arcball implementation as follows. The 'Y's taking place of 'Z's and vice versa.
glm::vec3 Arcball::_plane2sphere(glm::vec2 &v)
{
glm::vec2 f = v;
glm::vec3 r;
double lenSquared;
double len;
f /= _radius;
lenSquared = f.x * f.x + f.y * f.y;
len = sqrt(lenSquared);
if (lenSquared > 1.0)
{
r = glm::vec3(f.x / len, 0.0f, f.y / len);
}
else
{
double fz = sqrt(1 - lenSquared);
r = glm::vec3(f.x, fz, f.y);
}
return r;
}
While this does make sense to me, I was wondering what if I had a very arbitrary camera. When I have an arbitrary camera, the rotations to my object are not intuitive.
Any help is appreciated! Thanks!