Skip to content

Instantly share code, notes, and snippets.

@ac101m
Created April 22, 2019 03:13
Show Gist options
  • Save ac101m/97b5adbb24188ab3640690b1e22fda2d to your computer and use it in GitHub Desktop.
Save ac101m/97b5adbb24188ab3640690b1e22fda2d to your computer and use it in GitHub Desktop.
Camera rotation opengl
// member function changes direction camera is looking
void Camera::MoveLook(const float dx, const float dy, const float dr) {
// rotate cam.fwd & cam.right around cam.up by dx
this->fwd = glm::rotate(this->fwd, dx, this->up);
this->right = glm::rotate(this->right, dx, this->up);
// rotate cam.up & cam.fwd around cam.right by dy
this->up = glm::rotate(this->up, dy, this->right);
this->fwd = glm::rotate(this->fwd, dy, this->right);
// rotate cam.up & cam.right around cam.fwd by dr
this->up = glm::rotate(this->up, dr, this->fwd);
this->right = glm::rotate(this->right, dr, this->fwd);
// recalculate view matrix
this->UpdateViewMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment