81 lines
2.7 KiB
Markdown
81 lines
2.7 KiB
Markdown
|
|
# 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) - 变换组件
|