Sign up ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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 .

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;




share|improve this question

1 Answer 1

up vote 0 down vote accepted

I will assume you are manipulating the camera, but the explanation applies to objects as well.

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

The above poses a problem when looking straight down or straight up, in which case your assumed Up is now parallel with your Director and will make it impossible for you to calculate the orthonormal vectors properly. That is a special case and you will have to get around it. You can restrict the rotation of the camera beyond that point, or you can skip that particular rotation.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.