使用QT3D绘制字体
原创
©著作权归作者所有:来自51CTO博客作者wx64fa80747510b的原创作品,请联系作者获取转载授权,否则将追究法律责任
void BoardStatusDis::TextMeshAdd(const QVector3D &pos3d, const QString &text,float angle)
//创建QT3D字体对象
Qt3DExtras::QExtrudedTextMesh *textMesh = new Qt3DExtras::QExtrudedTextMesh();
QFont font("黑体",32,-1,false);
//3d字体都是有厚度的,一般绘制较薄使用
textMesh->setDepth(0.05f);
Qt3DCore::QTransform *cuboidTransform= new Qt3DCore::QTransform();
//3d字体材料,3d显示样式
Qt3DExtras::QPhongMaterial *cuboidMaterial = new Qt3DExtras::QPhongMaterial();
//照射到字体灯光,直观感受为字体正面显示颜色
cuboidMaterial->setDiffuse(Qt::black);
//设置字体大小
cuboidTransform->setScale(0.3f);
//设置字体3d坐标,显示的位置
cuboidTransform->setTranslation(pos3d);
//为了3d字体立体感,对字体进行翻转制定角度,y1.0f指绕y轴翻转angle角度
cuboidTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(0.0f, 1.0f, 0.0f), angle));
Qt3DCore::QEntity *m_cuboidEntity = new Qt3DCore::QEntity(_rootEntity);
//绑定3d字体对象,光效,位置翻转对象
m_cuboidEntity->addComponent(textMesh);
m_cuboidEntity->addComponent(cuboidMaterial);
m_cuboidEntity->addComponent(cuboidTransform);