Fun with SetWorldTransform

Environment: VC6, MFC

This code will show you how useful SetWorldTransform can be. The code will enable you to do things such as:

  • Scale to 1/2 of the original size
  • Translate right by 3/4 inch
  • Rotate 30 degrees counterclockwise
  • Shear along the x-axis with a proportionality constant of 1.0
  • Reflect about a horizontal axis

The code was originally part of the MS SDK, but I have enhanced and converted it to MFC to make it easier to understand.


// The Key part to the source code is using ‘SetWorldTransform’
// and setting up the XFORM structure

XFORM xForm;

SetGraphicsMode ( pDC->GetSafeHdc (), GM_ADVANCED );
pDC->SetMapMode ( MM_LOENGLISH );

xForm.eM11 = (FLOAT) 0.5;
xForm.eM12 = (FLOAT) 0.0;
xForm.eM21 = (FLOAT) 0.0;
xForm.eM22 = (FLOAT) 0.5;
xForm.eDx = (FLOAT) 0.0;
xForm.eDy = (FLOAT) 0.0;
SetWorldTransform ( pDC->GetSafeHdc (), &xForm );

Downloads


Download demo project – 8 Kb


Download source – 22 Kb

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read