如何在QML场景中绘制3D线条?

4
我尝试将Bullet Physics的调试绘图界面集成到QML中,因此必须实现一个drawLine()方法。
void drawLine(const btVector3 &from, const btVector3 &to, const btVector3 &color);

我尝试继承一个在场景中使用的项目,它同时从QQuickItem3D和btIDebugDraw继承。在drawLine()中,我将线条添加到成员向量中。在Qt的 drawItem() 中,我遍历线条并使用OpenGL调用来渲染它们。但是它们没有出现在屏幕上。

如何在三维空间中绘制这些线条,并从正确的相机视角进行查看?

void DebugDrawer::drawItem(QGLPainter *painter)
{
    if (lines_.size() < 1)
        return;

    // Draw current lines
    painter->modelViewMatrix().push();
    glBegin(GL_LINES);
    for (auto &line : lines_) {
        glColor3f(line.color.getX(), line.color.getY(), line.color.getZ());
        glVertex3f(line.from.getX(), line.from.getY(), line.from.getZ());
        glVertex3f(line.to.getX(), line.to.getY(), line.to.getZ());
    }
    glEnd();
    painter->modelViewMatrix().pop();

    // Reset buffer
    lines_.clear();
}

modelViewMatrix是投影矩阵乘以视图矩阵吗?除此之外,你的代码看起来很好。 - Rebirth
另外,我猜您是在drawLine函数中调用了setDebugMode(btIDebugDraw::DBG_DrawWireframe)之后推入了一个新行? - Rebirth
最后一件事,必须在你的主绘制函数中调用btDiscreteDynamicsWorld->debugDrawWorld();。你的问题没有提及lines_是否被填充,但这些应该是你所需要的全部内容,尤其是你正在使用传统的GL。 - Rebirth
1个回答

1
我最终使用了QtQuick的线条类,并在Bullet的flushLines()方法中使用setVertices()设置其顶点。

你能详细说明一下吗?你最终是否成功从C++中创建了QtQuick行?这是如何完成的? - jco
@jco 好久不见,不幸的是我已经不记得了。 - danijar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接