Re: Rotating Bitmaps

new topic     » goto parent     » topic index » view thread      » older message » newer message

>Hello Everybody,
>
>I have a question:
>Does anyone have (or know of) a function that will rotate a
>bitmap and return the modified bitmap.
>example:
>
>function rotate_bm (sequence bm, atom angle)
>    bm = ...guts... angle ...
>    return bm
>end function
>

The following routine by Jiri Babor rotates a bitmap any angle. I'm not sure
if you find the result pleasing or not. You might also want to check out
Pete Eberlein's texturemapping demo, you can find it at his homepage. I
guess Pete's way is faster, but I have not looked at his source to see how
he does it.

Einar
-----------------------------------------------------------
function rotate(sequence s,atom a, integer c) -- Jiri Babor
-- rotate image in sequence s in its own space about its cetre.
-- a is angle of rotation, in degrees, positive in clockwise direction
-- unused locations are set to color c (transparent)
    sequence rs,xca,xsa,yca,ysa
    atom ca,sa,xc,yc,x,y
    integer lx,ly
    ly=length(s)
    lx=length(s[1])
    rs=repeat(repeat(c,lx),ly)
    xc=(lx+1)/2
    yc=(ly+1)/2
    a=0.01745329*a -- degrees to radians (pi/180)
    sa=sin(a) ca=cos(a)
    xca={} xsa={}
    for i=1 to lx do
        xca=append(xca,(i-xc)*ca)
        xsa=append(xsa,(i-xc)*sa)
    end for
    yca={} ysa={}
    for i=1 to ly do
        yca=append(yca,(i-yc)*ca)
        ysa=append(ysa,(i-yc)*sa)
    end for
    for i=1 to ly do
        for j=1 to lx do
            x=xca[j]+ysa[i]+xc+0.0001 -- to eliminate ugly rounding errors
            y=-xsa[j]+yca[i]+yc+0.0001
            if x>1 and x<lx+1 and y>1 and y<ly+1 then
                rs[i][j]=s[y][x]
            end if
        end for
    end for
    return rs
end function

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu