c++ - Qt:3D水平条形图

标签 c++ qt 3d bar-chart qt3d

我正在尝试使用 Qt 3D 绘制 3D 水平条形图.我试图通过绘制具有相同 x 、 y 和旋转的连续长方体并将它们转换到不同的深度来实现这一点。但似乎只改变深度是行不通的,因为 x 和 y 也在改变,我不能弄清楚。

更新:

我发现 x 和 y 属性也应该由特定值更改。我对其进行了硬编码并且它工作正常,但我无法找出一个方程式来自动执行不同维度的操作。

enter image description here

代码:

SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity)
    : m_rootEntity(rootEntity)
{

    // Green cuboid
    //Cuboid shape data
    cuboid = new Qt3DExtras::QCuboidMesh();
    cuboid->setXExtent(8);
    cuboid->setYExtent(2);
    cuboid->setZExtent(4);
    // CuboidMesh Transform
    Qt3DCore::QTransform *cuboidTransform = new Qt3DCore::QTransform();
    cuboidTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(0.1f, -0.1f, 0.0f), 45.0f));

    Qt3DExtras::QPhongMaterial *cuboidMaterial = new Qt3DExtras::QPhongMaterial();
    cuboidMaterial->setDiffuse(QColor(QRgb(0x66423)));
    cuboidMaterial->setAmbient(QColor(QRgb(0x35423)));
    //Cuboid
    m_cuboidEntity = new Qt3DCore::QEntity(m_rootEntity);
    m_cuboidEntity->addComponent(cuboid);
    m_cuboidEntity->addComponent(cuboidMaterial);
    m_cuboidEntity->addComponent(cuboidTransform);

    // Red Cuboid shape data
     cuboid2 = new Qt3DExtras::QCuboidMesh();
     cuboid2->setXExtent(8);
     cuboid2->setYExtent(2);
     cuboid2->setZExtent(2);

     // CuboidMesh Transform
     cuboidTransform2 = new Qt3DCore::QTransform();
     cuboidTransform2->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(0.1f, -0.1f, 0.0f), 45.0f));

     /*An equation is needed to calculate the translation values*/
     cuboidTransform2->setTranslation(QVector3D(6*qAsin(45.0/180), 6*qAsin(45.0/180),-2.1f));

     Qt3DExtras::QPhongMaterial *cuboidMaterial2 = new Qt3DExtras::QPhongMaterial();
     cuboidMaterial2->setDiffuse(QColor(QRgb(0xff0000)));

     //Cuboid
     m_cuboidEntity2 = new Qt3DCore::QEntity(m_rootEntity);
     m_cuboidEntity2->addComponent(cuboid2);
     m_cuboidEntity2->addComponent(cuboidMaterial2);
     m_cuboidEntity2->addComponent(cuboidTransform2);
}

最佳答案

我认为您遇到的问题是翻译发生在旋转之后。可能您想要的不是在每个长方体上单独设置变换,而是在它们的父级上设置变换。所以不要旋转任何一个长方体;只需正常翻译它们,就像您直接从上方查看一样。然后向 m_rootEntity 添加一个旋转变换。

关于c++ - Qt:3D水平条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37799092/

相关文章:

c++ - SQLite如何限制记录数

qt - QML 中的垂直文本方向

c++ - qt中的图像 Gamma 校正

python - 如何在 matplotlib 中对条形图制作 3d 效果?

java - 边界球碰撞不起作用

python - 如何在 python/plotly 中制作 2D 向量分布的 3D 直方图

c++ - 播放音乐时如何避免微延迟?

c++ Eigen制作拷贝?

c++ - GTK 主题引擎 : where to start?

c++ - 在 Arduino 错误上将 4 个字节转换为长字节