4 #include <glm/gtc/matrix_transform.hpp>
15 , projection(glm::perspective(fov, aspect, near_clip, far_clip))
16 , view(glm::inverse(Transform()))
26 void Camera::Viewport(int width, int height) {
27 Viewport(0, 0, width, height);
30 void Camera::Viewport(int x, int y, int width, int height) {
31 glViewport(x, y, width, height);
32 Aspect(width, height);
35 void Camera::FOV(float f) {
40 void Camera::Aspect(float r) {
45 void Camera::Aspect(float w, float h) {
49 void Camera::Clip(float near, float far) {
55 Ray Camera::Aim() const {
56 const glm::mat4 inv_vp(glm::inverse(vp));
57 glm::vec4 from = inv_vp * glm::vec4(0.0f, 0.0f, -1.0f, 1.0f);
59 glm::vec4 to = inv_vp * glm::vec4(0.0f, 0.0f, 1.0f, 1.0f);
61 return Ray{ glm::vec3(from), glm::normalize(glm::vec3(to - from)) };
65 void Camera::Update(int dt) {
66 FPSController::Update(dt);
67 view = glm::inverse(Transform());
68 vp = projection * view;
71 void Camera::UpdateProjection() {
72 projection = glm::perspective(fov, aspect, near_clip, far_clip);