如何将QMatrix4x4应用于QT中的QTorusMesh等Mesh对象?

时间:2016-04-06 06:19:05

标签: qt opengl rotation mesh

我有像

这样的对象的4x4变换矩阵

0.866,0,0.5,0,
-0.5,0,0.866,0,
 0,-1,0,0,
 0,0,0,0

或类似矩阵(Qt Transform matrix

如何将4x4矩阵应用于此构造:

Qt3D::QScaleTransform *torusScale = new Qt3D::QScaleTransform();
Qt3D::QTranslateTransform *torusTranslation = new Qt3D::QTranslateTransform();
Qt3D::QRotateTransform *torusRotation = new Qt3D::QRotateTransform();
Qt3D::QTransform *torusTransforms = new Qt3D::QTransform();

torusScale->setScale3D(QVector3D(2.0f, 2.0f, 2.0f));
torusTranslation->setTranslation(QVector3D(1.7f, 1.7f, 0.0f));
torusRotation->setAngleDeg(25.0f);
torusRotation->setAxis(QVector3D(0, 1, 0));

torusTransforms->addTransform(torusRotation);
torusTransforms->addTransform(torusTranslation);
torusTransforms->addTransform(torusScale);

1 个答案:

答案 0 :(得分:0)

您需要创建Qt3DCore::QEntity,将QTorusMesh添加为组件,并添加torusTransformsQt3DCore::QTransform)作为QEntity的组成部分:

torusEntity = new Qt3DCore::QEntity(root_entity);
torusEntity->addComponent(torusMesh);
torusEntity->addComponent(torusMaterial);
torusEntity->addComponent(torusTransforms);

现在关于QMatrix4x4,您可以通过调用setMatrix SLOT来实例化Qt3DCore :: QTransform并设置其内部矩阵,该SLOT接收QMatrix4x4:

torusTransforms->setMatrix(my_matrix);

有关Qt文档中的运行示例,请查看:https://doc.qt.io/qt-5/qt3d-basicshapes-cpp-example.html,更具体地说是场景修改器实现。