0
\$\begingroup\$

In OpenGL (using shaders), I want to implement a system that will take the user's mouse as input, and then rotate the view about the origin of the rendered scene. So, I need to compute the view matrix (assume the model matrix is identity) that represents this rotation. If the view were to rotate around its own origin, then I could do this by applying a simple rotation operation to the view matrix. However, I don't want to do this -- I want to rotate about the origin of the world coordinate system. So, given a rotation angle "theta", how can I compute this matrix? Thanks!

\$\endgroup\$
  • \$\begingroup\$ In which language is this? \$\endgroup\$ – tkausl Jul 30 '15 at 12:53
  • \$\begingroup\$ I am writing OpenGL code in C++. \$\endgroup\$ – Karnivaurus Jul 30 '15 at 12:54
1
\$\begingroup\$

I would recommend you use the mat-library glm and something like the following:

double theta = glm::radians(90);
glm::vec3 camera(cos(theta), 0, sin(theta));
camera *= 5; // To get some space between camera and object
glm::mat4 matrix = glm::lookAt(camera, glm::vec3(0.0, 0.0, 0.0), glm::vec3(0.0, 1.0, 0,0));

This should give you the result you're looking for.

\$\endgroup\$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.