Windows api之SetPolyFillMode的winding填充模式原理

来源:互联网 发布:9.9元天天特价淘宝包 编辑:程序博客网 时间:2024/05/25 23:58

俗话说,佛法只渡有缘人,咱直接上英文了

SetPolyFillMode 的填充模式研究 ALTERNATE WINDING

函数原型

 int SetPolyFillMode( __in HDC hdc, __in int iPolyFillMode );

这是文档的原内容

ValueMeaning
ALTERNATE
Selects alternate mode (fills the area between odd-numbered and even-numbered polygon sides on each scan line).
WINDING
Selects winding mode (fills any region with a nonzero winding value).

 

批注  Remarks

In general, the modes differ only in cases where a complex, overlapping polygon must be filled (for example, a five-sided polygon that forms a five-pointed star with a pentagon in the center). In such cases, ALTERNATE mode fills every other enclosed region within the polygon (that is, the points of the star), but WINDING mode fills all regions (that is, the points and the pentagon).

When the fill mode is ALTERNATE, GDI fills the area between odd-numbered and even-numbered polygon sides on each scan line. That is, GDI fills the area between the first and second side, between the third and fourth side, and so on.

GDI 只填充扫描线划过的第一条边和第二条边,第三条边和第四条边之间的区域

 

When the fill mode is WINDING, GDI fills any region that has a nonzero winding value. This value is defined as the number of times a pen used to draw the polygon would go around the region. The direction of each edge of the polygon is important.

 

文档里提出了个词,winding number,wiki一下

In mathematics, thewinding number of a closed curve in the plane around a given point is an integer representing the total number of times that curve travels counterclockwise around the point. The winding number depends on theorientation of the curve, and is negative if the curve travels around the point clockwise.

1

\cdots  Winding Number -2.svg  Winding Number -1.svg  Winding Number 0.svg 123    Winding Number 1.svg  Winding Number 2.svg  Winding Number 3.svg −2−10 

最后终于弄明白两种填充方式了

winding

这是一个多边形,我们演一条边一个方向走,向箭头那样,走图形一圈,winding会填充1,2,3,5,但是不会填充4,因为4的winding number 为0,看箭头,4的两条边一个是顺时针,一个是逆时针,所以winding number 为0 ,5两边都是顺时针,winding number为1

alternate


这个就比较简单,看红色的scan line,从right 到left,1,2边之间的区域被填充了,3,4边之间的区域被填充了


原创粉丝点击