// 主渲染函数 void DrawTrap(HTrapezoid trap) { //HScanline scanline; int j, top, bottom; top = (int)(trap.top + 0.5f); bottom = (int)(trap.bottom + 0.5f); for (j = top; j < bottom; j++) { if (j >= 0 && j < HScreenDevice.GetInstance().ScreenHeight) //todo //插值得到梯形的腰的两个点 { trap.EdgeInterp((float)j + 0.5f); //初始化扫描线 HScanline scanline = GetScanline(trap, j); //绘制扫描线 DrawScanline(scanline); } } }
// 根据左右两边的端点,初始化计算出扫描线的起点和步长 HScanline GetScanline(HTrapezoid trap, int y) { HScanline scanlineRet = new HScanline(); // 左右两点的 宽度 float width = trap.right.v.pos.x - trap.left.v.pos.x; // 起点X 坐标 scanlineRet.x = (int)(trap.left.v.pos.x + 0.5f); // 宽度 scanlineRet.width = (int)(trap.right.v.pos.x + 0.5f) - scanlineRet.x; // y坐标 scanlineRet.y = y; // 扫描起点 scanlineRet.v = trap.left.v.Copy(); // if (trap.left.v.pos.x >= trap.right.v.pos.x) { scanlineRet.width = 0; } //计算步伐 scanlineRet.step = trap.left.v.Step(trap.right.v, width); return(scanlineRet); }