Files
XCEngine/docs/api/math/vector3/vector3.md
ssdfasd 0f0ab8922a docs: fix naming conventions across threading, math, memory, core, and debug modules
threading/:
- Rename 19 camelCase method files to hyphenated names
- task-system: createtaskgroup→create-task-group, etc.
- tasksystemconfig: enabletaskprofiling→enable-task-profiling, etc.
- thread: getcurrentid→get-current-id, etc.
- task: addref→add-ref, getid→get-id, etc.

math/:
- Rename underscore operator files to hyphenated
- vector3: operator_add→operator-add, etc.
- matrix4: gettranslation→get-translation, etc.
- vector4: tovector3→to-vector3, constructor_vector3→constructor-vector3
- sphere: sphere_constructor→sphere-constructor, etc.

memory/:
- Remove duplicate memorymanager/ folder (kept manager/ which was correct)

core/:
- filewriter: Consolidate ctor-default.md and ctor-file.md into constructor.md
- Rename dtor.md→destructor.md

debug/:
- filelogsink: Rename construct.md→constructor.md, ~filelogsink.md→destructor.md

All overview pages updated with new file references.
2026-03-22 23:09:29 +08:00

3.3 KiB

Vector3

命名空间: XCEngine::Math

类型: struct

头文件: XCEngine/Math/Vector3.h

描述: 三维向量,用于 3D 图形和游戏开发中的位置、方向和缩放计算

概述

Vector3 是 XCEngine 中用于表示三维向量的核心类型,支持常见的向量运算。它广泛用于 3D 图形编程中的位置、方向、速度、缩放等计算场景。

结构体成员

成员 类型 描述 默认值
x float X 分量 0.0f
y float Y 分量 0.0f
z float Z 分量 0.0f

公共方法

方法 描述
Zero 返回零向量 (0, 0, 0)
One 返回单位向量 (1, 1, 1)
Forward 返回前向向量 (0, 0, 1)
Back 返回后向向量 (0, 0, -1)
Up 返回上向量 (0, 1, 0)
Down 返回下向量 (0, -1, 0)
Right 返回右向量 (1, 0, 0)
Left 返回左向量 (-1, 0, 0)
Dot 计算点积
Cross 计算叉积
Normalize 返回归一化向量
Magnitude 计算向量长度
SqrMagnitude 计算向量长度的平方
Lerp 线性插值
MoveTowards 移向目标点
Project 投影到法向量上
ProjectOnPlane 投影到平面上
Angle 计算两个向量之间的夹角
Reflect 反射向量
Normalized 返回归一化副本(实例方法)

运算符

运算符 描述
+, - 向量加减
*, / 向量与标量或分量相乘/相除
+=, -= 复合赋值运算符
*=, /= 复合赋值运算符
[] 下标访问 x, y, z 分量
==, != 相等性比较
* (Quaternion) 用四元数旋转向量

实例方法

方法 描述
Magnitude() 计算向量长度
SqrMagnitude() 计算向量长度的平方
Normalized() 返回归一化副本

使用示例

#include "XCEngine/Math/Vector3.h"
#include <iostream>

using namespace XCEngine::Math;

int main() {
    Vector3 position(1.0f, 2.0f, 3.0f);
    Vector3 direction = Vector3::Forward();
    
    float dot = Vector3::Dot(position, direction);
    Vector3 cross = Vector3::Cross(position, direction);
    Vector3 normalized = position.Normalized();
    
    std::cout << "Position: (" << position.x << ", " << position.y << ", " << position.z << ")\n";
    std::cout << "Dot product: " << dot << "\n";
    std::cout << "Normalized: (" << normalized.x << ", " << normalized.y << ", " << normalized.z << ")\n";
    
    return 0;
}

相关文档