ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
Toggle main menu visibility
载入中...
搜索中...
未找到
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
7
namespace
Shit
{
8
16
class
SHIT_API
SHIT_REFLECT
(BlackList)
CameraComponent
:
public
Component
{
17
SHIT_REFLECT_BODY
(
CameraComponent
)
18
public
:
19
CameraComponent
();
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
28
Vector2
getPosition
()
const
;
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
}
Component.h
Core.h
SHIT_API
#define SHIT_API
定义
Core.h:14
SHIT_REFLECT_BODY
#define SHIT_REFLECT_BODY(Type)
定义
Macros.h:62
SHIT_REFLECT
#define SHIT_REFLECT(Mode)
定义
Macros.h:59
SHIT_META
#define SHIT_META(...)
定义
Macros.h:68
Math.h
Shit::CameraComponent::getSize
Vector2 getSize() const
视口世界大小
定义
CameraComponent.h:29
Shit::CameraComponent::CameraComponent
CameraComponent()
Shit::CameraComponent::setViewportRatio
void setViewportRatio(const SDL_FRect &ratio)
设置视口比例
定义
CameraComponent.h:41
Shit::CameraComponent::setPriority
void setPriority(int priority)
定义
CameraComponent.h:36
Shit::CameraComponent::setEnabled
void setEnabled(bool enabled)
是否参与渲染(编辑器双视图分离用)
定义
CameraComponent.h:37
Shit::CameraComponent::worldToScreen
Vector2 worldToScreen(const Vector2 &worldPosition) const
世界坐标 → 屏幕像素坐标
Shit::CameraComponent::getPosition
Vector2 getPosition() const
相机中心位置(从 TransformComponent 同步读取)
Shit::CameraComponent::getZoom
float getZoom() const
缩放系数
定义
CameraComponent.h:30
Shit::CameraComponent::isEnabled
bool isEnabled() const
定义
CameraComponent.h:38
Shit::CameraComponent::setSize
void setSize(const Vector2 &worldSize)
定义
CameraComponent.h:34
Shit::CameraComponent::onAttach
void onAttach() override
Shit::CameraComponent::getPixelPerUnit
float getPixelPerUnit() const
每逻辑单位对应的像素数
Shit::CameraComponent::onDetach
void onDetach() override
Shit::CameraComponent::getPriority
int getPriority() const
渲染优先级(小值先画)
定义
CameraComponent.h:31
Shit::CameraComponent::screenToWorld
Vector2 screenToWorld(const Vector2 &screenPosition) const
屏幕像素坐标 → 世界坐标
Shit::CameraComponent::setZoom
void setZoom(float zoom)
定义
CameraComponent.h:35
Shit::CameraComponent::getViewportRatio
const SDL_FRect & getViewportRatio() const
视口比例 (0~1)
定义
CameraComponent.h:40
Shit::Component::Component
Component()
Shit
定义
AudioPlayer.h:10
Shit::Vector2
glm::vec2 Vector2
定义
Math.h:5
include
ShitEngine
Component
CameraComponent.h
制作者
1.17.0