Author Topic: Rotate an image  (Read 5766 times)

0 Members and 1 Guest are viewing this topic.

Offline unatic

  • Newbie
  • Posts: 2
  • God looks after small children and old fools!
    • View Profile
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

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
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
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
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 »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
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

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
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: QB64: [Select]
  1. 'notes: X, Y is the place where you want the center of the image to go
  2. ' image is the image handle number
  3. ' xScale and yScale: if you want the image the same size as file image use 1, half the size use .5
  4. ' twice the size use 2... this allows you to stretch/shrink an image into a rectangle area any size
  5. ' Rotation is an angle in Degrees units: 0 degrees is due East (as file image) 270 degrees is due North....
  6. SUB RotoZoom2 (X AS LONG, Y AS LONG, Image AS LONG, xScale AS SINGLE, yScale AS SINGLE, Rotation AS SINGLE)
  7.     DIM px(3) AS SINGLE: DIM py(3) AS SINGLE
  8.     W& = _WIDTH(Image&): H& = _HEIGHT(Image&)
  9.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
  10.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
  11.     sinr! = SIN(-Rotation / 57.2957795131): cosr! = COS(-Rotation / 57.2957795131)
  12.     FOR i& = 0 TO 3
  13.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * xScale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * yScale + Y
  14.         px(i&) = x2&: py(i&) = y2&
  15.     NEXT
  16.     _MAPTRIANGLE (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  17.     _MAPTRIANGLE (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  18.  

EDIT: forgot to make yScale as Single
« Last Edit: June 17, 2018, 02:59:40 pm by bplus »

Offline unatic

  • Newbie
  • Posts: 2
  • God looks after small children and old fools!
    • View Profile
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

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
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.