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


Comments

  • Doubt regarding combination of these operations.

    Posted by Legacy on 08/20/2003 12:00am

    Originally posted by: Chandra Prakash Joshi

    In ur example you have shown all the transform operation with respect to the original image. Suppose i want a rectangular(not square) image to rotate 90 degree than zoom 200% than reflect along x axis and than again rotate it -90 degree. and unfortunately i can't use array for storing the list of transformations done on my image. Any suggestion or idea will be of gr8 Help.. ThankU.

    Reply
  • WinNT only...

    Posted by Legacy on 08/14/2003 12:00am

    Originally posted by: Oliver

    Good demonstration of world transformation. Thank you!

    Maybe you should point out that this example code works on WinNT only since SetWorldTransform is unsupported on non-NT systems.
    The usefulness of a function set that does not work on all Win platforms is a point that should be discussed.

    Oliver.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Event Date: April 15, 2014 The ability to effectively set sales goals, assign quotas and territories, bring new people on board and quickly make adjustments to the sales force is often crucial to success--and to the field experience! But for sales operations leaders, managing the administrative processes, systems, data and various departments to get it all right can often be difficult, inefficient and manually intensive. Register for this webinar and learn how you can: Align sales goals, quotas and …

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds