Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
CameraComponent.h
Go to the documentation of this file.
1/**
2 * @file CameraComponent.h
3 * @ingroup mnd_components
4 * @brief Perspective camera that drives the scene's view and projection matrices.
5 *
6 * Attach this component to a GameObject and call Scene::SetMainCamera() on
7 * that object. Engine::Run() queries it each frame to compute CameraData
8 * (view + projection) which is then forwarded to every shader via RenderQueue.
9 *
10 * The view matrix is built from the owner's world transform (position and
11 * rotation). The projection matrix is perspective, driven by m_fov and the
12 * window's current aspect ratio (passed in by the engine each frame).
13 *
14 * @see CameraData, Scene::SetMainCamera, Engine::Run
15 */
16
17#pragma once
18
19#include "Constants.h"
20#include "Types.h"
21#include "scene/Component.h"
22
23namespace mnd
24{
25
26/**
27 * @brief Perspective camera — provides view and projection matrices each frame.
28 *
29 * Works in conjunction with the owning GameObject's transform:
30 * - Position and rotation of the owner define where the camera is and where it looks.
31 * - m_fov, m_nearPlane, m_farPlane define the viewing frustum.
32 */
34{
36public:
37 /// No per-frame logic needed; view/projection are computed on demand.
38 void Update(f32 deltaTime) override;
39
40 /**
41 * @brief Compute the view matrix from the owner's world transform.
42 *
43 * Equivalent to glm::inverse(owner->GetWorldTransform()). Converts
44 * world-space coordinates into camera-space (eye space).
45 *
46 * @return Column-major 4×4 view matrix.
47 */
48 [[nodiscard]] mat4 GetViewMatrix() const;
49
50 /**
51 * @brief Compute the perspective projection matrix.
52 *
53 * Maps camera-space coordinates to clip space using glm::perspective.
54 *
55 * @param aspect Window width / height (updated each frame by the engine).
56 * @return Column-major 4×4 projection matrix.
57 */
58 [[nodiscard]] mat4 GetProjectionMatrix(f32 aspect) const;
59
60 [[nodiscard]] f32 GetFov() const { return m_fov; }
61
62 [[nodiscard]] f32 GetNearPlane() const { return m_nearPlane; }
63
64 [[nodiscard]] f32 GetFarPlane() const { return m_farPlane; }
65
66 void SetFov(f32 fov) { m_fov = fov; }
67
68 void SetNearPlane(f32 n) { m_nearPlane = n; }
69
70 void SetFarPlane(f32 f) { m_farPlane = f; }
71
72private:
73 f32 m_fov = kCameraFov; ///< Vertical field of view in degrees.
74 f32 m_nearPlane = kCameraNearPlane; ///< Distance to the near clip plane (avoid setting to 0).
75 f32 m_farPlane = kCameraFarPlane; ///< Distance to the far clip plane.
76};
77
78} // namespace mnd
Engine-wide compile-time tunables and ANSI colour codes.
constexpr mnd::f32 kCameraFov
Definition Constants.h:74
constexpr mnd::f32 kCameraFarPlane
Definition Constants.h:76
constexpr mnd::f32 kCameraNearPlane
Definition Constants.h:75
Engine-wide primitive type aliases and GLM math imports.
Perspective camera — provides view and projection matrices each frame.
void Update(f32 deltaTime) override
No per-frame logic needed; view/projection are computed on demand.
mat4 GetProjectionMatrix(f32 aspect) const
Compute the perspective projection matrix.
mat4 GetViewMatrix() const
Compute the view matrix from the owner's world transform.
#define COMPONENT(ComponentClass)
Definition Component.h:105
glm::mat4 mat4
4×4 column-major float matrix (model/view/projection).
Definition Types.h:63
float f32
32-bit IEEE float — the standard GL scalar type.
Definition Types.h:40