绘制点或填充圆形

3
在OpenGL中,如果我想画一个填充的圆形,我会这样做:
void DrawPoint(float X, float Y, float Z, float Radius) const
{
    glRasterPos2f(X, Y);
    glPointSize(Radius);
    glBegin(GL_POINTS);
        glVertex3f(X, Y, Z);
    glEnd();
    glPointSize(this->PointSize);
    glFlush();
}

然而,我在Direct-X中找不到glPointSize的等效物。因此,我尝试了以下内容:

struct Vector3
{
    double X, Y, Z;
};

#include <vector>
void DrawCircle1(float X, float Y, DWORD Color)
{
    const int sides = 20;
    std::vector<D3DXVECTOR3> points;
    for(int i = 0; i < sides; ++i)
    {
        double angle = D3DX_PI * 2 / sides * i;
        points.emplace_back(D3DXVECTOR3(sin(angle), cos(angle), 0));
    }

    device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, sides, &points[0], sizeof(D3DXVECTOR3));
}

void DrawCircle2(float CenterX, float CenterY, float Radius, int Rotations)
{
    std::vector<D3DXVECTOR3> Points;
    float Theta = 2 * 3.1415926535897932384626433832795 / float(Rotations);
    float Cos = cosf(Theta);
    float Sine = sinf(Theta);
    float X = Radius, Y = 0, Temp = 0;

    for(int I = 0; I < Rotations; ++I)
    {
        Points.push_back(D3DXVECTOR3(X + CenterX, Y + CenterY, 0));
        Temp = X;
        X = Cos * X - Sine * Y;
        Y = Sine * Temp + Cos * Y;
    }

    device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, Points.size(), &Points[0], sizeof(D3DXVECTOR3));
}

但是这些都不起作用。我无法弄清为什么什么都不起作用。第一个绘制了一个巨大的黑色圆圈,第二个绘制了一个长三角形。

有什么想法可以在Direct-X中绘制填充的圆或特定大小和颜色的点吗?

1个回答

2
static const int CIRCLE_RESOLUTION = 64;

struct VERTEX_2D_DIF { // transformed colorized
    float x, y, z, rhw;
    D3DCOLOR color;
    static const DWORD FVF = D3DFVF_XYZRHW|D3DFVF_DIFFUSE;
};

void DrawCircleFilled(float mx, float my, float r, D3DCOLOR color)
{
    VERTEX_2D_DIF verts[CIRCLE_RESOLUTION+1];

    for (int i = 0; i < CIRCLE_RESOLUTION+1; i++)
    {
        verts[i].x = mx + r*cos(D3DX_PI*(i/(CIRCLE_RESOLUTION/2.0f)));
        verts[i].y = my + r*sin(D3DX_PI*(i/(CIRCLE_RESOLUTION/2.0f)));
        verts[i].z = 0;
        verts[i].rhw = 1;
        verts[i].color = color;
    }

    m_pDevice->SetFVF(VERTEX_2D_DIF::FVF);
    m_pDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, CIRCLE_RESOLUTION-1, &verts, sizeof(VERTEX_2D_DIF));
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接