# Problem with arcball

I making graphics viewer, and I want to use "arcball" to manipulate object. I using OpenGL + CML ( for math ). My arcball don't want work, it is skewing not rotating :/ And I don't know why, I use formulas from http://www.csi.ucd.ie/staff/hcarr/home/teaching/comp4004/slides/05_arcball.pdf .

My code:
cml::vector3f u,v;

u[0] = 2.0 - prevX/(0.5f * width());
u[1] = 2.0 - prevY/(0.5f * height());
u[2] = sqrt(u[0]*u[0] + u[1]*u[1]);

v[0] = 2.0 - currentX/(0.5f * width());
v[1] = 2.0 - currentY/(0.5f * height());
v[2] = sqrt(v[0]*v[0] * v[1]*v[1]);

cml::quaternionf qu,qv,q;

qu[0] = 0;
qu[1] = u[0];
qu[2] = u[1];
qu[3] = u[2];

qv[0] = 0;
qv[1] = v[0];
qv[2] = v[1];
qv[3] = v[2];

q = qv * ( qu.inverse());

cml::matrix44f matrix;

matrix.identity();

cml::matrix_rotation_quaternion(matrix,q);

//Drawing


The reason it is not rotating on the sphere properly is because you are not assuming that there is a fixed yaw axis (which is usually Y). So what ends up happening that with each frame the new yaw axis skews the next frame's calculation a little bit. Over a few frames the camera goes through an unintended motion, which I believe is what is happening in your case.
For proper/predictable arcball rotation, such as the one seen in Autodesk Maya/Max, you will have to assume that your up vector is fixed for the calculation of the direction and right vectors (in a 3x3 rotation matrix each column represents the 3 orthonormal vectors, and is entirely dependant on how you have setup your co-ordinate system. Usually in OpenGL it is Right, Up, Direction) and then calculate a new up vector for the camera to work properly. Every frame, you assume your up vector is unchanging and stays fixed at (for example) [0,1,0].