docs: Add Component, GameObject, TransformComponent and Scene API documentation

- Add Component class documentation with lifecycle methods
- Add GameObject class documentation with component system
- Add TransformComponent documentation with transform methods
- Add Scene class documentation with GameObject management
- Add SceneManager singleton documentation with scene loading
- Update components.md overview with all component classes
- Update main.md navigation with Scene module
This commit is contained in:
2026-03-22 03:33:55 +08:00
parent d83ed56177
commit a9d5a68dd6
105 changed files with 3003 additions and 7 deletions

View File

@@ -0,0 +1,26 @@
# DetachChildren
Detach all child transforms.
## Syntax
```cpp
void DetachChildren();
```
## Remarks
Removes all children from this transform. The children become root-level transforms (their parent is set to `nullptr`).
## See Also
- [SetParent](set-parent)
- [GetChild](get-child)
## Examples
```cpp
void Example(TransformComponent* transform) {
transform->DetachChildren();
}
```

View File

@@ -0,0 +1,33 @@
# Find
Find a child transform by name.
## Syntax
```cpp
TransformComponent* Find(const std::string& name) const;
```
## Parameters
- `name` - The name of the child transform to find.
## Returns
Returns a pointer to the child transform with the specified name, or `nullptr` if not found. Only searches direct children, not the entire hierarchy.
## See Also
- [GetChild](get-child)
- [GetChildCount](get-child-count)
## Examples
```cpp
void Example(TransformComponent* transform) {
TransformComponent* child = transform->Find("Weapon");
if (child) {
XC_LOG_INFO("Found child: {}", child->GetName());
}
}
```

View File

@@ -0,0 +1,27 @@
# GetChildCount
Get the number of child transforms.
## Syntax
```cpp
size_t GetChildCount() const;
```
## Returns
Returns the number of direct child transforms.
## See Also
- [GetChild](get-child)
- [GetParent](get-parent)
## Examples
```cpp
void Example(TransformComponent* transform) {
size_t count = transform->GetChildCount();
XC_LOG_INFO("Child count: {}", count);
}
```

View File

@@ -0,0 +1,32 @@
# GetChild
Get a child transform by index.
## Syntax
```cpp
TransformComponent* GetChild(size_t index) const;
```
## Parameters
- `index` - The index of the child transform (0-based).
## Returns
Returns a pointer to the child transform at the specified index, or `nullptr` if the index is out of range.
## See Also
- [GetChildCount](get-child-count)
## Examples
```cpp
void Example(TransformComponent* transform) {
TransformComponent* firstChild = transform->GetChild(0);
if (firstChild) {
XC_LOG_INFO("First child: {}", firstChild->GetName());
}
}
```

View File

@@ -0,0 +1,31 @@
# GetForward
Get the forward direction vector in world space.
## Syntax
```cpp
Math::Vector3 GetForward() const;
```
## Returns
Returns the forward direction vector as a `Math::Vector3`.
## Remarks
Returns the forward direction of this transform in world space, based on the world rotation. By convention, forward is typically the negative Z axis direction.
## See Also
- [GetRight](get-right)
- [GetUp](get-up)
## Examples
```cpp
void Example(TransformComponent* transform) {
Math::Vector3 forward = transform->GetForward();
XC_LOG_INFO("Forward: ({}, {}, {})", forward.x, forward.y, forward.z);
}
```

View File

@@ -0,0 +1,31 @@
# GetLocalEulerAngles
Get the local rotation as Euler angles in degrees.
## Syntax
```cpp
Math::Vector3 GetLocalEulerAngles() const;
```
## Returns
Returns the local rotation as Euler angles `(x, y, z)` in degrees.
## Remarks
Converts the local quaternion rotation to Euler angles representation. The angles represent rotation around the X, Y, and Z axes respectively.
## See Also
- [SetLocalEulerAngles](set-local-euler-angles)
- [GetLocalRotation](get-local-rotation)
## Examples
```cpp
void Example(TransformComponent* transform) {
Math::Vector3 eulers = transform->GetLocalEulerAngles();
XC_LOG_INFO("Local euler angles: ({}, {}, {})", eulers.x, eulers.y, eulers.z);
}
```

View File

@@ -0,0 +1,33 @@
# GetLocalPosition
Get the position of this transform relative to the parent transform.
## Syntax
```cpp
const Math::Vector3& GetLocalPosition() const;
```
## Returns
Returns the local position as a `Math::Vector3` reference. The returned reference remains valid until the transform is modified.
## Remarks
Local position represents the position of this transform in parent space. If this transform has no parent, local position is the same as world position.
## See Also
- [SetLocalPosition](set-local-position)
- [GetPosition](get-position)
- [SetPosition](set-position)
## Examples
```cpp
void Example(TransformComponent* transform) {
const Math::Vector3& localPos = transform->GetLocalPosition();
XC_LOG_INFO("Local position: ({}, {}, {})",
localPos.x, localPos.y, localPos.z);
}
```

View File

@@ -0,0 +1,33 @@
# GetLocalRotation
Get the rotation of this transform relative to the parent transform.
## Syntax
```cpp
const Math::Quaternion& GetLocalRotation() const;
```
## Returns
Returns the local rotation as a `Math::Quaternion` reference.
## Remarks
Local rotation represents the rotation of this transform in parent space. If this transform has no parent, local rotation is the same as world rotation.
## See Also
- [SetLocalRotation](set-local-rotation)
- [GetRotation](get-rotation)
- [SetRotation](set-rotation)
## Examples
```cpp
void Example(TransformComponent* transform) {
const Math::Quaternion& localRot = transform->GetLocalRotation();
XC_LOG_INFO("Local rotation: ({}, {}, {}, {})",
localRot.x, localRot.y, localRot.z, localRot.w);
}
```

View File

@@ -0,0 +1,31 @@
# GetLocalScale
Get the scale of this transform relative to the parent transform.
## Syntax
```cpp
const Math::Vector3& GetLocalScale() const;
```
## Returns
Returns the local scale as a `Math::Vector3` reference.
## Remarks
Local scale represents the scale of this transform in parent space. If this transform has no parent, local scale is the same as world scale.
## See Also
- [SetLocalScale](set-local-scale)
- [GetScale](get-scale)
## Examples
```cpp
void Example(TransformComponent* transform) {
const Math::Vector3& scale = transform->GetLocalScale();
XC_LOG_INFO("Local scale: ({}, {}, {})", scale.x, scale.y, scale.z);
}
```

View File

@@ -0,0 +1,29 @@
# GetLocalToWorldMatrix
Get the transformation matrix from local space to world space.
## Syntax
```cpp
const Math::Matrix4x4& GetLocalToWorldMatrix() const;
```
## Returns
Returns the local-to-world transformation matrix as a `Math::Matrix4x4` reference.
## Remarks
Returns the matrix that transforms a point from local space to world space. The matrix is computed from the local position, rotation, and scale combined with the parent's world transform. Uses lazy evaluation and is cached until the transform is marked dirty.
## See Also
- [GetWorldToLocalMatrix](get-world-to-local-matrix)
## Examples
```cpp
void Example(TransformComponent* transform) {
const Math::Matrix4x4& matrix = transform->GetLocalToWorldMatrix();
}
```

View File

@@ -0,0 +1,32 @@
# GetParent
Get the parent transform.
## Syntax
```cpp
TransformComponent* GetParent() const;
```
## Returns
Returns a pointer to the parent `TransformComponent`, or `nullptr` if this transform has no parent.
## Remarks
Returns the parent transform in the transform hierarchy. The parent transform affects this transform's world position, rotation, and scale.
## See Also
- [SetParent](set-parent)
## Examples
```cpp
void Example(TransformComponent* transform) {
TransformComponent* parent = transform->GetParent();
if (parent) {
XC_LOG_INFO("Has parent: {}", parent->GetName());
}
}
```

View File

@@ -0,0 +1,33 @@
# GetPosition
Get the world position of this transform.
## Syntax
```cpp
Math::Vector3 GetPosition() const;
```
## Returns
Returns the world position as a `Math::Vector3`.
## Remarks
Returns the world-space position of this transform. If this transform has a parent, the world position is computed by combining the local position with the parent's world position.
## See Also
- [GetLocalPosition](get-local-position)
- [SetLocalPosition](set-local-position)
- [SetPosition](set-position)
## Examples
```cpp
void Example(TransformComponent* transform) {
Math::Vector3 worldPos = transform->GetPosition();
XC_LOG_INFO("World position: ({}, {}, {})",
worldPos.x, worldPos.y, worldPos.z);
}
```

View File

@@ -0,0 +1,30 @@
# GetRight
Get the right direction vector in world space.
## Syntax
```cpp
Math::Vector3 GetRight() const;
```
## Returns
Returns the right direction vector as a `Math::Vector3`.
## Remarks
Returns the right direction of this transform in world space, based on the world rotation. By convention, right is typically the positive X axis direction.
## See Also
- [GetForward](get-forward)
- [GetUp](get-up)
## Examples
```cpp
void Example(TransformComponent* transform) {
Math::Vector3 right = transform->GetRight();
}
```

View File

@@ -0,0 +1,31 @@
# GetRotation
Get the world rotation of this transform.
## Syntax
```cpp
Math::Quaternion GetRotation() const;
```
## Returns
Returns the world rotation as a `Math::Quaternion`.
## Remarks
Returns the world-space rotation of this transform. If this transform has a parent, the world rotation is computed by combining the local rotation with the parent's world rotation.
## See Also
- [GetLocalRotation](get-local-rotation)
- [SetLocalRotation](set-local-rotation)
- [SetRotation](set-rotation)
## Examples
```cpp
void Example(TransformComponent* transform) {
Math::Quaternion worldRot = transform->GetRotation();
}
```

View File

@@ -0,0 +1,31 @@
# GetScale
Get the world scale of this transform.
## Syntax
```cpp
Math::Vector3 GetScale() const;
```
## Returns
Returns the world scale as a `Math::Vector3`.
## Remarks
Returns the world-space scale of this transform. If this transform has a parent, the world scale is computed by multiplying the local scale with the parent's world scale.
## See Also
- [GetLocalScale](get-local-scale)
- [SetLocalScale](set-local-scale)
## Examples
```cpp
void Example(TransformComponent* transform) {
Math::Vector3 worldScale = transform->GetScale();
XC_LOG_INFO("World scale: ({}, {}, {})", worldScale.x, worldScale.y, worldScale.z);
}
```

View File

@@ -0,0 +1,28 @@
# GetSiblingIndex
Get the sibling index of this transform among siblings.
## Syntax
```cpp
int GetSiblingIndex() const;
```
## Returns
Returns the sibling index of this transform.
## See Also
- [SetSiblingIndex](set-sibling-index)
- [SetAsFirstSibling](set-as-first-sibling)
- [SetAsLastSibling](set-as-last-sibling)
## Examples
```cpp
void Example(TransformComponent* transform) {
int index = transform->GetSiblingIndex();
XC_LOG_INFO("Sibling index: {}", index);
}
```

View File

@@ -0,0 +1,30 @@
# GetUp
Get the up direction vector in world space.
## Syntax
```cpp
Math::Vector3 GetUp() const;
```
## Returns
Returns the up direction vector as a `Math::Vector3`.
## Remarks
Returns the up direction of this transform in world space, based on the world rotation. By convention, up is typically the positive Y axis direction.
## See Also
- [GetForward](get-forward)
- [GetRight](get-right)
## Examples
```cpp
void Example(TransformComponent* transform) {
Math::Vector3 up = transform->GetUp();
}
```

View File

@@ -0,0 +1,29 @@
# GetWorldToLocalMatrix
Get the transformation matrix from world space to local space.
## Syntax
```cpp
Math::Matrix4x4 GetWorldToLocalMatrix() const;
```
## Returns
Returns the world-to-local transformation matrix as a `Math::Matrix4x4`.
## Remarks
Returns the matrix that transforms a point from world space to local space. This is the inverse of `GetLocalToWorldMatrix()`.
## See Also
- [GetLocalToWorldMatrix](get-local-to-world-matrix)
## Examples
```cpp
void Example(TransformComponent* transform) {
Math::Matrix4x4 worldToLocal = transform->GetWorldToLocalMatrix();
}
```

View File

@@ -0,0 +1,35 @@
# InverseTransformDirection
Transform a direction from world space to local space.
## Syntax
```cpp
Math::Vector3 InverseTransformDirection(const Math::Vector3& direction) const;
```
## Parameters
- `direction` - The world space direction to transform.
## Returns
Returns the transformed direction in local space.
## Remarks
Transforms a direction from world space to local space. Unlike `InverseTransformPoint`, this does not consider translation. Only rotation and scale are applied.
## See Also
- [TransformDirection](transform-direction)
- [InverseTransformPoint](inverse-transform-point)
## Examples
```cpp
void Example(TransformComponent* transform) {
Math::Vector3 worldDir(1.0f, 0.0f, 0.0f);
Math::Vector3 localDir = transform->InverseTransformDirection(worldDir);
}
```

View File

@@ -0,0 +1,35 @@
# InverseTransformPoint
Transform a point from world space to local space.
## Syntax
```cpp
Math::Vector3 InverseTransformPoint(const Math::Vector3& point) const;
```
## Parameters
- `point` - The world space point to transform.
## Returns
Returns the transformed point in local space.
## Remarks
Transforms a point from world space to local space using the transform's world-to-local matrix.
## See Also
- [TransformPoint](transform-point)
- [InverseTransformDirection](inverse-transform-direction)
## Examples
```cpp
void Example(TransformComponent* transform) {
Math::Vector3 worldPoint(10.0f, 0.0f, 0.0f);
Math::Vector3 localPoint = transform->InverseTransformPoint(worldPoint);
}
```

View File

@@ -0,0 +1,28 @@
# LookAt
Rotate the transform to face a target position.
## Syntax
```cpp
void LookAt(const Math::Vector3& target);
void LookAt(const Math::Vector3& target, const Math::Vector3& up);
```
## Parameters
- `target` - The position to look at.
- `up` - The up vector to use (defaults to world up).
## Remarks
Rotates the transform so its forward direction points toward the target position. The optional `up` vector defines which direction is considered up.
## Examples
```cpp
void Example(TransformComponent* transform) {
Math::Vector3 targetPos(10.0f, 0.0f, 5.0f);
transform->LookAt(targetPos);
}
```

View File

@@ -0,0 +1,29 @@
# Rotate
Rotate the transform by the specified angles.
## Syntax
```cpp
void Rotate(const Math::Vector3& eulers, Space relativeTo = Space::Self);
void Rotate(const Math::Vector3& axis, float angle, Space relativeTo = Space::Self);
```
## Parameters
- `eulers` - The Euler angles of rotation (x, y, z).
- `axis` - The axis of rotation.
- `angle` - The angle of rotation in degrees.
- `relativeTo` - Whether the rotation is relative to self or world space.
## Remarks
Applies a rotation to the transform. When `relativeTo` is `Space::Self`, the rotation is applied in local space. When `Space::World`, the rotation is applied in world space.
## Examples
```cpp
void Example(TransformComponent* transform) {
transform->Rotate(Math::Vector3(0.0f, 45.0f, 0.0f), Space::Self);
}
```

View File

@@ -0,0 +1,22 @@
# SetAsFirstSibling
Set this transform as the first sibling (index 0).
## Syntax
```cpp
void SetAsFirstSibling();
```
## See Also
- [SetSiblingIndex](set-sibling-index)
- [SetAsLastSibling](set-as-last-sibling)
## Examples
```cpp
void Example(TransformComponent* transform) {
transform->SetAsFirstSibling();
}
```

View File

@@ -0,0 +1,22 @@
# SetAsLastSibling
Set this transform as the last sibling.
## Syntax
```cpp
void SetAsLastSibling();
```
## See Also
- [SetSiblingIndex](set-sibling-index)
- [SetAsFirstSibling](set-as-first-sibling)
## Examples
```cpp
void Example(TransformComponent* transform) {
transform->SetAsLastSibling();
}
```

View File

@@ -0,0 +1,30 @@
# SetLocalEulerAngles
Set the local rotation using Euler angles in degrees.
## Syntax
```cpp
void SetLocalEulerAngles(const Math::Vector3& eulers);
```
## Parameters
- `eulers` - The Euler angles `(x, y, z)` in degrees.
## Remarks
Sets the local rotation by converting the Euler angles to a quaternion. The angles represent rotation around the X, Y, and Z axes respectively.
## See Also
- [GetLocalEulerAngles](get-local-euler-angles)
- [SetLocalRotation](set-local-rotation)
## Examples
```cpp
void Example(TransformComponent* transform) {
transform->SetLocalEulerAngles(Math::Vector3(45.0f, 90.0f, 0.0f));
}
```

View File

@@ -0,0 +1,31 @@
# SetLocalPosition
Set the position of this transform relative to the parent transform.
## Syntax
```cpp
void SetLocalPosition(const Math::Vector3& position);
```
## Parameters
- `position` - The new local position as a `Math::Vector3`.
## Remarks
Sets the local position of this transform. If this transform has no parent, local position is the same as world position. This marks the transform as dirty, requiring world transform recalculation.
## See Also
- [GetLocalPosition](get-local-position)
- [GetPosition](get-position)
- [SetPosition](set-position)
## Examples
```cpp
void Example(TransformComponent* transform) {
transform->SetLocalPosition(Math::Vector3(10.0f, 0.0f, 5.0f));
}
```

View File

@@ -0,0 +1,32 @@
# SetLocalRotation
Set the rotation of this transform relative to the parent transform.
## Syntax
```cpp
void SetLocalRotation(const Math::Quaternion& rotation);
```
## Parameters
- `rotation` - The new local rotation as a `Math::Quaternion`.
## Remarks
Sets the local rotation of this transform. If this transform has no parent, local rotation is the same as world rotation. This marks the transform as dirty.
## See Also
- [GetLocalRotation](get-local-rotation)
- [GetRotation](get-rotation)
- [SetRotation](set-rotation)
## Examples
```cpp
void Example(TransformComponent* transform) {
Math::Quaternion rotation = Math::Quaternion::FromEuler(0.0f, 90.0f, 0.0f);
transform->SetLocalRotation(rotation);
}
```

View File

@@ -0,0 +1,30 @@
# SetLocalScale
Set the scale of this transform relative to the parent transform.
## Syntax
```cpp
void SetLocalScale(const Math::Vector3& scale);
```
## Parameters
- `scale` - The new local scale as a `Math::Vector3`.
## Remarks
Sets the local scale of this transform. If this transform has no parent, local scale is the same as world scale. This marks the transform as dirty.
## See Also
- [GetLocalScale](get-local-scale)
- [GetScale](get-scale)
## Examples
```cpp
void Example(TransformComponent* transform) {
transform->SetLocalScale(Math::Vector3(2.0f, 2.0f, 2.0f));
}
```

View File

@@ -0,0 +1,31 @@
# SetParent
Set the parent transform.
## Syntax
```cpp
void SetParent(TransformComponent* parent, bool worldPositionStays = true);
```
## Parameters
- `parent` - The new parent transform, or `nullptr` to detach from parent.
- `worldPositionStays` - If `true`, the world position remains unchanged after reparenting.
## Remarks
Sets the parent of this transform. When `worldPositionStays` is `true`, the world position is preserved, which may adjust the local position. When `false`, the local position is preserved, which may adjust the world position.
## See Also
- [GetParent](get-parent)
- [DetachChildren](detach-children)
## Examples
```cpp
void Example(TransformComponent* child, TransformComponent* newParent) {
child->SetParent(newParent, true);
}
```

View File

@@ -0,0 +1,31 @@
# SetPosition
Set the world position of this transform.
## Syntax
```cpp
void SetPosition(const Math::Vector3& position);
```
## Parameters
- `position` - The new world position as a `Math::Vector3`.
## Remarks
Sets the world-space position of this transform. If this transform has a parent, the local position is computed by transforming the world position into parent space.
## See Also
- [GetPosition](get-position)
- [GetLocalPosition](get-local-position)
- [SetLocalPosition](set-local-position)
## Examples
```cpp
void Example(TransformComponent* transform) {
transform->SetPosition(Math::Vector3(100.0f, 50.0f, 25.0f));
}
```

View File

@@ -0,0 +1,32 @@
# SetRotation
Set the world rotation of this transform.
## Syntax
```cpp
void SetRotation(const Math::Quaternion& rotation);
```
## Parameters
- `rotation` - The new world rotation as a `Math::Quaternion`.
## Remarks
Sets the world-space rotation of this transform. If this transform has a parent, the local rotation is computed by transforming the world rotation into parent space.
## See Also
- [GetRotation](get-rotation)
- [GetLocalRotation](get-local-rotation)
- [SetLocalRotation](set-local-rotation)
## Examples
```cpp
void Example(TransformComponent* transform) {
Math::Quaternion rot = Math::Quaternion::FromEuler(0.0f, 180.0f, 0.0f);
transform->SetRotation(rot);
}
```

View File

@@ -0,0 +1,31 @@
# SetScale
Set the world scale of this transform.
## Syntax
```cpp
void SetScale(const Math::Vector3& scale);
```
## Parameters
- `scale` - The new world scale as a `Math::Vector3`.
## Remarks
Sets the world-space scale of this transform. If this transform has a parent, the local scale is computed accordingly.
## See Also
- [GetScale](get-scale)
- [GetLocalScale](get-local-scale)
- [SetLocalScale](set-local-scale)
## Examples
```cpp
void Example(TransformComponent* transform) {
transform->SetScale(Math::Vector3(1.5f, 1.5f, 1.5f));
}
```

View File

@@ -0,0 +1,27 @@
# SetSiblingIndex
Set the sibling index of this transform.
## Syntax
```cpp
void SetSiblingIndex(int index);
```
## Parameters
- `index` - The new sibling index.
## See Also
- [GetSiblingIndex](get-sibling-index)
- [SetAsFirstSibling](set-as-first-sibling)
- [SetAsLastSibling](set-as-last-sibling)
## Examples
```cpp
void Example(TransformComponent* transform) {
transform->SetSiblingIndex(0);
}
```

View File

@@ -0,0 +1,126 @@
# TransformComponent
**命名空间**: `XCEngine::Components`
**类型**: `class`
**头文件**: `XCEngine/Components/TransformComponent.h`
**描述**: 游戏对象变换组件,管理位置、旋转、缩放和层级关系。
## 概述
TransformComponent 是 XCEngine ECS 系统中的变换组件,每个 GameObject 都拥有一个 TransformComponent。它管理对象的局部空间Local和世界空间World位置、旋转四元数和缩放支持父子层级变换、方向向量计算前后左右上下、矩阵运算和坐标变换。变换组件使用延迟更新机制只有在需要时才重新计算世界变换矩阵。
## 枚举
| 枚举值 | 描述 |
|--------|------|
| `Space::Self` | 相对于自身空间 |
| `Space::World` | 相对于世界空间 |
## 公共方法
### 局部空间
| 方法 | 描述 |
|------|------|
| [`GetLocalPosition`](get-local-position.md) | 获取局部位置 |
| [`SetLocalPosition`](set-local-position.md) | 设置局部位置 |
| [`GetLocalRotation`](get-local-rotation.md) | 获取局部旋转 |
| [`SetLocalRotation`](set-local-rotation.md) | 设置局部旋转 |
| [`GetLocalScale`](get-local-scale.md) | 获取局部缩放 |
| [`SetLocalScale`](set-local-scale.md) | 设置局部缩放 |
| [`GetLocalEulerAngles`](get-local-euler-angles.md) | 获取局部欧拉角 |
| [`SetLocalEulerAngles`](set-local-euler-angles.md) | 设置局部欧拉角 |
### 世界空间
| 方法 | 描述 |
|------|------|
| [`GetPosition`](get-position.md) | 获取世界位置 |
| [`SetPosition`](set-position.md) | 设置世界位置 |
| [`GetRotation`](get-rotation.md) | 获取世界旋转 |
| [`SetRotation`](set-rotation.md) | 设置世界旋转 |
| [`GetScale`](get-scale.md) | 获取世界缩放 |
| [`SetScale`](set-scale.md) | 设置世界缩放 |
### 方向向量
| 方法 | 描述 |
|------|------|
| [`GetForward`](get-forward.md) | 获取前方方向 |
| [`GetRight`](get-right.md) | 获取右方方向 |
| [`GetUp`](get-up.md) | 获取上方方向 |
### 矩阵运算
| 方法 | 描述 |
|------|------|
| [`GetLocalToWorldMatrix`](get-local-to-world-matrix.md) | 获取局部到世界矩阵 |
| [`GetWorldToLocalMatrix`](get-world-to-local-matrix.md) | 获取世界到局部矩阵 |
### 层级结构
| 方法 | 描述 |
|------|------|
| [`GetParent`](get-parent.md) | 获取父变换 |
| [`SetParent`](set-parent.md) | 设置父变换 |
| [`GetChildCount`](get-child-count.md) | 获取子对象数量 |
| [`GetChild`](get-child.md) | 获取指定索引的子变换 |
| [`Find`](find.md) | 按名称查找子变换 |
| [`DetachChildren`](detach-children.md) | 分离所有子变换 |
### 同级顺序
| 方法 | 描述 |
|------|------|
| [`GetSiblingIndex`](get-sibling-index.md) | 获取同级索引 |
| [`SetSiblingIndex`](set-sibling-index.md) | 设置同级索引 |
| [`SetAsFirstSibling`](set-as-first-sibling.md) | 设为第一个同级 |
| [`SetAsLastSibling`](set-as-last-sibling.md) | 设为最后一个同级 |
### 变换操作
| 方法 | 描述 |
|------|------|
| [`LookAt`](look-at.md) | 指向目标 |
| [`Rotate`](rotate.md) | 旋转 |
| [`Translate`](translate.md) | 平移 |
### 坐标变换
| 方法 | 描述 |
|------|------|
| [`TransformPoint`](transform-point.md) | 变换点坐标 |
| [`InverseTransformPoint`](inverse-transform-point.md) | 逆变换点坐标 |
| [`TransformDirection`](transform-direction.md) | 变换方向向量 |
| [`InverseTransformDirection`](inverse-transform-direction.md) | 逆变换方向向量 |
## 使用示例
```cpp
#include <XCEngine/Components/TransformComponent.h>
using namespace XCEngine::Components;
void TransformExample(TransformComponent* transform) {
transform->SetPosition(Vector3(10, 0, 0));
transform->SetRotation(Quaternion::FromEuler(0, 90, 0));
Vector3 forward = transform->GetForward();
Vector3 right = transform->GetRight();
transform->Translate(Vector3(0, 0, 5), Space::Self);
transform->Rotate(Vector3(0, 45, 0), Space::World);
Vector3 worldPos = transform->GetPosition();
Matrix4x4 l2w = transform->GetLocalToWorldMatrix();
}
```
## 相关文档
- [Components 模块总览](../components.md) - Components 模块总览
- [Component](component/component.md) - 组件基类
- [GameObject](game-object/game-object.md) - 游戏对象

View File

@@ -0,0 +1,35 @@
# TransformDirection
Transform a direction from local space to world space.
## Syntax
```cpp
Math::Vector3 TransformDirection(const Math::Vector3& direction) const;
```
## Parameters
- `direction` - The local space direction to transform.
## Returns
Returns the transformed direction in world space.
## Remarks
Transforms a direction from local space to world space. Unlike `TransformPoint`, this does not consider translation. Only rotation and scale are applied.
## See Also
- [InverseTransformDirection](inverse-transform-direction)
- [TransformPoint](transform-point)
## Examples
```cpp
void Example(TransformComponent* transform) {
Math::Vector3 localDir(1.0f, 0.0f, 0.0f);
Math::Vector3 worldDir = transform->TransformDirection(localDir);
}
```

View File

@@ -0,0 +1,35 @@
# TransformPoint
Transform a point from local space to world space.
## Syntax
```cpp
Math::Vector3 TransformPoint(const Math::Vector3& point) const;
```
## Parameters
- `point` - The local space point to transform.
## Returns
Returns the transformed point in world space.
## Remarks
Transforms a point from local space to world space using the transform's local-to-world matrix.
## See Also
- [InverseTransformPoint](inverse-transform-point)
- [TransformDirection](transform-direction)
## Examples
```cpp
void Example(TransformComponent* transform) {
Math::Vector3 localPoint(1.0f, 0.0f, 0.0f);
Math::Vector3 worldPoint = transform->TransformPoint(localPoint);
}
```

View File

@@ -0,0 +1,26 @@
# Translate
Move the transform by the specified translation.
## Syntax
```cpp
void Translate(const Math::Vector3& translation, Space relativeTo = Space::Self);
```
## Parameters
- `translation` - The translation vector.
- `relativeTo` - Whether the translation is relative to self or world space.
## Remarks
Moves the transform by the specified amount. When `relativeTo` is `Space::Self`, the translation is applied in local space. When `Space::World`, the translation is applied in world space.
## Examples
```cpp
void Example(TransformComponent* transform) {
transform->Translate(Math::Vector3(0.0f, 0.0f, 10.0f), Space::Self);
}
```