Files
XCEngine/docs/api/components/camera-component/camera-component.md
ssdfasd f5a34f8adc docs: 重构 API 文档 - components 和 scene 模块
- components: 修复英文标题为中文,添加缺失组件文档
  - 新增 camera-component, light-component, audio-source-component, audio-listener-component 类总览
  - 修复 get-position.md 格式
  - 更新 components.md 模块总览
- scene: 修复方法文档格式,新增缺失方法
  - 修复 find.md, create-game-object.md 英文标题
  - 新增 FindByID, SerializeToString, DeserializeFromString 方法文档
  - 更新 scene.md 类总览方法列表
2026-03-26 01:50:27 +08:00

81 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# CameraComponent
**命名空间**: `XCEngine::Components`
**类型**: `class`
**头文件**: `XCEngine/Components/CameraComponent.h`
**描述**: 相机组件,定义视图和投影参数,支持透视和正交两种投影模式。
## 概述
CameraComponent 是 XCEngine ECS 系统中的相机组件用于定义场景的观察视角。它支持透视投影Perspective和正交投影Orthographic两种模式可以设置视场角、近裁剪面、远裁剪面、深度值和清除颜色等参数。
## 枚举
### CameraProjectionType
| 枚举值 | 描述 |
|--------|------|
| `Perspective` | 透视投影,符合人眼观察习惯 |
| `Orthographic` | 正交投影,保持物体真实大小 |
## 公共方法
### 投影设置
| 方法 | 描述 |
|------|------|
| [`GetProjectionType`](get-projection-type.md) | 获取投影类型 |
| [`SetProjectionType`](set-projection-type.md) | 设置投影类型 |
| [`GetFieldOfView`](get-field-of-view.md) | 获取视场角(透视投影) |
| [`SetFieldOfView`](set-field-of-view.md) | 设置视场角 |
| [`GetOrthographicSize`](get-orthographic-size.md) | 获取正交投影大小 |
| [`SetOrthographicSize`](set-orthographic-size.md) | 设置正交投影大小 |
### 裁剪平面
| 方法 | 描述 |
|------|------|
| [`GetNearClipPlane`](get-near-clip-plane.md) | 获取近裁剪面距离 |
| [`SetNearClipPlane`](set-near-clip-plane.md) | 设置近裁剪面距离 |
| [`GetFarClipPlane`](get-far-clip-plane.md) | 获取远裁剪面距离 |
| [`SetFarClipPlane`](set-far-clip-plane.md) | 设置远裁剪面距离 |
### 相机属性
| 方法 | 描述 |
|------|------|
| [`GetDepth`](../../rhi/texture/get-depth.md) | 获取深度值 |
| [`SetDepth`](set-depth.md) | 设置深度值 |
| [`IsPrimary`](is-primary.md) | 检查是否为主相机 |
| [`SetPrimary`](set-primary.md) | 设置为主相机 |
| [`GetClearColor`](get-clear-color.md) | 获取清除颜色 |
| [`SetClearColor`](../../rhi/opengl/pipeline-state/set-clear-color.md) | 设置清除颜色 |
## 使用示例
```cpp
#include <XCEngine/Components/CameraComponent.h>
#include <XCEngine/Components/GameObject.h>
using namespace XCEngine::Components;
void SetupCamera(GameObject* cameraObject) {
auto camera = cameraObject->AddComponent<CameraComponent>();
camera->SetProjectionType(CameraProjectionType::Perspective);
camera->SetFieldOfView(60.0f);
camera->SetNearClipPlane(0.1f);
camera->SetFarClipPlane(1000.0f);
camera->SetPrimary(true);
}
```
## 相关文档
- [Components 模块总览](../components.md) - Components 模块总览
- [Component](../component/component.md) - 组件基类
- [TransformComponent](../transform-component/transform-component.md) - 变换组件