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 {
16 public:
18
19 void onAttach() override;
20 void onDestroy() override;
21
22 // 坐标转换
23 Vector2 worldToScreen(const Vector2& worldPosition) const;
24 Vector2 screenToWorld(const Vector2& screenPosition) const;
25
27 Vector2 getSize() const { return m_worldSize; }
28 float getZoom() const { return m_zoom; }
29 int getPriority() const { return m_priority; }
30 float getPixelPerUnit() const;
31
32 void setSize(const Vector2& worldSize) { m_worldSize = worldSize; }
33 void setZoom(float zoom) { m_zoom = zoom; }
34 void setPriority(int priority) { m_priority = priority; }
35
36 const SDL_FRect& getViewportRatio() const { return m_viewportRatio; }
37 void setViewportRatio(const SDL_FRect& ratio) { m_viewportRatio = ratio; }
38
39 private:
40 Vector2 m_worldSize{ 1280.0f, 720.0f };
41 float m_zoom = 1.0f;
42 int m_priority = 0;
43 SDL_FRect m_viewportRatio{ 0.0f, 0.0f, 1.0f, 1.0f };
44 };
45}
#define SHIT_API
定义 Core.h:12
Vector2 getSize() const
视口世界大小
定义 CameraComponent.h:27
void setViewportRatio(const SDL_FRect &ratio)
设置视口比例
定义 CameraComponent.h:37
void setPriority(int priority)
定义 CameraComponent.h:34
Vector2 worldToScreen(const Vector2 &worldPosition) const
世界坐标 → 屏幕像素坐标
Vector2 getPosition() const
相机中心位置(从 TransformComponent 同步读取)
float getZoom() const
缩放系数
定义 CameraComponent.h:28
void setSize(const Vector2 &worldSize)
定义 CameraComponent.h:32
void onAttach() override
float getPixelPerUnit() const
每逻辑单位对应的像素数
int getPriority() const
渲染优先级(小值先画)
定义 CameraComponent.h:29
Vector2 screenToWorld(const Vector2 &screenPosition) const
屏幕像素坐标 → 世界坐标
void setZoom(float zoom)
定义 CameraComponent.h:33
void onDestroy() override
const SDL_FRect & getViewportRatio() const
视口比例 (0~1)
定义 CameraComponent.h:36
定义 AudioPlayer.h:9
glm::vec2 Vector2
定义 Math.h:5