我试图将 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/