我正在使用 Eigen::Affine3f
来表示相机矩阵。 (我已经弄清楚如何从初始“lookAt”和“up” vector 设置 View 矩阵/Affine3f
)
现在,我想支持更改相机的方向。简单的问题:将旋转应用于此 Affine3f
的最佳方式是什么,即俯仰、偏航、滚动?
最佳答案
使用内置功能非常简单。您可以使用 AxisAngle
对象乘以现有的 Affine3f
。请注意,轴需要归一化:
Vector3f rotationAxis;
rotationAxis.setRandom(); // I don't really care, you determine the axis
rotationAxis.normalize(); // This is important, don't forget it
Affine3f randomAffine3f, rotatedAffine;
// Whatever was left in memory in my case,
// whatever your transformation is in yours
std::cout << randomAffine3f.matrix() << std::endl;
// We'll now apply a rotation of 0.256*M_PI around the rotationAxis
rotatedAffine = (AngleAxisf(0.256*M_PI, rotationAxis) * randomAffine3f);
std::cout << rotatedAffine.matrix() << std::endl; // Ta dum!!
关于c++ - 对 Eigen::Affine3f 应用旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34895284/