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:
26
docs/api/components/transform-component/detach-children.md
Normal file
26
docs/api/components/transform-component/detach-children.md
Normal 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();
|
||||
}
|
||||
```
|
||||
33
docs/api/components/transform-component/find.md
Normal file
33
docs/api/components/transform-component/find.md
Normal 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());
|
||||
}
|
||||
}
|
||||
```
|
||||
27
docs/api/components/transform-component/get-child-count.md
Normal file
27
docs/api/components/transform-component/get-child-count.md
Normal 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);
|
||||
}
|
||||
```
|
||||
32
docs/api/components/transform-component/get-child.md
Normal file
32
docs/api/components/transform-component/get-child.md
Normal 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());
|
||||
}
|
||||
}
|
||||
```
|
||||
31
docs/api/components/transform-component/get-forward.md
Normal file
31
docs/api/components/transform-component/get-forward.md
Normal 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);
|
||||
}
|
||||
```
|
||||
@@ -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);
|
||||
}
|
||||
```
|
||||
@@ -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);
|
||||
}
|
||||
```
|
||||
@@ -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);
|
||||
}
|
||||
```
|
||||
31
docs/api/components/transform-component/get-local-scale.md
Normal file
31
docs/api/components/transform-component/get-local-scale.md
Normal 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);
|
||||
}
|
||||
```
|
||||
@@ -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();
|
||||
}
|
||||
```
|
||||
32
docs/api/components/transform-component/get-parent.md
Normal file
32
docs/api/components/transform-component/get-parent.md
Normal 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());
|
||||
}
|
||||
}
|
||||
```
|
||||
33
docs/api/components/transform-component/get-position.md
Normal file
33
docs/api/components/transform-component/get-position.md
Normal 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);
|
||||
}
|
||||
```
|
||||
30
docs/api/components/transform-component/get-right.md
Normal file
30
docs/api/components/transform-component/get-right.md
Normal 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();
|
||||
}
|
||||
```
|
||||
31
docs/api/components/transform-component/get-rotation.md
Normal file
31
docs/api/components/transform-component/get-rotation.md
Normal 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();
|
||||
}
|
||||
```
|
||||
31
docs/api/components/transform-component/get-scale.md
Normal file
31
docs/api/components/transform-component/get-scale.md
Normal 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);
|
||||
}
|
||||
```
|
||||
28
docs/api/components/transform-component/get-sibling-index.md
Normal file
28
docs/api/components/transform-component/get-sibling-index.md
Normal 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);
|
||||
}
|
||||
```
|
||||
30
docs/api/components/transform-component/get-up.md
Normal file
30
docs/api/components/transform-component/get-up.md
Normal 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();
|
||||
}
|
||||
```
|
||||
@@ -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();
|
||||
}
|
||||
```
|
||||
@@ -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);
|
||||
}
|
||||
```
|
||||
@@ -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);
|
||||
}
|
||||
```
|
||||
28
docs/api/components/transform-component/look-at.md
Normal file
28
docs/api/components/transform-component/look-at.md
Normal 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);
|
||||
}
|
||||
```
|
||||
29
docs/api/components/transform-component/rotate.md
Normal file
29
docs/api/components/transform-component/rotate.md
Normal 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);
|
||||
}
|
||||
```
|
||||
@@ -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();
|
||||
}
|
||||
```
|
||||
@@ -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();
|
||||
}
|
||||
```
|
||||
@@ -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));
|
||||
}
|
||||
```
|
||||
@@ -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));
|
||||
}
|
||||
```
|
||||
@@ -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);
|
||||
}
|
||||
```
|
||||
30
docs/api/components/transform-component/set-local-scale.md
Normal file
30
docs/api/components/transform-component/set-local-scale.md
Normal 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));
|
||||
}
|
||||
```
|
||||
31
docs/api/components/transform-component/set-parent.md
Normal file
31
docs/api/components/transform-component/set-parent.md
Normal 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);
|
||||
}
|
||||
```
|
||||
31
docs/api/components/transform-component/set-position.md
Normal file
31
docs/api/components/transform-component/set-position.md
Normal 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));
|
||||
}
|
||||
```
|
||||
32
docs/api/components/transform-component/set-rotation.md
Normal file
32
docs/api/components/transform-component/set-rotation.md
Normal 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);
|
||||
}
|
||||
```
|
||||
31
docs/api/components/transform-component/set-scale.md
Normal file
31
docs/api/components/transform-component/set-scale.md
Normal 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));
|
||||
}
|
||||
```
|
||||
27
docs/api/components/transform-component/set-sibling-index.md
Normal file
27
docs/api/components/transform-component/set-sibling-index.md
Normal 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);
|
||||
}
|
||||
```
|
||||
126
docs/api/components/transform-component/transform-component.md
Normal file
126
docs/api/components/transform-component/transform-component.md
Normal 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) - 游戏对象
|
||||
@@ -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);
|
||||
}
|
||||
```
|
||||
35
docs/api/components/transform-component/transform-point.md
Normal file
35
docs/api/components/transform-component/transform-point.md
Normal 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);
|
||||
}
|
||||
```
|
||||
26
docs/api/components/transform-component/translate.md
Normal file
26
docs/api/components/transform-component/translate.md
Normal 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);
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user