Commit 9d506946 authored by Marek Dvoroznak's avatar Marek Dvoroznak Committed by Mikael Magnusson

libs: npd: better triangle texturing

parent 97d3926b
...@@ -154,45 +154,25 @@ npd_draw_texture_line (gint x1, ...@@ -154,45 +154,25 @@ npd_draw_texture_line (gint x1,
} }
static void static void
npd_texture_fill_triangle (gint x1, npd_texture_fill_triangle (gint x1,
gint y1, gint y1,
gint x2, gint x2,
gint y2, gint y2,
gint x3, gint x3,
gint y3, gint y3,
NPDMatrix *A, NPDMatrix *A,
NPDImage *input_image, NPDImage *input_image,
NPDImage *output_image, NPDImage *output_image,
NPDSettings settings) NPDSettings settings)
{ {
gint yA, yB, yC, xA, xB, xC; gint yA, yB, yC, xA, xB, xC;
gint tmp, y; gint y;
gint deltaXAB, deltaYAB; gint deltaXAB, deltaYAB;
gint deltaXBC, deltaYBC; gint deltaXBC, deltaYBC;
gint deltaXAC, deltaYAC; gint deltaXAC, deltaYAC;
gint dX1, dX2, dX3, dX4;
gfloat slopeAB; gint dY1, dY2, dY3, dY4;
gfloat slopeBC; gint k, l;
gfloat slopeAC;
gfloat k, l;
gfloat slope1, slope2, slope3, slope4;
if (y1 == y2 && x1 > x2)
{
tmp = y1; y1 = y2; y2 = tmp;
tmp = x1; x1 = x2; x2 = tmp;
}
if (y1 == y3 && x1 > x3)
{
tmp = y1; y1 = y3; y3 = tmp;
tmp = x1; x1 = x3; x3 = tmp;
}
if (y2 == y3 && x2 > x3)
{
tmp = y2; y2 = y3; y3 = tmp;
tmp = x2; x2 = x3; x3 = tmp;
}
if (y1 <= y2) if (y1 <= y2)
{ {
...@@ -241,60 +221,61 @@ npd_texture_fill_triangle (gint x1, ...@@ -241,60 +221,61 @@ npd_texture_fill_triangle (gint x1,
deltaXBC = xC - xB, deltaYBC = yC - yB; deltaXBC = xC - xB, deltaYBC = yC - yB;
deltaXAC = xC - xA, deltaYAC = yC - yA; deltaXAC = xC - xA, deltaYAC = yC - yA;
slopeBC = (deltaYBC == 0 ? 0 : (gfloat) deltaXBC / deltaYBC); if (deltaYAB != 0)
slopeAC = (deltaYAC == 0 ? 0 : (gfloat) deltaXAC / deltaYAC);
if (deltaYAB == 0)
{ {
slopeAB = 0; gboolean test = ((gfloat) deltaXAB / deltaYAB) > ((gfloat) deltaXAC / deltaYAC);
k = xA; if (test)
l = xB; {
dX1 = deltaXAC; dY1 = deltaYAC;
slope1 = slopeAB; dX2 = deltaXAB; dY2 = deltaYAB;
slope2 = slopeAC; dX3 = deltaXAC; dY3 = deltaYAC;
slope3 = slopeAC; dX4 = deltaXBC; dY4 = deltaYBC;
slope4 = slopeBC; }
else
{
dX1 = deltaXAB; dY1 = deltaYAB;
dX2 = deltaXAC; dY2 = deltaYAC;
dX3 = deltaXBC; dY3 = deltaYBC;
dX4 = deltaXAC; dY4 = deltaYAC;
}
k = xA * dY1; l = xA * dY2;
for (y = yA; y < yB; y++)
{
npd_draw_texture_line (k / dY1, l / dY2 - 1,
y, A,
input_image, output_image,
settings);
k += dX1; l += dX2;
}
if (test) l = xB * dY4;
else k = xB * dY3;
} }
else else
{ {
slopeAB = (gfloat) deltaXAB / deltaYAB; if (deltaXAB > 0)
k = xA;
l = xA;
if (slopeAB > slopeAC)
{ {
slope1 = slopeAC; dX3 = deltaXAC; dY3 = deltaYAC;
slope2 = slopeAB; dX4 = deltaXBC; dY4 = deltaYBC;
slope3 = slopeAC; k = xA * dY3; l = xB * dY4;
slope4 = slopeBC;
} }
else else
{ {
slope1 = slopeAB; dX3 = deltaXBC; dY3 = deltaYBC;
slope2 = slopeAC; dX4 = deltaXAC; dY4 = deltaYAC;
slope3 = slopeBC; k = xB * dY3; l = xA * dY4;
slope4 = slopeAC;
} }
} }
for (y = yA; y < yB; y++) for (y = yB; y < yC; y++)
{
npd_draw_texture_line ((gint) round (k), (gint) round (l),
y, A,
input_image, output_image,
settings);
k += slope1;
l += slope2;
}
for (y = yB; y <= yC; y++)
{ {
npd_draw_texture_line ((gint) round (k), (gint) round (l), npd_draw_texture_line (k / dY3, l / dY4 - 1,
y, A, y, A,
input_image, output_image, input_image, output_image,
settings); settings);
k += slope3; k += dX3; l += dX4;
l += slope4;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment