Here's how the functions work: If you change the viewport origin to (xViewOrg, yViewOrg), the logical point (0, 0) will be mapped to the device point (xViewOrg, yViewOrg). If you change the window origin to (xWinOrg, yWinOrg), the logical point (xWinOrg, yWinOrg) will be mapped to the device point (0, 0), which is the upper left corner. Regardless of any changes you make to the window and viewport origins, the device point (0, 0) is always the upper left corner of the client area
按习惯,(0,0)就原点,原点就是(0,0),但是如果用此来理解windows的map mode,就会走弯路。其实,稍微改变一下观念,windows的map mode就比较好理解了。举例说明:
page space---->device space
pDC->SetMapMode(MM_LOMETRIC);
pDC->SetWindowOrg(40,0); //这句“设定”page space的原点为(40,0),注意,
//这时(40,0)就是原点,原点就是(40,0)这个点,其实,(0,0)与原点没有必然联系。这一句对下面的画图函数在page space中所作的图不会有任何影响。一句话:SetWindowOrg就是指定一下,page space中哪个点为原点。
pDC->Rectangle(0,0,100,-100);
pDC->Rectangle(0,-100,50,-200);
同理,SetViewportOrg也是指定一下,device space中哪个点为原点,两个坐标系映射时,两个原点重合。
SetWindowExt设定page space的大小,SetViewportOrg设定device space的大小,其实,真正有意义的只是两者的比例关系,例如,在一个1024*768的显示屏上:
pDC->SetMapMode(MM_ISOTROPIC);
pDC->SetWindowExt(10240,7680);
pDC->SetViewportExt(1024,768);
pDC->Rectangle(0,0,100,100);
就会画一个10 pixels*10 pixels的矩形。其本质就是,X方向,每个逻辑单位有1024/10240个象素,Y方向每个逻辑单位有768/7680个象素。因此,下面的代码有相同的作用:
pDC->SetMapMode(MM_ISOTROPIC);
pDC->SetWindowExt(102400,76800);
pDC->SetViewportExt(10240,7680);
pDC->Rectangle(0,0,100,100);
Here's how the functions work: If you change the viewport origin to (xViewOrg, yViewOrg), the logical point (0, 0) will be mapped to the device point (xViewOrg, yViewOrg). If you change the window origin to (xWinOrg, yWinOrg), the logical point (xWinOrg, yWinOrg) will be mapped to the device point (0, 0), which is the upper left corner. Regardless of any changes you make to the window and viewport origins, the device point (0, 0) is always the upper left corner of the client area