ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
CameraComponent.h
浏览该文件的文档.
1#pragma once
2#include "../Core/Core.h"
3#include "Component.h"
4#include "../Math.h"
5#include <SDL3/SDL_rect.h>
6
7namespace Shit {
8
16 class SHIT_API SHIT_REFLECT(BlackList) CameraComponent : public Component {
18 public:
20
21 void onAttach() override;
22 void onDetach() override;
23
24 // 坐标转换
25 Vector2 worldToScreen(const Vector2& worldPosition) const;
26 Vector2 screenToWorld(const Vector2& screenPosition) const;
27
29 Vector2 getSize() const { return m_worldSize; }
30 float getZoom() const { return m_zoom; }
31 int getPriority() const { return m_priority; }
32 float getPixelPerUnit() const;
33
34 void setSize(const Vector2& worldSize) { m_worldSize = worldSize; }
35 void setZoom(float zoom) { m_zoom = zoom; }
36 void setPriority(int priority) { m_priority = priority; }
37 void setEnabled(bool enabled) { m_isEnabled = enabled; }
38 bool isEnabled() const { return m_isEnabled; }
39
40 const SDL_FRect& getViewportRatio() const { return m_viewportRatio; }
41 void setViewportRatio(const SDL_FRect& ratio) { m_viewportRatio = ratio; }
42
43 private:
44 SHIT_META(({.displayName = "World Size", .tooltip = "可见世界范围(世界单位)"}))
45 Vector2 m_worldSize{ 1280.0f, 720.0f };
46 SHIT_META(({.displayName = "Zoom", .range = {0.1, 10}, .step = 0.1}))
47 float m_zoom = 1.0f;
48 SHIT_META(({.displayName = "Priority", .tooltip = "渲染优先级(小值先画)"}))
49 int m_priority = 0;
50 SHIT_META(({.displayName = "Viewport Ratio", .tooltip = "相对于逻辑分辨率的视口区域 (0~1)"}))
51 SDL_FRect m_viewportRatio{ 0.0f, 0.0f, 1.0f, 1.0f };
52 bool m_isEnabled = true;
53 };
54}
#define SHIT_API
定义 Core.h:14
#define SHIT_REFLECT_BODY(Type)
定义 Macros.h:62
#define SHIT_REFLECT(Mode)
定义 Macros.h:59
#define SHIT_META(...)
定义 Macros.h:68
Vector2 getSize() const
视口世界大小
定义 CameraComponent.h:29
void setViewportRatio(const SDL_FRect &ratio)
设置视口比例
定义 CameraComponent.h:41
void setPriority(int priority)
定义 CameraComponent.h:36
void setEnabled(bool enabled)
是否参与渲染(编辑器双视图分离用)
定义 CameraComponent.h:37
Vector2 worldToScreen(const Vector2 &worldPosition) const
世界坐标 → 屏幕像素坐标
Vector2 getPosition() const
相机中心位置(从 TransformComponent 同步读取)
float getZoom() const
缩放系数
定义 CameraComponent.h:30
bool isEnabled() const
定义 CameraComponent.h:38
void setSize(const Vector2 &worldSize)
定义 CameraComponent.h:34
void onAttach() override
float getPixelPerUnit() const
每逻辑单位对应的像素数
void onDetach() override
int getPriority() const
渲染优先级(小值先画)
定义 CameraComponent.h:31
Vector2 screenToWorld(const Vector2 &screenPosition) const
屏幕像素坐标 → 世界坐标
void setZoom(float zoom)
定义 CameraComponent.h:35
const SDL_FRect & getViewportRatio() const
视口比例 (0~1)
定义 CameraComponent.h:40
定义 AudioPlayer.h:10
glm::vec2 Vector2
定义 Math.h:5