[英]drawing multiple circles in Qt
I have a code that draws a circle in this way: 我有一个这样绘制代码的代码:
QList< QPair<double, double> > vertices;
//constructor
vertices.clear();
calculateWhiteVetices();
//drawing methods
void MyGLWidget::drawWhiteCircle() {
int n = vertices.count();
qglColor(Qt::white);
glBegin(GL_POLYGON);
for(int i = 0; i < n; i++) {
glVertex2f(vertices[i].first, vertices[i].second);
}
glEnd();
}
void MyGLWidget::calculateWhiteVetices()
{
double a = 3.14 / 90;
vertices.append(QPair<double, double> (0,0));
for(int i = 0; i <= 360; i++) {
vertices.append(QPair<double, double> (cos(i * a) * radius, sin(i * a) * radius));
}
}
//paintGL method
glPushMatrix();
glTranslatef(randx , randy , 0);
drawWhiteCircle();
glPopMatrix();
now I want to add another circle here, but there's a problem; 现在我想在这里添加另一个圆圈,但是有一个问题; The colors are mixed together and the shape is ruined.
颜色混合在一起,形状被破坏。 This is the code:
这是代码:
QList< QPair<double, double> > blueVertices;
//constructor
blueVertices.clear();
calculateBlueVetices();
replacing each vertices
with blueVertices
in new methods and put the methods exactly next to white circle's methods. 在新方法
blueVertices
每个vertices
替换为blueVertices
,然后将这些方法恰好置于白色圆圈的方法旁边。 and put this part of code right after the glPopMatrix();
并将这部分代码放在
glPopMatrix();
in the paintGL
method. 在
paintGL
方法中。
//paintGL method
glPushMatrix();
glTranslatef(randx-0.2f , randy-0.2f , 0);
drawBlueCircle();
glPopMatrix();
I know the vertices are mixing somewhere because of my bad definition but I don't know where... . 由于我的定义不正确,我知道顶点在某处混合,但我不知道在哪里。 What is my fault here?
我这是什么错 This is my output:
这是我的输出:
You can draw both circles side-by-side with some distance just to verify you are generating correct vertices. 您可以并排绘制一定距离的两个圆,以验证您生成的顶点正确。 Just to start with you can try White circle with
glTranslatef(radius , 0 , 0);
刚开始时,您可以尝试使用
glTranslatef(radius , 0 , 0);
白色圆圈glTranslatef(radius , 0 , 0);
and Blue with glTranslatef( -radius , 0 , 0);
和蓝色带
glTranslatef( -radius , 0 , 0);
to check if both have required vertices 检查两个顶点是否都需要顶点
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.