Rotate and zoom part of an image
#1
Hi all! I am trying to have a Sub which can display the part of an image rotated and in a certain angle.
I know this can be achieved with MAPTRIANGLE, I found a rotozoomer posted by Galleon on qb64.org. But it can not display the part of an image.
So I fiddled around and came close to what I want to have, but I got problems with the scaling.
First my SUB:
Code:
SUB RotoZoom (X AS INTEGER, Y AS INTEGER, Image AS LONG, startx AS INTEGER, starty AS INTEGER, xoffset AS INTEGER, yoffset AS INTEGER, Scale AS SINGLE, Rotation AS SINGLE)
   DIM px(3) AS SINGLE: DIM py(3) AS SINGLE
   W& = _WIDTH(Image&: H& = _HEIGHT(Image&
   px(0) = -xoffset / 2: py(0) = -yoffset / 2: px(1) = -xoffset / 2: py(1) = yoffset / 2
   px(2) = xoffset / 2: py(2) = yoffset / 2: px(3) = xoffset / 2: py(3) = -yoffset / 2
   sinr! = SIN(-Rotation / 57.2957795131): cosr! = COS(-Rotation / 57.2957795131)
   FOR i& = 0 TO 3
       x2& = (px(i& * cosr! + sinr! * py(i& * Scale + X: y2& = (py(i& * cosr! - px(i& * sinr!) * Scale + Y
       px(i& = x2&: py(i& = y2&
   NEXT
   _MAPTRIANGLE (startx, starty)-(startx, yoffset - 1)-(xoffset - 1, yoffset - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
   _MAPTRIANGLE (startx, starty)-(xoffset - 1, starty)-(xoffset - 1, yoffset - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
END SUB

Next I post an image of the bitmap font I want to draw:
.bmp   font186.bmp (Size: 191.3 KB / Downloads: 77)

Now how I call the SUB - please note that the scale is always 1 ...
Code:
   RotoZoom 100, 100, player&, 0, 0, 40, 34, 1, 0
   RotoZoom 200, 100, player&, 40, 0, 80, 34, 1, 0
   RotoZoom 300, 100, player&, 40, 34, 80, 68, 1, 0

And here's the result ... As you see the farther I move into the image, the bigger the resulting image becomes.


What am I doing wrong here?
Reply
#2
Ok guys, I found the solution myself ...
The following code works (only the SUB):

Code:
SUB RotoZoom (X AS INTEGER, Y AS INTEGER, Image AS LONG, startx AS INTEGER, starty AS INTEGER, xoffset AS INTEGER, yoffset AS INTEGER, Scale AS SINGLE, Rotation AS SINGLE)
   DIM px(3) AS SINGLE: DIM py(3) AS SINGLE
   W& = _WIDTH(Image&: H& = _HEIGHT(Image&
   px(0) = (-xoffset + startx) / 2: py(0) = (-yoffset + starty) / 2: px(1) = (-xoffset + startx) / 2: py(1) = (yoffset - starty) / 2
   px(2) = (xoffset - startx) / 2: py(2) = (yoffset - starty) / 2: px(3) = (xoffset - startx) / 2: py(3) = (-yoffset + starty) / 2
   sinr! = SIN(-Rotation / 57.2957795131): cosr! = COS(-Rotation / 57.2957795131)
   FOR i& = 0 TO 3
       x2& = (px(i& * cosr! + sinr! * py(i& * Scale + X: y2& = (py(i& * cosr! - px(i& * sinr!) * Scale + Y
       px(i& = x2&: py(i& = y2&
   NEXT
   _MAPTRIANGLE (startx, starty)-(startx, yoffset - 1)-(xoffset - 1, yoffset - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
   _MAPTRIANGLE (startx, starty)-(xoffset - 1, starty)-(xoffset - 1, yoffset - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
END SUB

No I can start with my AstroRocks (Asteroids clone) for QB64 ... since it is now possible to rotate a sprite animation. :D
Reply
#3
Sorry, I couldn't been of help. It seems you are farther along with this _MAPTRIANGLE thing than I, plus you are more into game sprites than I...

I am surprised no one could help, maybe try QB64.net or QB64.org for expert help next time, Walter seems too tied up with forum pioneering I guess.

PS I am also wondering why GET and PUT were not used, I thought those dealt with image manipulations. That _MAPTRIANGLE sub must be one very flexible routine!
B += x
Reply
#4
Hi. I see to it, BUT in code missing brackets. I use not TJP QB64 IDE.
Reply
#5
Try it.

Code:
SCREEN _NEWIMAGE(640, 480, 32)
player& = _LOADIMAGE("font186.bmp", 32)
DO UNTIL _KEYHIT
    RotoZoom 100, 100, player&, 0, 0, 40, 34, 1, F
    RotoZoom 200, 100, player&, 40, 0, 80, 34, 1, -F
    RotoZoom 300, 100, player&, 40, 34, 80, 68, 4, F
    _DISPLAY
    CLS
    F = F + .1

LOOP




SUB RotoZoom (X AS INTEGER, Y AS INTEGER, Image AS LONG, startx AS INTEGER, starty AS INTEGER, xoffset AS INTEGER, yoffset AS INTEGER, Scale AS SINGLE, Rotation AS SINGLE)
    DIM px(3) AS SINGLE: DIM py(3) AS SINGLE
    W& = _WIDTH(Image&): H& = _HEIGHT(Image&)
    px(0) = (-xoffset + startx) / 2: py(0) = (-yoffset + starty) / 2: px(1) = (-xoffset + startx) / 2: py(1) = (yoffset - starty) / 2
    px(2) = (xoffset - startx) / 2: py(2) = (yoffset - starty) / 2: px(3) = (xoffset - startx) / 2: py(3) = (-yoffset + starty) / 2
    sinr! = SIN(-Rotation / 57.2957795131): cosr! = COS(-Rotation / 57.2957795131)
    FOR i& = 0 TO 3
        x2& = Scale * (px(i&) * cosr! + sinr! * py(i&)) + X: y2& = Scale * (py(i&) * cosr! - px(i&) * sinr!) + Y
        px(i&) = x2&: py(i&) = y2&
    NEXT
    _MAPTRIANGLE (startx, starty)-(startx, yoffset - 1)-(xoffset - 1, yoffset - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
    _MAPTRIANGLE (startx, starty)-(xoffset - 1, starty)-(xoffset - 1, yoffset - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
END SUB
Reply