问题描述
Ciao,最近我已经开始使用qt3d来实现设计工具。 即使我有两个烦人的错误,清单上几乎所有的功能都已实现。 在这两个之中,有一个使我真的很沮丧。 我需要做的是使用旋转矢量(xangle,yangle,zangle)旋转网格,然后将网格平移回特定位置。 在我旋转一个角度然后向后平移之前,一切工作都很好,但是例如当我要以x和y角度旋转时,网格无法正确地平移回所需的位置。 这里是简单的代码片段:
void
RotationHelper::rotateAndTranslateBack(PickableEntity* entity,const QVector3D& rotation,const QVector3D& backTranslation)
{
auto transform = EntityHelper::getTransformComponent(entity);
/*
transform->setRotationX(transform->rotationX() + rotation.x());
transform->setRotationY(transform->rotationY() + rotation.y());
transform->setRotationZ(transform->rotationZ() + rotation.z());
*/
auto rotationMatrix = transform->worldMatrix();
rotationMatrix.rotate(QQuaternion::fromAxisAndAngle(QVector3D(1,0),rotation.x()));
rotationMatrix.rotate(QQuaternion::fromAxisAndAngle(QVector3D(0,1,rotation.y()));
rotationMatrix.rotate(QQuaternion::fromAxisAndAngle(QVector3D(0,1),rotation.z()));
transform->setMatrix(rotationMatrix);
const auto finalTranslation = (transform->translation() + backTranslation);
transform->setTranslation(finalTranslation);
}
非常感谢您的帮助。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)