Just™ Game Engine
camera.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021-2022 Konstanty Misiak
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7#pragma once
8#include "jng/core/base.hpp"
9
10namespace jng {
11
12 class Camera
13 {
14 public:
15 enum class ProjectionType { Orthographic = 0, Perspective = 1 };
16
17 Camera() { recalculateProjection(); }
18 Camera(const Camera&) = default;
19 void reset() {} // TODO: impl
20
21 void setOrthographic(f32 oSize, f32 oNear = -1.f, f32 oFar = 1.f);
22 void setPerspective(f32 pFOV, f32 pNear = 0.01f, f32 pFar = 1000.f);
23 const glm::mat4& getProjection() const { return m_projection; }
24
25 void setProjectionType(ProjectionType type) { m_projectionType = type; recalculateProjection(); }
26 ProjectionType getProjectionType() const { return m_projectionType; }
27
28 void setViewportSize(f32 width, f32 height);
29 f32 getAspectRatio() const { return m_aspectRatio; }
30
31 f32 getOrthographicSize() const { return m_orthoSize; }
32 f32 getOrthographicNear() const { return m_orthoNear; }
33 f32 getOrthographicFar() const { return m_orthoFar; }
34 void setOrthographicSize(f32 oSize) { m_orthoSize = oSize; recalculateProjection(); }
35 void setOrthographicNear(f32 oNear) { m_orthoNear = oNear; recalculateProjection(); }
36 void setOrthographicFar(f32 oFar) { m_orthoFar = oFar; recalculateProjection(); }
37
38 f32 getPerspectiveFOV() const { return m_perspectiveFOV; }
39 f32 getPerspectiveNear() const { return m_perspectiveNear; }
40 f32 getPerspectiveFar() const { return m_perspectiveFar; }
41 void setPerspectiveFOV(float pFOV) { m_perspectiveFOV = pFOV; recalculateProjection(); }
42 void setPerspectiveNear(float pNear) { m_perspectiveNear = pNear; recalculateProjection(); }
43 void setPerspectiveFar(float pFar) { m_perspectiveFar = pFar; recalculateProjection(); }
44
45 glm::mat4 getVP(const glm::mat4 transform) const;
46 private:
47 void recalculateProjection();
48
49 glm::mat4 m_projection{ 1.f };
50 f32 m_aspectRatio{ 0.f };
51 f32 m_orthoSize{ 10.f };
52 f32 m_orthoNear{ -1.f };
53 f32 m_orthoFar{ 1.f };
54 f32 m_perspectiveFOV{ 45.f };
55 f32 m_perspectiveNear{ 0.01f };
56 f32 m_perspectiveFar{ 1000.f };
58 };
59
60} // namespace jng
Definition: camera.hpp:13
f32 getPerspectiveFar() const
Definition: camera.hpp:40
void setOrthographicFar(f32 oFar)
Definition: camera.hpp:36
ProjectionType getProjectionType() const
Definition: camera.hpp:26
void setOrthographicSize(f32 oSize)
Definition: camera.hpp:34
f32 getOrthographicSize() const
Definition: camera.hpp:31
void setProjectionType(ProjectionType type)
Definition: camera.hpp:25
ProjectionType
Definition: camera.hpp:15
void setOrthographicNear(f32 oNear)
Definition: camera.hpp:35
glm::mat4 getVP(const glm::mat4 transform) const
Definition: camera.cpp:41
f32 getOrthographicNear() const
Definition: camera.hpp:32
Camera(const Camera &)=default
void setPerspectiveFar(float pFar)
Definition: camera.hpp:43
const glm::mat4 & getProjection() const
Definition: camera.hpp:23
Camera()
Definition: camera.hpp:17
void setPerspectiveNear(float pNear)
Definition: camera.hpp:42
void reset()
Definition: camera.hpp:19
void setPerspective(f32 pFOV, f32 pNear=0.01f, f32 pFar=1000.f)
Definition: camera.cpp:25
void setPerspectiveFOV(float pFOV)
Definition: camera.hpp:41
f32 getAspectRatio() const
Definition: camera.hpp:29
void setViewportSize(f32 width, f32 height)
Definition: camera.cpp:34
f32 getPerspectiveNear() const
Definition: camera.hpp:39
void setOrthographic(f32 oSize, f32 oNear=-1.f, f32 oFar=1.f)
Definition: camera.cpp:16
f32 getPerspectiveFOV() const
Definition: camera.hpp:38
f32 getOrthographicFar() const
Definition: camera.hpp:33
Definition: base.hpp:11
float f32
Definition: base.hpp:47