The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Hi!

I'm trying to rotate a metafile with the SetWorldTransform.

But it rotates around the upper left corner of my picture.

I want it to rotate around the center.

How do i do that ???

I'm trying to rotate a metafile with the SetWorldTransform.

But it rotates around the upper left corner of my picture.

I want it to rotate around the center.

How do i do that ???

hDC = BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );

/* Rita kursskivan som bakgrund till kompassen */

SetMapMode( hDC, MM_ANISOTROPIC );

SetViewportOrgEx( hDC, ClientRect.left, ClientRect.top, NULL );

SetViewportExtEx( hDC, XSize, YSize, NULL );

PlayMetaFile( hDC, hMFBackGround );

/* Rita skillnadsfalt */

if( Compass[ CpIx ]->Active ){

SelectObject( hDC, YellowBrush );

}

else SelectObject( hDC, BlackBrush );

SelectObject( hDC, GetStockObject( NULL_PEN ) );

SetMapMode( hDC, MM_TEXT );

/* Rita pie:n */

Pie( hDC, Origo.x - DiffRadius, Origo.y - DiffRadius,

Origo.x + DiffRadius, Origo.y + DiffRadius,

Start.x, Start.y, Stop.x, Stop.y );

/* Rita kompass nal */

NeedleWidth = NeedleRect.right - NeedleRect.left;

NeedleHight = NeedleRect.bottom - NeedleRect.top;

SetMapMode( hDC, MM_ANISOTROPIC );

SetViewportOrgEx( hDC, (int)(Origo.x - NeedleWidth/2.0),

(int)(Origo.y - NeedleHight/2.0), NULL );

SetViewportExtEx( hDC, NeedleWidth, NeedleHight, NULL );

Rotation = (float)(Compass[ CpIx ]->ComCourse * DEGTORAD);

NeedleXForm.eM11 = (float)cos( Rotation );

NeedleXForm.eM12 = (float)sin( Rotation );

NeedleXForm.eM21 = (float)-sin( Rotation );

NeedleXForm.eM22 = (float)cos( Rotation );

OldGraphMode = SetGraphicsMode( hDC, GM_ADVANCED );

SetWorldTransform( hDC, &NeedleXForm );

PlayMetaFile( hDC, hMFNeedle );

SetGraphicsMode( hDC, OldGraphMode );

EndPaint( hWnd, (LPPAINTSTRUCT)&ps );

danny_pav had this ...what's the effect of this

Answers2000: I don't want to move the picture just rotate it.

If i set some values in eDx and eDy the picture moves to that position it seems (upper left corner). I want it to stay in center and rotate around the center of the metafile.

Also, I think it would be better to call SetWindowExt and SetWindowOrg along with viewport functions after changing map/graphics mode. At least, that's how I did it, and all worked fine.

I´ve tried to call SetViewportExt and Org again after SetGraphicsMode and to set XFORM eDx and eDy to the center of my metafile. But that doesn´t help at all, it still rotates around the upper left corner. Probably i´ve made some misstake somewhere, but i can´t find it. I´ve increased the points to 150 cause this is important for me.

XFORM x1,x2,x3,result1,result2;

// At first, move the center of the metafile in the center

// of the world space

x1.eDx=-center.x; // Center of your metafile

x1.eDy=-center.y;

x1.eM11=1;x1.eM12=0;x1.eM2

// Next, rotate around center of the world space

x2.eDx=0;

x2.eDy=0;

x2.eM11=cos(Angle);

x2.eM12=sin(Angle);

x2.eM21=-sin(Angle);

x2.eM22=cos(Angle);

// The last, return metafile back in its place

x3.eDx=center.x;

x3.eDy=center.y;

x3.eM11=1;x3.eM12=0;x3.eM2

// Now do eral job

CombineTransform(result1,&

CombineTransform(result2,&

SetWorldTransform(dc,&resu

Good luck!

// Now do REAL job....

..

Minus is so little on screen:

x1.eDX= - center.x

x2.eDY= - center.y

My MetaFile still rotates around the upper left corner

My code is as follows:

OldGraphMode = SetGraphicsMode( hDC, GM_ADVANCED );

SetViewportOrgEx( hDC, (int)(Origo.x - NeedleWidth/2.0),

(int)(Origo.y - NeedleHight/2.0), NULL );

SetViewportExtEx( hDC, NeedleWidth, NeedleHight, NULL );

Pivot.x = (int)(NeedleWidth/2.0);

Pivot.y = (int)(NeedleHight/2.0);

// At first move the center of the metafile

// in the center of the world space

x1.eDx = -Pivot.x;

x1.eDy = -Pivot.y;

x1.eM11 = 1;

x1.eM12 = 0;

x1.eM21 = 0;

x1.eM22 = 1;

// Next rotate around center of world space

x2.eDx = 0;

x2.eDy = -Pivot.y;

x2.eM11 = (float)cos( Rotation );

x2.eM12 = (float)sin( Rotation );

x2.eM21 = (float)-sin( Rotation );

x2.eM22 = (float)cos( Rotation );

// The last, return metafile back in its place

x3.eDx = Pivot.x;

x3.eDy = Pivot.y;

x3.eM11 = 1;

x3.eM12 = 0;

x3.eM21 = 0;

x3.eM22 = 1;

// Now do real job

CombineTransform(&result1,

CombineTransform(&result2,

SetWorldTransform( hDC, &result2 );

PlayMetaFile( hDC, hMFNeedle );

SetGraphicsMode( hDC, OldGraphMode );

/* Avsluta uppdatering av klientarean */

EndPaint( hWnd, (LPPAINTSTRUCT)&ps );

Whats wrong i think you can help me if you can ther´s another 100 points there for you.

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.

If you calculate the center point of the metafile correctly, the code in my answer will rotate metafile around it's center without any problem.

Suppose, you playing metafile in rect 20,30,100,150. And, as I understood, you want to rotate it around the center of this rectangle.

If so, the center you must use in code is 60,90 ( [100-20]/2+20, [150-30]/2+30 ). And not the center of the metafile itself

(the center of the metafile is width/2,height/2 - 40,60 in our case).

Next, if you want to resize metafile, say, twice, use SetViewportExtEx(2,2). Then metafile appears rotated around its center in rect 40,60,200,300. In this case the center of the resized metafile on screen will be in 120,180 and the metafile will seem shifted to right and down (and twice size, of course).

If you want to keep the center of the metafile on screen in first point, 60,90, then use SetViewportOrgEx(60-120,90

I assume the size of window is 1,1 and its origin is 0,0.

If you have more question, feel free to write me directly to nick@rtzi.ru

By the way, the second CombineTransform is not necessary. It's enough to set x2.eDX=Pivot.x, x2.eDY=Pivot.y. Moreover, the rotation may be done in one step. But this is no so simple - it's need to apply some mathematics to fill XFORM.