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!
1 Answer
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.