Skip to content

Commit

Permalink
Simple speed up of Lesson 1 ssloy/tinyrenderer#28
Browse files Browse the repository at this point in the history
  • Loading branch information
mathsyouth committed Oct 7, 2024
1 parent ccdf77b commit 5e66337
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,31 @@ void line(int x0, int y0, int x1, int y1, TGAImage &image, TGAColor color)
int derror2 = std::abs(dy) * 2;
int error2 = 0;
int y = y0;
for (int x=x0; x <= x1; x++)
const int yinc = (y1 > y0? 1 : -1);
if (steep)
{
if (steep)
for (int x=x0; x <= x1; x++)
{
image.set(y, x, color);
error2 += derror2;
if (error2 > dx)
{
y += yinc;
error2 -= dx * 2;
}
}
else
}
else
{
for (int x=x0; x <= x1; x++)
{
image.set(x, y, color);
}
error2 += derror2;
if (error2 > dx)
{
y += (y1 > y0? 1 : -1);
error2 -= dx * 2;
error2 += derror2;
if (error2 > dx)
{
y += yinc;
error2 -= dx * 2;
}
}
}
}
Expand Down

0 comments on commit 5e66337

Please sign in to comment.