MQEngine
载入中...
搜索中...
未找到
Camera.h
浏览该文件的文档.
1//
2// Created by Administrator on 2025/8/24.
3//
4
5#ifndef CAMERA_H
6#define CAMERA_H
7#include "../EnginePCH.h"
8#include "../Thirdparty/thirdparty.h"
9#include <boost/describe.hpp>
10namespace MQEngine {
11 constexpr FCT::UniformSlot CameraUniformSlot {
12 "CameraUniform",
13 FCT::UniformVar{FCT::UniformType::ProjectionMatrix},
14 FCT::UniformVar{FCT::UniformType::ViewMatrix}
15 };
17 FCT::Vec3 position;
18 template<class Archive>
19 void serialize(Archive& ar, const unsigned int version) {
20 ar & position;
21 }
22 };
24
25 struct ENGINE_API RotationComponent {
26 FCT::Vec3 rotation;
27
28 template<class Archive>
29 void serialize(Archive& ar, const unsigned int version) {
30 ar & rotation;
31 }
32 };
33 BOOST_DESCRIBE_STRUCT(RotationComponent, (), (rotation))
34
35 struct ENGINE_API ScaleComponent {
36 FCT::Vec3 scale = FCT::Vec3(1.0f, 1.0f, 1.0f);
37 template<class Archive>
38 void serialize(Archive& ar, const unsigned int version) {
39 ar & scale;
40 }
41 };
42 BOOST_DESCRIBE_STRUCT(ScaleComponent, (), (scale))
43
44 struct ENGINE_API CameraComponent {
45 bool active = true;
46 float fov = 45.0f;
47 float nearPlane = 0.1f;
48 float farPlane = 1000.0f;
49 template<class Archive>
50 void serialize(Archive& ar, const unsigned int version) {
51 ar & fov;
52 ar & nearPlane;
53 ar & farPlane;
54 }
55 };
56 BOOST_DESCRIBE_STRUCT(CameraComponent, (), (active, fov, nearPlane, farPlane))
57
58 struct ENGINE_API CacheRotationMatrix {
59 FCT::Mat4 rotationMatrix;
60 };
61
62 constexpr FCT::UniformSlot ModelUniformSlot {
63 "ModelUniform",
64 FCT::UniformVar{FCT::UniformType::ModelMatrix,"modelMatrix"}
65 };
66
68 FCT::Uniform* uniform = nullptr;
69 bool init = false;
70 bool ownsUniform = true; // 标记是否拥有uniform的所有权
71
72 CacheModelMatrix() = delete;
73 explicit CacheModelMatrix(FCT::Context* ctx) : init(false), ownsUniform(true)
74 {
75 uniform = new FCT::Uniform(ctx, ModelUniformSlot);
76 }
77
79 if (ownsUniform && uniform) {
80 delete uniform;
81 uniform = nullptr;
82 }
83 }
84
87
89 : uniform(other.uniform), init(other.init), ownsUniform(other.ownsUniform) {
90 other.uniform = nullptr;
91 other.ownsUniform = false;
92 }
93
95 if (this != &other) {
96 if (ownsUniform && uniform) {
97 delete uniform;
98 }
99 uniform = other.uniform;
100 init = other.init;
101 ownsUniform = other.ownsUniform;
102 other.uniform = nullptr;
103 other.ownsUniform = false;
104 }
105 return *this;
106 }
107 };
108
109} // MQEngine
110
111#endif //CAMERA_H
#define ENGINE_API
定义 EnginePCH.h:14
定义 application.h:5
BOOST_DESCRIBE_STRUCT(PositionComponent,(),(position)) struct ENGINE_API RotationComponent
定义 Camera.h:23
constexpr FCT::UniformSlot ModelUniformSlot
定义 Camera.h:62
constexpr FCT::UniformSlot CameraUniformSlot
定义 Camera.h:11
bool init
定义 Camera.h:69
CacheModelMatrix(const CacheModelMatrix &)=delete
bool ownsUniform
定义 Camera.h:70
FCT::Uniform * uniform
定义 Camera.h:68
~CacheModelMatrix()
定义 Camera.h:78
CacheModelMatrix & operator=(CacheModelMatrix &&other) noexcept
定义 Camera.h:94
CacheModelMatrix & operator=(const CacheModelMatrix &)=delete
CacheModelMatrix(CacheModelMatrix &&other) noexcept
定义 Camera.h:88
CacheModelMatrix(FCT::Context *ctx)
定义 Camera.h:73
定义 Camera.h:16
void serialize(Archive &ar, const unsigned int version)
定义 Camera.h:19
FCT::Vec3 position
定义 Camera.h:17