我正在尝试使用Attched Image:
但是,我的代码为我提供了以下模式:
谁能指导我正确的方向?
void drawPattern(float xPos, float yPos, float length){
glColor3f(0.0, 1.0, 0.0);
// Drawing Square
glBegin(GL_POLYGON);
glVertex2f(xPos + length, yPos);
glVertex2f(xPos, yPos);
glVertex2f(xPos , yPos + length);
glVertex2f(xPos + length , yPos + length);
glEnd();
glColor3f(0,0,1);
float halfPi = 0.5 * PI;
//Drawing Bottom Left Circle
glBegin(GL_LINE_LOOP);
for (float angle = 0.0; angle < 90 * 0.01745329; angle += 0.01745329){
glVertex2f( xPos + (length/2)*cos(angle), yPos + (length/2)*sin(angle));
}
glEnd();
//Drawing Top Right Circle
glBegin(GL_LINE_LOOP);
for (float angle = 0.0; angle < 90 * 0.01745329; angle += 0.01745329){
glVertex2f( xPos + length/2 + (length/2)*cos(angle), yPos + length/2 + (length/2)*sin(angle));
}
glEnd();
}
最佳答案
除此之外,您还必须使用line primitive type GL_LINE_STRIP
而不是GL_LINE_LOOP
,答案中已经提到过,右上角的弧线方向错误。
这是因为圆弧的中心点必须位于左上角(xPos + length
,yPos + length
)角,而不是四边形的中心。此外,必须在左下段中绘制圆弧。这可以通过减去正弦和余弦项来实现:
glBegin(GL_LINE_STRIP);
for (float angle = 0.0; angle < 90 * 0.01745329; angle += 0.01745329) {
glVertex2f(
xPos + length - (length/2)*cos(angle),
yPos + length - (length/2)*sin(angle));
}
glEnd();
关于c++ - OpenGL-绘制图案,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58194811/