Qt:3D水平条形图 [英] Qt: 3D Horizontal Bar Chart

查看:354
本文介绍了Qt:3D水平条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用



代码:

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

//绿色长方体
//长方体形状数据
长方体=新的Qt3DExtras :: QCuboidMesh();
cuboid-> setXExtent(8);
cuboid-> setYExtent(2);
cuboid-> setZExtent(4);
// CuboidMesh转换
Qt3DCore :: QTransform * cuboidTransform = new Qt3DCore :: QTransform();
cuboidTransform-> setRotation(QQuaternion :: fromAxisAndAngle(QVector3D(0.1f,-0.1f,0.0f),45.0f));

Qt3DExtras :: QPhongMaterial * cuboidMaterial =新的Qt3DExtras :: QPhongMaterial();
cuboidMaterial-> setDiffuse(QColor(QRgb(0x66423)));
cuboidMaterial-> setAmbient(QColor(QRgb(0x35423)));
//长方体
m_cuboidEntity =新的Qt3DCore :: QEntity(m_rootEntity);
m_cuboidEntity-> addComponent(cuboid);
m_cuboidEntity-> addComponent(cuboidMaterial);
m_cuboidEntity-> addComponent(cuboidTransform);

//红色长方体形状数据
cuboid2 =新的Qt3DExtras :: QCuboidMesh();
cuboid2-> setXExtent(8);
cuboid2-> setYExtent(2);
cuboid2-> setZExtent(2);

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

/ *需要一个方程来计算转换值* /
cuboidTransform2-> setTranslation(QVector3D(6 * qAsin(45.0 / 180),6 * qAsin(45.0 / 180) ,-2.1f));

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

//长方体
m_cuboidEntity2 =新的Qt3DCore :: QEntity(m_rootEntity);
m_cuboidEntity2-> addComponent(cuboid2);
m_cuboidEntity2-> addComponent(cuboidMaterial2);
m_cuboidEntity2-> addComponent(cuboidTransform2);
}


解决方案

我认为您的问题是平移发生在旋转之后 。您可能想要的不是在每个长方体上分别设置转换,而是在其父级上设置转换。因此,请勿旋转任何一个长方体;只需平移它们,就像直接从上方查看一样。但是然后将旋转变换添加到 m_rootEntity


I am trying to draw a 3D horizontal bar chart using Qt 3D.I am trying to achieve this by drawing consecutive cuboids having the same x , y and rotation and translating them to different depths.But it seemed that changing the depth only is not working as both x and y are also changing and I can't figure it out.

Update:

I found out that the x and y attributes should also be changed by specific values. I hard-coded it and it works fine but I can't figure out an equation to do this automatic with varying dimensions.

The code:

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);
}

解决方案

I think the problem you are having is that the translation happens after the rotation. Probably what you want is instead of setting the transform on each cuboid individually, you set the transform on their parent. So don't rotate either cuboid; just translate them normally as if you are viewing directly from above. But then add a rotation transform to m_rootEntity.

这篇关于Qt:3D水平条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆