【发布时间】:2016-12-28 06:05:21
【问题描述】:
我正在用 C++ 编写一个具有静态 RotationX() RotationY() 和 RotationZ() 方法的 Matrix 类。如果在乘以向量之前将矩阵相乘,我得到的结果与将矩阵单独乘以向量的结果不同。
这段代码
Vec4 result1 { 1, 1, 1, 1 };
result1 = Matrix::RotationX(ToRadians(-90)) * result1;
result1 = Matrix::RotationY(ToRadians(90)) * result1;
result1 = Matrix::RotationZ(ToRadians(90)) * result1;
// result1 => { -1, -1, -1, 1 }
给出与此代码不同的结果
Vec4 result2 { 1, 1, 1, 1 };
auto rotation = Matrix::RotationX(ToRadians(-90)) *
Matrix::RotationY(ToRadians(90)) *
Matrix::RotationZ(ToRadians(90));
result2 = rotation * result2;
// result2 => { 1, 1, -1, 1 }
这里有什么问题?我可以提供我的旋转函数实现,但我想在发布代码之前确保这不是仿射变换的概念问题。
【问题讨论】:
标签: c++ math matrix affinetransform