-
Notifications
You must be signed in to change notification settings - Fork 7
/
Camera.h
36 lines (29 loc) · 1.04 KB
/
Camera.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* Copyright (c) Aleksey Fedotov
* MIT licence
*/
#pragma once
#include "Transform.h"
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/glm.hpp>
class Camera final
{
public:
auto transform() -> Transform & { return transform_; }
auto setPerspective(float fov, float aspectRatio, float nearClip, float farClip) -> Camera &;
auto setOrthographic(float width, float height, float nearClip, float farClip) -> Camera &;
auto viewMatrix() const -> glm::mat4 { return glm::inverse(transform_.worldMatrix()); }
auto invViewMatrix() const -> glm::mat4 { return glm::inverse(viewMatrix()); }
auto projMatrix() const -> glm::mat4;
auto viewProjMatrix() const -> glm::mat4 { return projMatrix() * viewMatrix(); }
auto invViewProjMatrix() const -> glm::mat4 { return glm::inverse(viewProjMatrix()); }
protected:
bool ortho_ = false;
float fov_ = glm::degrees(60.0f);
float aspectRatio_ = 1;
float orthoWidth_ = 1;
float orthoHeight_ = 1;
float nearClip_ = 1;
float farClip_ = 100;
Transform transform_;
};