4 #include <glm/gtc/matrix_transform.hpp>
15 , projection(glm::perspective(fov, aspect, near_clip, far_clip))
16 , view(glm::inverse(Transform()))
22 void Camera::Viewport(int width, int height) {
23 Viewport(0, 0, width, height);
26 void Camera::Viewport(int x, int y, int width, int height) {
27 glViewport(x, y, width, height);
28 Aspect(width, height);
31 void Camera::FOV(float f) {
36 void Camera::Aspect(float r) {
41 void Camera::Aspect(float w, float h) {
45 void Camera::Clip(float near, float far) {
51 Ray Camera::Aim() const {
52 const glm::mat4 inv_vp(glm::inverse(vp));
53 glm::vec4 from = inv_vp * glm::vec4(0.0f, 0.0f, -1.0f, 1.0f);
55 glm::vec4 to = inv_vp * glm::vec4(0.0f, 0.0f, 1.0f, 1.0f);
57 return Ray{ glm::vec3(from), glm::normalize(glm::vec3(to - from)) };
61 void Camera::Update(int dt) {
62 FPSController::Update(dt);
63 view = glm::inverse(Transform());
64 vp = projection * view;
67 void Camera::UpdateProjection() {
68 projection = glm::perspective(fov, aspect, near_clip, far_clip);