2
我正在嘗試使用Qt 3D繪製3D水平條形圖。我試圖通過繪製具有相同x,y和旋轉的連續長方體並將它們轉換爲不同深度來實現此目的。但它似乎只改變深度不起作用,因爲x和y都在變化,我無法弄清楚。Qt:3D水平條形圖
更新:
我發現x和y的屬性也應由特定值被改變。我硬編碼它,它工作正常,但我無法找出一個方程來自動做這個不同的尺寸。
代碼:
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);
}
非常感謝,它工作正常。 –