# 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 = 2.0 - prevX/(0.5f * width());
u = 2.0 - prevY/(0.5f * height());
u = sqrt(u*u + u*u);

v = 2.0 - currentX/(0.5f * width());
v = 2.0 - currentY/(0.5f * height());
v = sqrt(v*v * v*v);

cml::quaternionf qu,qv,q;

qu = 0;
qu = u;
qu = u;
qu = u;

qv = 0;
qv = v;
qv = v;
qv = v;

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].