绘制实心底部三角形

时间:2016-10-27 21:24:03

标签: c++ algorithm graphics 3d

我正在尝试绘制一个平底三角形,一个实心的三角形,但是当我这样称呼它时,我得到一个除零

raster.DrawBottomTriangle(0, 50, 50, 0, -50, 0, Color(1, 0, 0));

所以我尝试使用上面的函数绘制一个平底三角形,但是我得到一个除零。

void Rasterizer::DrawBottomTriangle(int x0, int y0, int x1, int y1, int x2, int y2, Color color)
{
    int temp_x;

    // test order of x1 and x2
    if (x2 < x1)
    {
        temp_x = x1;
        x1 = x2;
        x2 = temp_x;
    } // end if swap
    // compute deltas
    float dxy_left = (x2 - x0) / (y2 - y0);
    float dxy_right = (x2 - x1) / (y2 - y1);
    // set starting and ending points for edge trace
    float xs = x0;
    float xe = x1;

    // draw each scanline
    for (int y = y0; y <= y2; y++)
    {
        // draw a line from xs to xe at y in color c
        DrawHorizontalLine((int)(xs + 0.5), (int)(xe + 0.5), 50, color);
        // move down one scanline
        xs += dxy_left;
        xe += dxy_right;
    } // end for y

}

0 个答案:

没有答案