Solved

MM_ANISTROPIC

Posted on 1998-09-16
4
274 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand data scrubbing tool 13 32
method notes when mouse over in eclipse 5 87
MaxSpan challenge 9 96
Problem to event 3 97
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 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