|
|
@ -163,8 +163,16 @@ void Raster::drawSpan(const Span &span) { |
|
|
|
|
|
|
|
Rgba color; |
|
|
|
float length = span.xEnd - span.xStart; |
|
|
|
for (int i = span.xStart; i <= span.xEnd; i++) { |
|
|
|
color = colorLerp(span.color1, span.color2, (float) (i - span.xStart) / length); |
|
|
|
|
|
|
|
|
|
|
|
int startX = tmax<int>(span.xStart, 0); |
|
|
|
int endX = tmin<int>(span.xEnd, _width); |
|
|
|
|
|
|
|
float scale = (startX - span.xStart) / length; |
|
|
|
|
|
|
|
//优化3 x轴越界处理
|
|
|
|
for (int i = startX; i <= endX; i++) { |
|
|
|
color = colorLerp(span.color1, span.color2, (float) (i - startX) / length); |
|
|
|
setPixel(i, span.y, color); |
|
|
|
} |
|
|
|
} |
|
|
@ -182,16 +190,20 @@ void Raster::drawEge(const Ege& e1, const Ege& e2) { |
|
|
|
float scale2 = 0; |
|
|
|
|
|
|
|
|
|
|
|
//优化2 不画三角形坐标y以为的部分
|
|
|
|
// int startY = tmin<int>(e2.y2, _height);
|
|
|
|
// int endY = tmax<int>(e2.y1, 0);
|
|
|
|
// scale2 = (startY - _height) / yOffset2;
|
|
|
|
//优化2 y轴越界处理
|
|
|
|
int startY2 = tmin<int>(e2.y2, _height); |
|
|
|
int endY2 = tmax<int>(e2.y1, 0); |
|
|
|
scale2 = (e2.y2 - startY2) / yOffset2; |
|
|
|
|
|
|
|
int startY1 = tmin<int>(e1.y2, _height); |
|
|
|
float s = (e1.y2 - startY1) / yOffset1; |
|
|
|
scale1 = tmax<float>(scale1, s); |
|
|
|
|
|
|
|
//printf("")
|
|
|
|
|
|
|
|
Rgba colorE1; |
|
|
|
Rgba colorE2; |
|
|
|
for (int y = e2.y2; y > e2.y1; y--) { |
|
|
|
for (int y = startY2; y > endY2; y--) { |
|
|
|
|
|
|
|
int x2; |
|
|
|
if (e2.x2 < e2.x1) { |
|
|
|