vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
camera.h
1#pragma once
2
3#include <glm/glm.hpp>
4#include <glm/gtc/matrix_transform.hpp>
5
6#include "core/reflect.h"
7#include "ecs/entity.h"
8
9namespace Vkm::Engine {
10
11class Scene;
12
16enum class ProjectionType {
17 Perspective = 0,
18 Orthographic = 1,
19 Count
20};
21
25struct Camera {
26 ProjectionType projection = ProjectionType::Perspective;
28 float fovY = glm::radians(70.0f);
29 float orthoHeight = 10.0f;
31 float aspect = 0.0f;
32 float zNear = 0.1f;
33 float zFar = 1000.0f;
35 float focusDistance = 10.0f;
36 float dofAmount = 0.0f;
38 float dofMaxBlur = 0.011f;
39 bool active = true;
40
48 static glm::mat4 computeProjection(const Camera& camera, float viewportAspect) {
49 const float aspect = camera.aspect > 0.0f ? camera.aspect : viewportAspect;
50 if (camera.projection == ProjectionType::Perspective) {
51 return glm::perspective(camera.fovY, aspect, camera.zNear, camera.zFar);
52 } else {
53 const float halfWidth = camera.orthoHeight * aspect;
54 return glm::ortho(
55 -halfWidth,
56 halfWidth,
57 -camera.orthoHeight,
58 camera.orthoHeight,
59 camera.zNear,
60 camera.zFar
61 );
62 }
63 }
64};
65
77EntityId findActiveCamera(const Scene& scene, EntityId cached = {});
78
79} // namespace Vkm::Engine
80
81VKM_ENUM_NAMES(::Vkm::Engine::ProjectionType, "Perspective", "Orthographic")
82
83VKM_REFLECT_BEGIN(::Vkm::Engine::Camera)
84 VKM_F(projection)
85 VKM_F(fovY)
86 VKM_F(orthoHeight)
87 VKM_F(aspect)
88 VKM_F(zNear)
89 VKM_F(zFar)
90 VKM_F(focusDistance)
91 VKM_F(dofAmount)
92 VKM_F(dofMaxBlur)
93 VKM_F(active)
94VKM_REFLECT_END()
Central registry managing entities and an open set of component types.
Definition scene.h:29
Component representing a camera, containing projection and view parameters.
Definition camera.h:25
float aspect
Width / height; <= 0 derives it from the viewport each frame.
Definition camera.h:31
float fovY
Vertical, radians.
Definition camera.h:28
static glm::mat4 computeProjection(const Camera &camera, float viewportAspect)
Compute the projection matrix for this camera.
Definition camera.h:48
float orthoHeight
Definition camera.h:29
float focusDistance
World distance held in sharp focus.
Definition camera.h:35
float dofAmount
Definition camera.h:36
float dofMaxBlur
Widest blur radius, fraction of viewport height (0..0.05)
Definition camera.h:38