refactor: Camera 位姿统一到 TransformComponent(单一事实源)

- Camera 删除内部 position/yaw/pitch 状态:Update 把鼠标旋转与 WASD
  移动直接写回实体 Transform(rotation.y=yaw / rotation.x=pitch,
  移动基向量由实体旋转推导,有变更才 Compose)
- GetView(transform) = 实体世界矩阵的逆——相机即实体,视图矩阵无
  第二来源;Scene::GetPrimaryCamera 可选带出实体 Transform
- 默认朝向约定变化:rotation.y=0 = 看向 -Z(与旧 yaw=-90 等价)
- 消除 CameraComponent 位置与 Transform 脱节的遗留债
This commit is contained in:
2026-09-23 15:14:29 +08:00
parent 019c17c7e7
commit 1bc44e261b
6 changed files with 71 additions and 67 deletions
+6 -5
View File
@@ -136,9 +136,10 @@ namespace Engine
ubo.prevView = m_LastView;
ubo.prevProj = m_LastProjNoJitter;
// ---- 1. 相机 ----
auto* cameraComp = scene.GetPrimaryCamera();
if (!cameraComp) {
// ---- 1. 相机(位姿单一事实源 = 相机实体的 Transform)----
TransformComponent* camTransform = nullptr;
auto* cameraComp = scene.GetPrimaryCamera(&camTransform);
if (!cameraComp || !camTransform) {
// 无相机:本帧跳过(正常场景必有相机,安全网)
return false;
}
@@ -146,7 +147,7 @@ namespace Engine
const f32 aspect = static_cast<f32>(targetExtent.width) /
static_cast<f32>(targetExtent.height);
ubo.view = camera.GetView();
ubo.view = camera.GetView(*camTransform);
ubo.proj = camera.GetProjection(aspect, 0.1f, 100.0f);
// 未抖动投影:velocity 的当前帧 clip 位置用它(抖动不能进 velocity)
@@ -184,7 +185,7 @@ namespace Engine
ubo.lights[i].color = glm::vec4(0.0f);
}
ComputeCascades(shadowDir);
ubo.cameraPos = glm::vec4(camera.GetPosition(), 1.0f);
ubo.cameraPos = glm::vec4(camTransform->position, 1.0f);
// ---- 3. GPUDriven:单趟收集 + 多视图剔除 ----
// 每个实例的包围球对 4 个视锥分别测试: