我尝试将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();
}
setDebugMode(btIDebugDraw::DBG_DrawWireframe)
之后推入了一个新行? - Rebirth