c++ - 如何在 QML 场景上绘制 3D 线?

标签 c++ qt opengl qml qtquick3d

我试图将 Bullet Physics 的调试绘图接口(interface)集成到 QML 中,所以我必须实现一个 drawLine() 方法。

void drawLine(const btVector3 &from, const btVector3 &to, const btVector3 &color);

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

如何在 3D 空间和正确的相机 View 中绘制线条?

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

最佳答案

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

关于c++ - 如何在 QML 场景上绘制 3D 线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28253660/

相关文章:

c++ - 是否可以让两个 C++ 程序访问同一内存位置

c++ - 不按特定顺序跳过多个循环(C++)

c++ - 与 Qthreads 链接错误

c++ - QThread.wait()函数有什么用?

opengl - 无法使用多重采样渲染到纹理

c++ - 无法为 Oculus Rift 创建 OpenGL 交换纹理

c++ - 使用阴影贴图将 OpenGL 场景渲染为黑色

c++ - 将二进制对象读/写为十六进制?

c++ - 变量没有产生正确的数据

qt - 错误 : couldn't get appropriate GL format for Qt windows