84 lines
1.8 KiB
C++
84 lines
1.8 KiB
C++
/**
|
|
* @file Transform.h
|
|
* @brief 变换组件数据结构与更新接口。
|
|
*/
|
|
#pragma once
|
|
#include "ComponentsCommon.h"
|
|
|
|
namespace XEngine::transform {
|
|
|
|
/**
|
|
* @brief 变换组件初始化参数。
|
|
*/
|
|
struct init_info
|
|
{
|
|
f32 position[3]{};
|
|
f32 rotation[4]{};
|
|
f32 scale[3]{1.f, 1.f, 1.f};
|
|
};
|
|
|
|
/**
|
|
* @brief 变换组件缓存更新标记位。
|
|
*/
|
|
struct component_flags
|
|
{
|
|
enum flags :u32 {
|
|
rotation = 0x01,
|
|
orientation = 0x02,
|
|
position = 0x04,
|
|
scale = 0x08,
|
|
|
|
|
|
all = rotation | orientation | position| scale
|
|
};
|
|
};
|
|
|
|
/**
|
|
* @brief 变换组件批量更新缓存项。
|
|
*/
|
|
struct component_cache
|
|
{
|
|
math::v4 rotation;
|
|
math::v3 orientation;
|
|
math::v3 position;
|
|
math::v3 scale;
|
|
|
|
transform_id id;
|
|
u32 flags;
|
|
};
|
|
|
|
/**
|
|
* @brief 获取实体的世界矩阵与逆世界矩阵。
|
|
* @param id 实体标识符。
|
|
* @param world 输出世界矩阵。
|
|
* @param inverse_world 输出逆世界矩阵。
|
|
*/
|
|
void get_transform_matrices(const game_entity::entity_id id, math::m4x4& world, math::m4x4& inverse_world);
|
|
/**
|
|
* @brief 为实体创建变换组件。
|
|
* @param info 变换初始化参数。
|
|
* @param entity 目标实体。
|
|
* @return 创建后的变换组件句柄。
|
|
*/
|
|
component create( init_info info, game_entity::entity entity);
|
|
/**
|
|
* @brief 移除变换组件。
|
|
* @param c 变换组件句柄。
|
|
*/
|
|
void remove(component c);
|
|
/**
|
|
* @brief 查询指定实体集合的变换更新标记。
|
|
* @param ids 实体标识符数组。
|
|
* @param count 实体数量。
|
|
* @param flags 输出标记数组。
|
|
*/
|
|
void get_update_component_flags(const game_entity::entity_id *const ids, u32 count, u8 *const flags);
|
|
/**
|
|
* @brief 批量提交变换缓存更新。
|
|
* @param cache 缓存数组首地址。
|
|
* @param count 缓存项数量。
|
|
*/
|
|
void update(const component_cache *const cache, u32 count);
|
|
|
|
}
|