0
我有一个绘制圆的函数。绘制正方形时的OpenGL圆弧半径问题
glBegin(GL_LINE_LOOP);
for(int i = 0; i < 20; i++)
{
float theta = 2.0f * 3.1415926f * float(i)/float(20);//get the current angle
float rad_x = ratio*(radius * cosf(theta));//calculate the x component
float rad_y = radius * sinf(theta);//calculate the y component
glVertex2f(x + rad_x, y + rad_y);//output vertex
}
glEnd();
这工作丹迪。我将X,Y和半径值保存在我的对象中。
然而,当我试着画一个正方形用下面的函数调用:
newSquare(id, red, green, blue, x, (x + radius), y, (y + radius));
我获得下面的图片。
正如你看到的,广场是近一倍宽(看起来更像直径)。以下代码是我如何创建我的方形框。正如你所看到的,它开始于它应该在的圆圈的中心。并且应该延伸到圆的边缘。
glBegin(GL_QUADS);
glVertex2f(x2, y2);
glVertex2f(x2, y1);
glVertex2f(x1, y1);
glVertex2f(x1, y2);
glEnd();
我似乎无法理解为什么这是!
你的代码看起来正确(假设'ratio = 1')。构建圆时,您可能已经设置了一些错误的参数。显然,两个'radius'变量都不匹配。 – 2014-11-02 15:24:39
我的比例实际上是父窗口的宽度/高度!我会调查。 – 2014-11-02 15:27:32
哦,所以你做了一个手动投影。你应该把它留给投影矩阵。这确保所有对象都在同一个坐标系中。例如。你还没有x修正你的四边形。 – 2014-11-02 15:29:28