引擎-关于旋转矩阵计算的一些数学杂谈

内容目录

在自研引擎中,我添加了旋转矩阵,原理有点多正在写。

[nodiscard]] inline constexpr Matrix Rotate(const Vector3<T>& Axis, const float Degrees) requires (M == 4 && N == 4 && CArithmetic<T>)
{
    const float Radians = Degrees * (PI / 180.0f);
    Matrix Result = *this;
    Result[0][0] = std::cos(Radians) + (1 - std::cos(Radians)) * Axis.X * Axis.X;
    Result[0][1] = (1 - std::cos(Radians)) * Axis.X * Axis.Y - std::sin(Radians) * Axis.Z;
    Result[0][2] = (1 - std::cos(Radians)) * Axis.X * Axis.Z + std::sin(Radians) * Axis.Y;
    Result[1][0] = (1 - std::cos(Radians)) * Axis.X * Axis.Y + std::sin(Radians) * Axis.Z;
    Result[1][1] = std::cos(Radians) + (1 - std::cos(Radians)) * Axis.Y * Axis.Y;
    Result[1][2] = (1 - std::cos(Radians)) * Axis.Y * Axis.Z - std::sin(Radians) * Axis.X;
    Result[2][0] = (1 - std::cos(Radians)) * Axis.X * Axis.Z - std::sin(Radians) * Axis.Y;
    Result[2][1] = (1 - std::cos(Radians)) * Axis.Y * Axis.Z - std::sin(Radians) * Axis.X;
    Result[2][2] = std::cos(Radians) + (1 - std::cos(Radians)) * Axis.Z * Axis.Z;
    return Result;
}
同步Sch