Bresenham algorytm

0

Witam,

mam problem, probuje skonczyc algorytm bresenham's, ale problem jest taki ze rysuje tylko na polowe oktanow (octants)

Jak robilem slope negatywny to wywalal mi blad...

Jak to poprawic zeby linia rysowana sie praktycznie na 360 stopni w kazda strone?

void Rasterizer::DrawLine2D(const Vertex2d & v1, const Vertex2d & v2, int thickness)
{
Vector2 pt1 = v1.position;
Vector2 pt2 = v2.position;

bool swap_vertices = false; // Set to true when x1 > x2
bool negative_slope = false; // Set to true if y2 - y1 < 0
bool swap_xy = false; // set to true if dx < dy

// SWAP VERTICES
if (pt1[0] > pt2[0])
{
    swap_vertices = true;
}

if (swap_vertices == true)
{
    pt1 = v2.position;
    pt2 = v1.position;
}

// NEGATIVE SLOPE
if (pt2[1] - pt1[1] < 0)
{
    negative_slope = true;
}

int dx = pt2[0] - pt1[0];
int dy = pt2[1] - pt1[1];

int epsilon = 0;

int x = pt1[0];
int y = pt1[1];
int ex = pt2[0];

if (negative_slope == true)
{
    y = -y;
    dy = -dy;   
}

// SWAP X AND Y
if(abs(dx) < abs(dy))
{
    swap_xy = true;
}

if (swap_xy == true) {
    x = pt1[1];
    y = pt1[0];
}

while (x <= ex)
{
    int newx = x;
    int newy = y;

    if (negative_slope == true)
    {
        newy = -y;
    }

    if(swap_xy == true)
    {
        // DO SOMETHING
        newy = x;
        newx = y;
    }

    Vector2 temp(newx, newy);
    Colour4 colour = v1.colour;

    SetFGColour(colour);
    DrawPoint2D(temp);

    epsilon += dy;

    if ((epsilon << 1) >= dx)
    {
        y++;

        epsilon -= dx;
    }
    x++;
}
}
0

Ktos sie zna na tym temacie ? Mogę zapłacić za korepetycje jesli trzeba. Proszę o odp.

1 użytkowników online, w tym zalogowanych: 0, gości: 1