【问题标题】:rendering a cone in Qt在 Qt 中渲染一个圆锥
【发布时间】: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

【问题讨论】:

    标签: c++ qt


    【解决方案1】:

    没关系,想通了..必须使用QPhongMaterial,但在新版本中它已移至Qt3DExtras。

    即在QEntity中加入一个Qt3DExtras::QPhongMaterial

    【讨论】:

    • 当您回答自己的问题时,最好的做法是 1) 接受它,2) 写下您为解决问题所做的工作的解释,以便发现该问题的人会能够做同样的事情。这是一个很好的例子:stackoverflow.com/questions/59090834/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-10
    • 2021-12-20
    • 1970-01-01
    • 2014-01-15
    • 1970-01-01
    • 2019-11-10
    • 2012-03-17
    相关资源
    最近更新 更多