AndersCarlsson
asked on
How to use "SetWorldTransform"
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 ???
how about setting the XFORM eDx and eDy to the point about which rotation occurs?
ASKER
Maybe some code could help ...
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 );
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 );
ASKER
Thanks danny_pav
. but i've tried that and it doesnt work
any other suggestions ?
. but i've tried that and it doesnt work
any other suggestions ?
AndersCarlsson,
do you keep in mind that SetWorldTransform does not supported on Win 95 ?
do you keep in mind that SetWorldTransform does not supported on Win 95 ?
Use the eDx and eDy members of NeedleXForm to perform the horizontal and vertical translation (how much you want to move by).
danny_pav had this ...what's the effect of this
danny_pav had this ...what's the effect of this
ASKER
NickRepin: I work on a NT machine.
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.
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.
Try to call SetViewportExt and SetViewportOrg again after calling SetGraphicsMode.
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.
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.
ASKER
NickRepin
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.
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.
World transformation doesn't depend on Window and Viewport settings. You should rotate like this:
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 1=0;x1.eM2 2=1;
// 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 1=0;x3.eM2 2=1;
// Now do eral job
CombineTransform(result1,& x1,&x2);
CombineTransform(result2,& result1,&x 3);
SetWorldTransform(dc,&resu lt2);
Good luck!
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!
Type errors...
// Now do REAL job....
..
Minus is so little on screen:
x1.eDX= - center.x
x2.eDY= - center.y
// Now do REAL job....
..
Minus is so little on screen:
x1.eDX= - center.x
x2.eDY= - center.y
ASKER
It didn´t work NickRepin.
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, &x1, &x2 );
CombineTransform(&result2, &result1, &x3 );
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.
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.
1) x2.eDY must be 0
-------------------
2) Check result of SetGraphicsMode(GM_ADVANCE D)
-------------------
2) Check result of SetGraphicsMode(GM_ADVANCE
ASKER
OK!
1) I just followed your "Type error" comment.
2) SetGraphicsMode result is nonzero.
I tried to move the centerpoint step by step, and finally i succeeded with center.x = 252 and center.y = 640.
I don´t understand why, cause my windowsize is 125*125.
Must i set windowextension or what ?
1) I just followed your "Type error" comment.
2) SetGraphicsMode result is nonzero.
I tried to move the centerpoint step by step, and finally i succeeded with center.x = 252 and center.y = 640.
I don´t understand why, cause my windowsize is 125*125.
Must i set windowextension or what ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Another words, if I understood, instead of NeedleSize/2 use
Pivot=Origo
Pivot=Origo