PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
camera_component.h
1#pragma once
2
3#include "pixelbullet/serialization/node.h"
4
5#include <string>
6#include <string_view>
7
8namespace pixelbullet
9{
10enum class CameraProjectionMode
11{
12 Perspective,
13 Orthographic,
14};
15
16[[nodiscard]] constexpr std::string_view ToString(const CameraProjectionMode value) noexcept
17{
18 switch (value)
19 {
20 case CameraProjectionMode::Orthographic:
21 return "Orthographic";
22 case CameraProjectionMode::Perspective:
23 default:
24 return "Perspective";
25 }
26}
27
28inline Node& operator<<(Node& node, const CameraProjectionMode& value)
29{
30 node << std::string(ToString(value));
31 return node;
32}
33
34inline const Node& operator>>(const Node& node, CameraProjectionMode& value)
35{
36 std::string serialized;
37 node >> serialized;
38 value = serialized == "Orthographic" ? CameraProjectionMode::Orthographic : CameraProjectionMode::Perspective;
39 return node;
40}
41
43{
44 bool primary = true;
45 float field_of_view_degrees = 45.0f;
46 float near_plane = 0.1f;
47 float far_plane = 1000.0f;
48 CameraProjectionMode projection_mode = CameraProjectionMode::Perspective;
49 float orthographic_x_mag = 1.0f;
50 float orthographic_y_mag = 1.0f;
51};
52
53inline Node& operator<<(Node& node, const CameraComponent& camera)
54{
55 node["primary"] << camera.primary;
56 node["fieldOfViewDegrees"] << camera.field_of_view_degrees;
57 node["nearPlane"] << camera.near_plane;
58 node["farPlane"] << camera.far_plane;
59 node["projectionMode"] << camera.projection_mode;
60 node["orthographicXMag"] << camera.orthographic_x_mag;
61 node["orthographicYMag"] << camera.orthographic_y_mag;
62 return node;
63}
64
65inline const Node& operator>>(const Node& node, CameraComponent& camera)
66{
67 node["primary"] >> camera.primary;
68 node["fieldOfViewDegrees"] >> camera.field_of_view_degrees;
69 node["nearPlane"] >> camera.near_plane;
70 node["farPlane"] >> camera.far_plane;
71 if (node.has_property("projectionMode"))
72 {
73 node["projectionMode"] >> camera.projection_mode;
74 }
75 if (node.has_property("orthographicXMag"))
76 {
77 node["orthographicXMag"] >> camera.orthographic_x_mag;
78 }
79 if (node.has_property("orthographicYMag"))
80 {
81 node["orthographicYMag"] >> camera.orthographic_y_mag;
82 }
83 return node;
84}
85} // namespace pixelbullet
Represents a hierarchical node capable of storing various data types and supporting YAML serializatio...
Definition node.h:49
Definition camera_component.h:43