我正在尝试在Qt C++中导入6个机器人操纵器手臂关节的3D网格。关节正在显示,但它们没有旋转,就好像它们连接在一起一样。但是每个关节都围绕自己的中心独立旋转。我想通过c++代码旋转每个关节,其他关节也应该旋转。我正在使用Blender设置网格的中心并导出到obj文件。
Qt3DCore::QEntity *root = new Qt3DCore::QEntity();
Qt3DExtras::Qt3DWindow view;
Joint *joint1 = new Joint(root);
joint1->mesh()->setSource(QUrl(QStringLiteral("qrc:/assets/base.obj")));
joint1->transform()->setTranslation(QVector3D(0.0f, 1.81f, 0.0f));
joint1->transform()->setScale(0.01f);
Qt3DExtras::QPhongMaterial *material1 = new Qt3DExtras::QPhongMaterial();
material1->setDiffuse(QColor(204, 91, 70));
material1->setSpecular(QColor(255, 171, 247 ));
material1->setShininess(500.0f);
joint1->addComponent(material1);
Joint *joint2 = new Joint(root);
joint2->mesh()->setSource(QUrl(QStringLiteral("qrc:/assets/j2.obj")));
joint2->transform()->setTranslation(QVector3D(0.0f, 1.9030f, 0.0f));
joint2->transform()->setScale(0.01f);
Qt3DExtras::QPhongMaterial *material2 = new Qt3DExtras::QPhongMaterial();
material2->setDiffuse(QColor(27, 176, 204));
material2->setSpecular(QColor(37, 95, 255 ));
material2->setShininess(500.0f);
joint2->addComponent(material2);
/*
* Rest of the 4 joint meshes are defined in same way as above
*/
view.setRootEntity(root);
我的联合类如下:
关节
#include "joint.h"
Joint::Joint(Qt3DCore::QNode *parent)
: Qt3DCore::QEntity(parent)
,m_mesh(new Qt3DRender::QMesh())
,m_transform(new Qt3DCore::QTransform())
{
addComponent(m_mesh);
addComponent(m_transform);
}
Joint::~Joint()
{
}
Qt3DRender::QMesh *Joint::mesh() const
{
return m_mesh;
}
Qt3DCore::QTransform *Joint::transform() const
{
return m_transform;
}
我的联合头文件:
关节
#ifndef JOINT_H
#define JOINT_H
#include <Qt3DCore/QEntity>
#include <Qt3DCore/QTransform>
#include <Qt3DRender/QMesh>
class Joint : public Qt3DCore::QEntity
{
public:
Joint(Qt3DCore::QNode *parent= 0);
~Joint();
Qt3DRender::QMesh *mesh() const;
Qt3DCore::QTransform *transform() const;
private:
Qt3DRender::QMesh *m_mesh;
Qt3DCore::QTransform *m_transform;
};
#endif //JOINT_H
最佳答案
如果关节具有“父子”层次结构,则应将每个父节点表示为Joint *joint2 = new Joint(joint1);
。
这样,当您旋转 parent 时, child 也会旋转。但这不是对等的(它在Blender中充当 parent ):旋转或平移 child 不会影响其任何 parent 。
关于c++ - 导入机器人机械手(6轴)的连接零件,并通过用户输入使每个关节旋转(C++代码),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50986339/