I'm trying my hardest to understand what this code is doing so far I think the sin(theta)
and cos(theta)
of the code is representing a point with an angle.
This point with an angle sin(theta)
and cos(theta)
will allow the xmouse/16
value and ymouse/16
value to rotate or translate on this point with an angle because of their layout representation in the GLM::LookAt()
function (view/camera matrix).
The result of doing this is that the view matrix rotates on the x axis left and right when I move the mouse left and right and the y axis up and down when I move the mouse up and down.
Is this correct? It took a lot work to understand this and if I am correct does anyone know how to move the mouse left, right, up and down from the centre of the screen (as in the mouse cursor at centre of the screen when moved to the left, right, up and down will move the camera respectively) rather then from a small region of the top left hand corner thanks!.
N.B.: I'm using Model Matrix and Perspective Projection Matrix with this in the middle so Model * View * Perspective
- C++ OpenGL 3.3x GLSL 3.30 CORE Windows 10
Code:
GLuint OpenGL_Engine::SetupViewCamera(GLFWwindow *RenderWindow, glm::vec3 eyepos, glm::vec3 originpos, glm::vec3 viewrotationpos, GLuint program, GLfloat RotAng)
{
double xmouse = 0.0f, ymouse = 0.0f;
glfwGetCursorPos(RenderWindow, &xmouse, &ymouse);
double theta = glm::radians(RotAng);
glm::vec3 camera(cos(theta), 0.0f, sin(theta));
camera *= 5;
glm::mat4 ViewMatrix = glm::lookAt(
camera,
glm::vec3(xmouse/16, ymouse/16, 0.0),
glm::vec3(0.0, 1.0, 0));
glm::mat4 IViewMatrix = glm::inverse(ViewMatrix);
GLint Viewmatrixloc = glGetUniformLocation(program, "VM");
glUniformMatrix4fv(Viewmatrixloc, 1, GL_FALSE, &IViewMatrix[0][0]);
return 80;
}