Skip to content

Instantly share code, notes, and snippets.

@byBretema
Last active March 20, 2024 10:16
Show Gist options
  • Save byBretema/54e3c30f5c95a06393d1562679d8f931 to your computer and use it in GitHub Desktop.
Save byBretema/54e3c30f5c95a06393d1562679d8f931 to your computer and use it in GitHub Desktop.
struct NanoCamera
{
float rotx = 0.f;
float roty = 0.f;
float zoom = 0.f;
float fovy = 75.f;
glm::mat4 view = glm::identity<glm::mat4>();
glm::mat4 proj = glm::identity<glm::mat4>();
glm::mat4 update(float aspect, float displ_x, float displ_y, float wheel_y)
{
rotx += displ_x * 0.001f;
roty += displ_y * 0.001f;
zoom += wheel_y;
glm::mat4 pivot = glm::identity<glm::mat4>();
pivot = glm::rotate(pivot, rotx, glm::vec3 { 0, 1, 0 });
pivot = glm::rotate(pivot, roty, glm::vec3 { 1, 0, 0 });
glm::vec3 const front = -1.f * pivot[2].xyz();
glm::vec3 const eye = front * zoom;
view = glm::lookAt(eye, eye + front, pivot[1].xyz());
proj = glm::perspective(fovy, aspect, 0.1f, 1'000.f);
return proj * view;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment