We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

MM_ANISTROPIC

daknight2000
daknight2000 asked
on
Medium Priority
329 Views
Last Modified: 2013-11-20
Someone please explain me how SetViewportOrg(), SetWindowOrg(), SetWindowExt() and SetViewportExt() works?
Comment
Watch Question

Commented:
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

Author

Commented:
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
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
thanx alot Phillip ...  Now i got something in my mind ...

Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.