# Arcball 3D camera

I have checked multiple threads before posting, but i havent been able to figure this one out.

Ok so i have been following this tutorial, but im not using glm, ive been implementing everything up until now, like lookat etc. http://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Arcball

So i can rotate with the click and drag of the mouse, but when i rotate 90º degrees around Y and then move the mouse upwards or donwwards, it rotates on the wrong axis, this problem is demonstrated on this part of the tutorial

An extra trick is converting the rotation axis from camera coordinates to object coordinates. It's useful when the camera and object are placed differently. For instace, if you rotate the object by 90° on the Y axis ("turn its head" to the right), then perform a vertical move with your mouse, you make a rotation on the camera X axis, but it should become a rotation on the Z axis (plane barrel roll) for the object. By converting the axis in object coordinates, the rotation will respect that the user work in camera coordinates (WYSIWYG). To transform from camera to object coordinates, we take the inverse of the MV matrix (from the MVP matrix triplet).

What i have to do acording to the tutorial is convert my axis_in_camera_coordinates to object coordinates, and the rotation is done well, but im confused on what matrix i use to do just that. The tutorial talks about converting the axis from camera to object coordinates by using the inverse of the MV. Then it shows these 3 lines of code witch i havent been able to understand.

glm::mat3 camera2object = glm::inverse(glm::mat3(transforms[MODE_CAMERA]) *
glm::mat3(mesh.object2world));
glm::vec3 axis_in_object_coord = camera2object * axis_in_camera_coord;


So what do i aply to my calculated axis?, the inverse of what, i supose the inverse of the model view? So my question is how do you transform camera axis to object axis. Do i apply the inverse of the lookat matrix? My code:

if (cur_mx != last_mx || cur_my != last_my) {
va = get_arcball_vector(last_mx, last_my);
vb = get_arcball_vector( cur_mx,  cur_my);
angle = acos(min(1.0f, dotProduct(va, vb)))*20;

axis_in_camera_coord = crossProduct(va, vb);

axis.x = axis_in_camera_coord[0];
axis.y = axis_in_camera_coord[1];
axis.z = axis_in_camera_coord[2];
axis.w = 1.0f;

last_mx = cur_mx;
last_my = cur_my;
}
Quaternion q = qFromAngleAxis(angle, axis);
Matrix m;
qGLMatrix(q,m);

vi = mMultiply(m, vi);
up = mMultiply(m, up);

ViewMatrix = ogLookAt(vi.x, vi.y, vi.z,0,0,0,up.x,up.y,up.z);

• EDIT Instead of a single RT view matrix ive split it into 2 rotations one on the X axis and another on the Y axis (RR*T). Also i was implementing quaternion rotation without setting my initial camera orientation.. – user38873 Nov 29 '13 at 19:45
• You should post that as an answer for future visitors, and mark as the answer as well (please don't include "tags" like "resolved" in question titles). – user1430 Nov 30 '13 at 0:41
• I think you're overcomplicating things a bit. You may check those answers: gamedev.stackexchange.com/questions/26007/… stackoverflow.com/questions/21603412/… – kolenda Mar 3 '14 at 14:36