MM_ANISTROPIC

Someone please explain me how SetViewportOrg(), SetWindowOrg(), SetWindowExt() and SetViewportExt() works?
daknight2000Asked:
Who is Participating?
 
psdavisConnect With a Mentor Commented:
// Get the size of the current window

CRect rectClient;
GetClientRect(rectClient);

// Means that you will be responsible for setting the viewport/window extents.  The 'ANISOTROPIC' means that you'll have a different X and Y 'zoom' factor.  If you use ISOTROPIC, then the X and Y will have the same 'zoom' factor.  Other values will ignore the viewport/window extents.  For example MM_TWIPS will automatically expect each pixel to represent 1/1440 of an inch.

pDC->SetMapMode(MM_ANISTROPIC);

// Since SetViewportOrg is missing, I'm assuming it's at 0,0 like it should be.  The viewport org is set the the exact middle of the screen.  So when drawing, the origin of 0,0 is in the middle of the window at all times.

pDC->SetViewPortOrg(rectClient.right/2, rectClient.bottom/2);

// Moved this line up one.  This means that the total width and height of the extent is the entire width and height of the image.  The negative is because Y is exactly the opposite of what you were taught in school.  The only Y that isn't is the MM_TEXT mode, but it's only a 1:1 relationship.

pDC->SetViewPortExt(rectClient.right, -rectClient.bottom);

// OK, now we're finally having fun.  The 1000,1000 means that when you draw a point, it will be scaled to the entire window.

pDC->SetWindowExt(1000,1000);

// Let's do an example. If you started with

pDC->MoveTo( 0, 0 );  

// That would move to the center of the screen

pDC->LineTo( 500, 0 );

// This will draw a line from the center of the image to the right HALF way towards the edge of the window.

pDC->LineTo( 1000, 0 );

// This would draw it from the center to the right edge of the window

pDC->LineTo( -1000, 0 );

// To the left edge.

pDC->LineTo( 0, 500 );

// Half way up the image

// Get the idea.  Whatever the drawing measurements, the 500 is placed in the right ratio from the window extents to the viewport extents.

Good luck
0
 
psdavisCommented:
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
0
 
daknight2000Author 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
0
 
daknight2000Author Commented:
thanx alot Phillip ...  Now i got something in my mind ...

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.