Link to home
Start Free TrialLog in
Avatar of daknight2000
daknight2000

asked on

MM_ANISTROPIC

Someone please explain me how SetViewportOrg(), SetWindowOrg(), SetWindowExt() and SetViewportExt() works?
Avatar of psdavis
psdavis
Flag of United States of America image

Sure, wondered about that myself for the longest time.  

1) SetWindowOrg.  Just leave this to 0,0 and ignore this one.
2) SetViewportOrg.  Whenever you want to change the origin of the drawing, move the origin to a certain location.  Then if you use a BitBlt or StretchDIBits then the image will be automatically updated
3) Extents.  All the extents do is create a 'zoom' factor.  It could have just as easily been SetExtentZoom( float ) and it would have been a whole lot simpler.  Take a look at the following code I wrote to convert LP to DP coordinates.  Don't over think the extents.  Set the WindowExtent to some useful number (I use 600 dpi so it's at 600 for me).  And set your viewport extents to the same number for a non-zoomed image.  If you change your ViewportExtents to lets say (1200,1200), then the image will be twice as large.  If it's (300,300) then it's shrunk.  Get the idea?

void CAfixCtrl::QuickLPtoDP( CPoint& ptPoint )
{
   float fZoomX = (float) m_szViewportExt.cx / (float) m_szWindowExt.cx;
   float fZoomY = (float) m_szViewportExt.cy / (float) m_szWindowExt.cy;

   ptPoint.x = (int)( ptPoint.x * fZoomX + 0.5 ) + m_ptViewportOrg.x;
   ptPoint.y = (int)( ptPoint.y * fZoomY + 0.5 ) + m_ptViewportOrg.y;
}

void CAfixCtrl::QuickDPtoLP( CPoint& ptPoint )
{
   float fZoomX = (float) m_szViewportExt.cx / (float) m_szWindowExt.cx;
   float fZoomY = (float) m_szViewportExt.cy / (float) m_szWindowExt.cy;

   ptPoint.x = (int)(((float)( ptPoint.x - m_ptViewportOrg.x ) / fZoomX ) + 0.5 );
   ptPoint.y = (int)(((float)( ptPoint.y - m_ptViewportOrg.y ) / fZoomY ) + 0.5 );
}

Phillip
Avatar of daknight2000
daknight2000

ASKER

sorry Philip .. I am a kid in mfc world... I guess, I failed to explain the question ...
Please explain me what this piece of code is supposed to do :-

CRect rectClient;
GetClientRect(rectClient);
pDC->SetMapMode(MM_ANISTROPIC);
pDC->SetWindowExt(1000,1000);
pDC->SetViewPortExt(rectClient.right, -rectClient.bottom);
pDC->SetViewPortOrg(rectClient.right/2, rectClient.bottom/2);

please also explain me that what  that "-" sign with "y" co-ordinate in SetViewPortExt() is supposed to do?
thanx alot
ASKER CERTIFIED SOLUTION
Avatar of psdavis
psdavis
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanx alot Phillip ...  Now i got something in my mind ...