c – 如何在QML场景上绘制3D线条?
发布时间:2020-12-16 07:10:45 所属栏目:百科 来源:网络整理
导读:我尝试将Bullet Physics的调试绘图界面集成到QML中,因此我必须实现drawLine()方法. void drawLine(const btVector3 from,const btVector3 to,const btVector3 color); 我尝试的是我从QQuickItem3D和btIDebugDraw继承了一个在场景中使用的项目.在drawLine()中
我尝试将Bullet Physics的调试绘图界面集成到QML中,因此我必须实现drawLine()方法.
void drawLine(const btVector3 &from,const btVector3 &to,const btVector3 &color); 我尝试的是我从QQuickItem3D和btIDebugDraw继承了一个在场景中使用的项目.在drawLine()中,我将行添加到成员向量中.在Qt的drawItem()中,我遍历这些行并使用OpenGL调用来渲染它们.但是,它们不会出现在屏幕上. 如何在3D空间和正确的摄像机视图中绘制线条? 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()设置其顶点.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |