Solved

MM_ANISTROPIC

Posted on 1998-09-16
4
265 Views
Last Modified: 2013-11-20
Someone please explain me how SetViewportOrg(), SetWindowOrg(), SetWindowExt() and SetViewportExt() works?
0
Comment
Question by:daknight2000
  • 2
  • 2
4 Comments
 
LVL 7

Expert Comment

by:psdavis
ID: 1322174
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
 

Author Comment

by:daknight2000
ID: 1322175
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
 
LVL 7

Accepted Solution

by:
psdavis earned 50 total points
ID: 1322176
// 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
 

Author Comment

by:daknight2000
ID: 1322177
thanx alot Phillip ...  Now i got something in my mind ...

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now