ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
CameraComponent类 参考

相机组件,定义"从哪个角度观察世界" 更多...

#include <CameraComponent.h>

类 CameraComponent 继承关系图:
Component

Public 成员函数

 CameraComponent ()
void onAttach () override
void onDestroy () override
Vector2 worldToScreen (const Vector2 &worldPosition) const
 世界坐标 → 屏幕像素坐标
Vector2 screenToWorld (const Vector2 &screenPosition) const
 屏幕像素坐标 → 世界坐标
Vector2 getPosition () const
 相机中心位置(从 TransformComponent 同步读取)
Vector2 getSize () const
 视口世界大小
float getZoom () const
 缩放系数
int getPriority () const
 渲染优先级(小值先画)
float getPixelPerUnit () const
 每逻辑单位对应的像素数
void setSize (const Vector2 &worldSize)
void setZoom (float zoom)
void setPriority (int priority)
const SDL_FRect & getViewportRatio () const
 视口比例 (0~1)
void setViewportRatio (const SDL_FRect &ratio)
 设置视口比例
Public 成员函数 继承自 Component
 Component ()
virtual ~Component ()=default
virtual void onCreate ()
virtual void onDetach ()
 Component (const Component &)=delete
Componentoperator= (const Component &)=delete
 Component (Component &&)=delete
Componentoperator= (Component &&)=delete
GameObjectgetOwner () const
bool isRegistered () const

额外继承的成员函数

Protected 属性 继承自 Component
GameObjectm_owner = nullptr
bool m_isRegistered = false

详细描述

相机组件,定义"从哪个角度观察世界"

相机的位置由同 GameObject 上的 TransformComponent 决定。 m_worldSize 决定能看到的世界范围,m_viewportRatio 决定渲染到屏幕的哪个区域。 支持多相机分屏渲染(按 priority 排序)。

构造及析构函数说明

◆ CameraComponent()

CameraComponent ( )

成员函数说明

◆ getPixelPerUnit()

float getPixelPerUnit ( ) const

每逻辑单位对应的像素数

◆ getPosition()

Vector2 getPosition ( ) const

相机中心位置(从 TransformComponent 同步读取)

◆ getPriority()

int getPriority ( ) const
inline

渲染优先级(小值先画)

◆ getSize()

Vector2 getSize ( ) const
inline

视口世界大小

◆ getViewportRatio()

const SDL_FRect & getViewportRatio ( ) const
inline

视口比例 (0~1)

◆ getZoom()

float getZoom ( ) const
inline

缩放系数

◆ onAttach()

void onAttach ( )
overridevirtual

重载 Component .

◆ onDestroy()

void onDestroy ( )
overridevirtual

重载 Component .

◆ screenToWorld()

Vector2 screenToWorld ( const Vector2 & screenPosition) const

屏幕像素坐标 → 世界坐标

◆ setPriority()

void setPriority ( int priority)
inline

◆ setSize()

void setSize ( const Vector2 & worldSize)
inline

◆ setViewportRatio()

void setViewportRatio ( const SDL_FRect & ratio)
inline

设置视口比例

◆ setZoom()

void setZoom ( float zoom)
inline

◆ worldToScreen()

Vector2 worldToScreen ( const Vector2 & worldPosition) const

世界坐标 → 屏幕像素坐标


该类的文档由以下文件生成: