4

I try to integrate Bullet Physics' debug drawing interface into QML, so I have to implement a drawLine() method.

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

What I tried is that I inherited an item, that is used in the scene, from both QQuickItem3D and btIDebugDraw. In drawLine(), I add the lines to a member vector. In Qt's drawItem(), I iterate over the lines and use OpenGL calls to render them. However, they do not appear on screen.

How can I draw the lines in 3D space and from the correct camera 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();
}
danijar
  • 32,406
  • 45
  • 166
  • 297
  • Is modelViewMatrix the Projection * View matrix? Other than that your code looks fine. – Rebirth Feb 02 '15 at 05:15
  • Also, I take it you are pushing a new line in the drawLine function inherited from btIDebugDraw and before that you've called: `setDebugMode(btIDebugDraw::DBG_DrawWireframe)`? – Rebirth Feb 02 '15 at 05:26
  • One last thing, btDiscreteDynamicsWorld->debugDrawWorld(); has to be called in your main draw function. Your question omits whether or not lines_ is being populated, but these things are all you should need, especially as you are using legacy GL. – Rebirth Feb 02 '15 at 05:45

1 Answers1

1

I ended up using QtQuick's line class and set its vertices using setVertices() in Bullet's flushLines() method.

danijar
  • 32,406
  • 45
  • 166
  • 297