Author Topic: Rotate an image  (Read 627 times)

Offline unatic

  • God looks after small children and old fools!
Rotate an image
« on: June 16, 2018, 06:41:08 PM »
Using the sample program,  I have been able to flip an image in both directions, but I am unable to figure out how to rotate the image by 90 degrees.  I am using the _PUTIMAGE but have not been able to figure this out.  Any help would be appreciated.
I'm the one that has to die when it's time for me to die, so let me live my life, the way I want to.

Jimi Hendrix

Offline Ashish

  • The joy of coding is endless.
Re: Rotate an image
« Reply #1 on: June 17, 2018, 12:21:37 AM »
Hi unatic!
See Example #1 of this page - http://qb64.org/wiki/MAPTRIANGLE
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories

Re: Rotate an image
« Reply #2 on: June 17, 2018, 11:10:31 AM »
Here is my test code for RotoZoom2 with independent scales for X and Y:
« Last Edit: June 17, 2018, 11:20:38 AM by bplus »
B = B + ...

Re: Rotate an image
« Reply #3 on: June 17, 2018, 01:06:46 PM »
Good work Bplus, so now just add background shift in Y axis and enemies and game is done :-D

Re: Rotate an image
« Reply #4 on: June 17, 2018, 02:54:39 PM »
To make the sub even easier to use I have written up some notes for it:
Code: [Select]
'notes: X, Y is the place where you want the center of the image to go
' image is the image handle number
' xScale and yScale: if you want the image the same size as file image use 1, half the size use .5
' twice the size use 2... this allows you to stretch/shrink an image into a rectangle area any size
' Rotation is an angle in Degrees units: 0 degrees is due East (as file image) 270 degrees is due North....
SUB RotoZoom2 (X AS LONG, Y AS LONG, Image AS LONG, xScale AS SINGLE, yScale AS SINGLE, Rotation AS SINGLE)
    DIM px(3) AS SINGLE: DIM py(3) AS SINGLE
    W& = _WIDTH(Image&): H& = _HEIGHT(Image&)
    px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
    px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
    sinr! = SIN(-Rotation / 57.2957795131): cosr! = COS(-Rotation / 57.2957795131)
    FOR i& = 0 TO 3
        x2& = (px(i&) * cosr! + sinr! * py(i&)) * xScale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * yScale + Y
        px(i&) = x2&: py(i&) = y2&
    NEXT
    _MAPTRIANGLE (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
    _MAPTRIANGLE (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
END SUB

EDIT: forgot to make yScale as Single
« Last Edit: June 17, 2018, 02:59:40 PM by bplus »
B = B + ...

Offline unatic

  • God looks after small children and old fools!
Re: Rotate an image
« Reply #5 on: June 17, 2018, 08:37:27 PM »
Thanks for the information and pointers!  I just did not look deep enough at the image functions in QB64.  I will study these samples and after I understand them, I will incorporate the functionality into my program.  Again, thank you!!
I'm the one that has to die when it's time for me to die, so let me live my life, the way I want to.

Jimi Hendrix

Re: Rotate an image
« Reply #6 on: June 18, 2018, 09:10:05 AM »
Ha, yeah, I remember the first time I looked at RotoZoom sub... yikes! a head scratcher until you realize it draws a rectangular image by drawing two triangles: 2 edges and the diagonal, then the other 2 edges and same diagonal. To do that, it calculates the (x, y) points at corners for the triangles at drawing surface. The mapping then takes all points in triangle of image and translates them to triangle on drawing surface.
B = B + ...