4 #include <glm/gtc/matrix_transform.hpp>
15 , projection(glm::perspective(fov, aspect, near_clip, far_clip))
16 , view(glm::inverse(Transform())) {
21 void Camera::Viewport(int width, int height) {
22 Viewport(0, 0, width, height);
25 void Camera::Viewport(int x, int y, int width, int height) {
26 glViewport(x, y, width, height);
27 Aspect(width, height);
30 void Camera::FOV(float f) {
35 void Camera::Aspect(float r) {
40 void Camera::Aspect(float w, float h) {
44 void Camera::Clip(float near, float far) {
50 Ray Camera::Aim() const {
51 const glm::mat4 inv_vp(glm::inverse(projection * view));
52 glm::vec4 from = inv_vp * glm::vec4(0.0f, 0.0f, -1.0f, 1.0f);
54 glm::vec4 to = inv_vp * glm::vec4(0.0f, 0.0f, 1.0f, 1.0f);
56 return Ray{ glm::vec3(from), glm::normalize(glm::vec3(to - from)) };
60 void Camera::Update(int dt) {
61 FPSController::Update(dt);
62 view = glm::inverse(Transform());
65 void Camera::UpdateProjection() {
66 projection = glm::perspective(fov, aspect, near_clip, far_clip);