Files
XCEngine/docs/api/components/transform-component/get-position.md

35 lines
941 B
Markdown
Raw Normal View History

# TransformComponent::GetPosition
获取变换的世界空间位置。
```cpp
Math::Vector3 GetPosition() const;
```
返回变换的世界空间位置。如果变换有父对象,世界位置由局部位置与父对象世界位置组合计算得出。
**返回:** `Math::Vector3` - 世界空间位置向量
**线程安全:** ✅ (只读操作)
**示例:**
```cpp
#include <XCEngine/Components/TransformComponent.h>
using namespace XCEngine::Components;
void Example(TransformComponent* transform) {
Math::Vector3 worldPos = transform->GetPosition();
printf("World position: (%f, %f, %f)\n",
worldPos.x, worldPos.y, worldPos.z);
}
```
## 相关文档
- [TransformComponent 总览](transform-component.md) - 返回类总览
- [GetLocalPosition](get-local-position.md) - 获取局部位置
- [SetPosition](set-position.md) - 设置世界位置
- [SetLocalPosition](set-local-position.md) - 设置局部位置