【发布时间】:2019-12-24 17:59:05
【问题描述】:
我不确定如何在 Qt 中渲染圆锥。 Qt 中已经有一个 QConeMesh,我正在关注这个文档,但没有渲染任何内容。我对 Qt 很陌生,所以我可能犯了一些愚蠢的错误,但是仔细看,我不知道在哪里我错了。它确实渲染了其他东西,比如线条,所以我很确定问题出在这里。
这是我的代码:
#include "Boid.h"
#include <qdebug.h>
Boid::Boid(QNode *parent)
: QEntity(parent),
m_Position(0, 0, 0),
m_MovementVector(rand() % 2 - 1, rand() % 2 - 1, rand() % 2 - 1),
m_BoidColor(15, 100, 100)
{
Qt3DExtras::QConeMesh *boidCone = new Qt3DExtras::QConeMesh();
boidCone->setBottomRadius(0.5f);
boidCone->setTopRadius(0.01f);
boidCone->setHasTopEndcap(true);
boidCone->setHasBottomEndcap(true);
boidCone->setSlices(100);
boidCone->setLength(1);
boidCone->setRings(100);
Qt3DCore::QTransform *boidTransform = new Qt3DCore::QTransform();
boidTransform->setScale(1);
boidTransform->setTranslation(m_Position);
boidTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(0.0f, 1.0f, 0.0f), 25.0f));
Qt3DRender::QMaterial *boidMaterial = new Qt3DRender::QMaterial();
boidMaterial->setEnabled(true);
qDebug() << "test " << parent;
Qt3DCore::QEntity *boidEntity = new Qt3DCore::QEntity(parent);
boidEntity->addComponent(boidCone);
boidEntity->addComponent(boidTransform);
boidEntity->addComponent(boidMaterial);
}
调试将打印出测试和正确的父对象。 这是我正在关注的文档,我认为它有点过时了 https://doc.qt.io/archives/qt-5.6/qt3d-basicshapes-cpp-example.html
【问题讨论】: