I'm currently working on a OpenGl Project and I have alot of difficulty understanding how arcball camera work. From what I have read online, all I have to do is to rotate a camera around a target and I dont have to worry about any others things. This is my code.

glm::vec4 cameraTarget = glm::vec4(InPointToFix.x, InPointToFix.y, InPointToFix.z, 1.0);

const GLfloat x_Rotation = InPitchValue / 57.5829;
const GLfloat y_Rotation = InYawValue / 57.5829;

glm::mat4 tempoMatrix = InMatrix;
tempoMatrix = glm::rotate(tempoMatrix, x_Rotation, glm::vec3(1.0, 0.0, 0.0));
tempoMatrix = glm::rotate(tempoMatrix, y_Rotation, glm::vec3(0.0, 1.0, 0.0));

glm::vec4 cameraPosition = (tempoMatrix * glm::vec4(1,1,1,1));

InMatrix = glm::lookAt(glm::vec3(cameraPosition), glm::vec3(cameraTarget), glm::vec3(0.0, 1.0, 0.0));

So, in my code, I get my previous View Matrix from the function and my angle parameters, I create a new tempoMatrix by using my old Matrix, I rotate it by the Yaw and pitch I received by the function, I then transform my tempo matrix into a vec4 (to be used as a vec3 later) and then I apply the change to my ViewMatrix I receive by reference.

What happen is that whenever I apply the change, the camera stays at the exact same position but just zoom out and out until I see nothing ...

It's been a while I'm trying to figure this out and I really need help with the ArcBall Camera.

  • \$\begingroup\$ Did you look if InPitchValue and InYawValue do change when you you apply a change? It could determine if your problem is from a maths error or from another part of your code. \$\endgroup\$ – Aracthor May 16 '16 at 2:49
  • \$\begingroup\$ They don't, they are either -1.0, 1.0 or 0. \$\endgroup\$ – Gabriel Roy May 16 '16 at 4:43
  • \$\begingroup\$ If your angles never change, why are you surprises your camera's rotation doesn't? \$\endgroup\$ – Aracthor May 16 '16 at 5:51
  • \$\begingroup\$ Its suppose to work because I use the matrix by reference. and my question was originaly why the camera zoom out. \$\endgroup\$ – Gabriel Roy May 16 '16 at 6:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.