Jump to content
  • Advertisement
Sign in to follow this  
cambalinho

VB6 - GDIPLUS: how rotate an image on center?

This topic is 658 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

how can i rotate an image on it's center?

Dim i As Integer
        For i = 0 To 360
            GdipTranslateWorldTransform hGraphics, 100, 100, MatrixOrderAppend
            GdipRotateWorldTransform hGraphics, 45!, MatrixOrderPrepend
            GdipTranslateWorldTransform hGraphics, -100, -100, MatrixOrderAppend
            GdipDrawImageRectRect hGraphics, HBITMAP, 100, 100, lngwidth, lngheight, 0, 0, lngwidth, lngheight, UnitPixel, ImageAttributes
            Sleep 500
        Next

that code can draw the image rotated. but it's drawed on several positions instead on it's center :(

can anyone advice me?

Share this post


Link to post
Share on other sites
Advertisement

Never done VB6 or GDIPLUS, but the normal trick is to first translate the center of the image to the origin, then rotate, then translate back to were it was.

(Rotation rotates around origin, so if your image is not there, it moves.)

Share this post


Link to post
Share on other sites
Is this happening because it's not erasing the old image?

Because it's not erasing, you get several of the image rotated around a pivot point.

On an important side note is there a legitimate reason you are using vb6, which hasnt been supported by Microsoft for decades, when there are better free options like visual studio community 2015?

Share this post


Link to post
Share on other sites

Why are you translating to (100,100)? You first need to translate to the origin (0,0), rotate and then translate back to the original position. Rotation is based around (0,0) unless the math library does some really weird and unexpected work in the background.

 

[edit] Is the initial position at (-100,-100)? That's the only way I can make sense of this.

Edited by MarkS

Share this post


Link to post
Share on other sites
The image is rotating, just around a pivot near the top left of the window rather than the centre of the image.

What are the actual image dimensions, and could this be related to the 100,100 in your code above?

Share this post


Link to post
Share on other sites

i'm sorry... the 100X100 is the position where i must draw the image. so the 1st image is drawed on correct position. the next image isn't.

i'm trying learning, from several places, how use the rotate. but seems so complicate without understand it :(

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!