将旋转应用于Eigen :: Affine3f

时间:2016-01-20 08:46:59

标签: c++ matrix eigen

我正在使用Eigen::Affine3f来表示相机矩阵。 (我已经想出如何从最初的“lookAt”和“up”向量设置视图矩阵/ Affine3f

现在,我想支持更改相机的方向。简单的问题:对这个Affine3f应用旋转的最佳方法是什么,即俯仰,偏航,滚动?

1 个答案:

答案 0 :(得分:2)

使用内置功能非常简单。您可以使用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!!