# How to use trackball for rotating an camera matrix in eye frame

I have a QOpenGLWidget where I use camera transformation matrix(4,4), FOV and vectors Position(4), Up(4), Forward(4). I also have an ArcBall which I can use. I managed to implement zoom and pan by modifying the Position vector. Now I want to implement rotation with arcball.

On mouseMove I compute the rotation matrix with arcball. Then I need to use this matrix for rotating the camera. Now how do I do that?

I tried multiplying or summing the camera matrix and arcball matrix but it is not working for me.

• this should help Jun 3, 2021 at 11:20
• I somehow managed to do it with multiplying the arcball matrix with something like product(look_from_zero) of forward and up vector (I did not use left vector). But thanks. Jun 3, 2021 at 12:16
• To clarify my comment: result matrix = lookFromZero(forward * arcball, up* arcball). Maybe it will help someone. Sep 19, 2022 at 12:08

I'm assuming the rotation matrix generated from the arcball is 2D, so I think there are a few clear top level steps. But I'm not sure about the details of some of them.

First you'll need to extend the 2D rotation to 3D which should be easy.

Next you'll need to rotate the rotation matrix itself so its axis aligns with your Forward vector. I'm not certain how to do this step.

Then, use the resulting matrix to transform the Up vector and reconstruct the camera matrix using the new vector and the other values and vectors.