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