对 Eigen::Affine3f 应用旋转
Apply rotation to Eigen::Affine3f
我正在使用 Eigen::Affine3f
来表示相机矩阵。 (我已经弄清楚如何从初始 "lookAt" 和 "up" 向量设置视图矩阵/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!!
我正在使用 Eigen::Affine3f
来表示相机矩阵。 (我已经弄清楚如何从初始 "lookAt" 和 "up" 向量设置视图矩阵/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!!