用OpenGL或D3D绘制Ellipse的有效方法 [英] Effecient way to draw Ellipse with OpenGL or D3D
本文介绍了用OpenGL或D3D绘制Ellipse的有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
void DrawCircle(float cx,float cy,float r,int num_segments)
{
float theta = 2 * 3.1415926 / float(num_segments);
float c = cosf(theta); //预先计算正弦和余弦
float s = sinf(theta);
float t;
float x = r; //我们从角度= 0开始
float y = 0;
glBegin(GL_LINE_LOOP);
for(int ii = 0; ii {
glVertex2f(x + cx,y + cy); //输出顶点
//应用旋转矩阵
t = x;
x = c * x - s * y;
y = s * t + c * y;
}
glEnd();
$ b 我想知道是否有类似的方法来绘制椭圆的主要/短轴矢量和大小都是已知的。
解决方案
无法在openGL中绘制曲线,只需很多直线线。但是如果你使用了顶点缓冲对象,那么你不必将每个顶点都发送到显卡上,这样会更快。 b
$ b
There is a fast way to draw circle like this
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();
}
I am wondering if there is a similar way to draw ellipse where its major/minor axes vector and size are both known.
解决方案 There is no way to draw a curve in openGL, just a lot of straight lines. But if you used vertex buffer objects then you won't have to send each vertex to the graphics card which will be much faster.
这篇关于用OpenGL或D3D绘制Ellipse的有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文