参考文章 Unity3D中的Quaternion(四元数)点击打开链接
UE4中找了好久终于发现相关函数:翻译来自有道 哈哈
/*
* Convert a vector of floating-point Euler angles (in degrees) into a Quaternion. 将浮点欧拉角的一个矢量转换成四元数。
* @param Euler the Euler angles 对欧拉角进行分析
* @return constructed FQuat 返回构造FQuat
*/
static CORE_API FQuatMakeFromEuler(const FVector&Euler);
使用:
FVector vec = FVector(0,0,45);
FQuat quat = FQuat::MakeFromEuler(vec);
/**
* Return the Quaternion orientation corresponding to the direction in which the vector points.
返回与矢量点方向对应的四元数方向。
* Similar to the FRotator version, returns a result without roll such that it preserves the up vector.
类似于FRotator版本,返回一个没有滚动的结果,这样它就保留了向上的向量。
* @note If you don't care about preserving the up vector and just want the most direct rotation, you can use the faster
* 'FQuat::FindBetweenVectors(FVector::ForwardVector, YourVector)' or 'FQuat::FindBetweenNormals(...)' if you know the vector is of unit length.
注意,如果你不关心保持向上的向量,只需要最直接的旋转,你就可以用得更快
“FQuat::FindBetweenVectors(FVector::ForwardVector YourVector)”或“FQuat:FindBetweenNormals(…)如果你知道向量的单位长度。
* @return Quaternion from the Vector's direction, without any roll.
@return Quaternion从矢量方向,没有任何滚动。
* @see ToOrientationRotator(), FQuat::FindBetweenVectors()
*/
CORE_API FQuat ToOrientationQuat() const;
使用:
FVector v(0, 0, 40);
auto q = v.ToOrientationQuat();