【发布时间】:2011-05-04 16:23:56
【问题描述】:
有一种快速的方法可以像这样画圆
void DrawCircle(float cx, float cy, float r, int num_segments)
{
float theta = 2 * 3.1415926 / float(num_segments);
float c = cosf(theta);//precalculate the sine and cosine
float s = sinf(theta);
float t;
float x = r;//we start at angle = 0
float y = 0;
glBegin(GL_LINE_LOOP);
for(int ii = 0; ii < num_segments; ii++)
{
glVertex2f(x + cx, y + cy);//output vertex
//apply the rotation matrix
t = x;
x = c * x - s * y;
y = s * t + c * y;
}
glEnd();
}
我想知道是否有类似的方法来绘制椭圆,其中长轴/短轴矢量和大小都是已知的。
【问题讨论】:
-
只要您使用立即模式(glBegin、glVertex、glEnd 等),该代码就永远不会“高效”
标签: opengl graphics vector geometry