在OpenGl中画椭圆 [英] Drow an Ellipse in OpenGl

查看:79
本文介绍了在OpenGl中画椭圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 如何在Visual Studio Studio C ++中用Midpoint方法绘制椭圆?

Hi How can i draw an Ellipse with Midpoint method in visual-studio c++?

推荐答案

很多可能性之一...由Google"opengl ellipse":
http://stackoverflow.com/questions/5886628/effecient- [-a-d3d或d3d的方式来绘制椭圆形 [
One of lot of possibilities...by google "opengl ellipse":
http://stackoverflow.com/questions/5886628/effecient-way-to-draw-ellipse-with-opengl-or-d3d[^]

In the hope language depended differences can be resolved by OP.

Regards.


void drawEllipse(float xc, float yc, float x, float y)
{
    int p1[] = {(int)xc+x, (int)yc+y};
    int p2[] = {(int)xc-x, (int)yc+y};
    int p3[] = {(int)xc+x, (int)yc-y};
    int p4[] = {(int)xc-x, (int)yc-y};
    glVertex2iv(p1);
    glVertex2iv(p2);
    glVertex2iv(p3);
    glVertex2iv(p4);
}

void ellipseMidpoint(float xc, float yc, float rx, float ry)
{
    float rxSq = rx * rx;
    float rySq = ry * ry;
    float x = 0, y = ry, p;
    float px = 0, py = 2 * rxSq * y;
    drawEllipse(xc, yc, x, y);

    p = rySq - (rxSq * ry) + (0.25 * rxSq);
    while (px < py)
    {
        x++;
        px = px + 2 * rySq;
        if (p < 0)
            p = p + rySq + px;
        else
        {
            y--;
            py = py - 2 * rxSq;
            p = p + rySq + px - py;
        }
        drawEllipse(xc, yc, x, y);
    }

    p = rySq*(x+0.5)*(x+0.5) + rxSq*(y-1)*(y-1) - rxSq*rySq;
    while (y > 0)
    {
        y--;
        py = py - 2 * rxSq;
        if (p > 0)
            p = p + rxSq - py;
        else
        {
            x++;
            px = px + 2 * rySq;
            p = p + rxSq - py + px;
        }
        drawEllipse(xc, yc, x, y);
    }
}


这篇关于在OpenGl中画椭圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆