1. Rotating Bitmaps

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

Important points for me is:
      I.   MINIMAL or NO image corruption
      II.  fast function execution
      III. no need for me to know memory addresses and the like

What I'm doing is a game where I want to have bm sprites
of characters facing one direction but in different positions.
The rotate function would take care of the rest.

TIA,
Lewis Townsend
|\      ____ _     _     _ _    __
| \    | __/ ||   / |   // || / __ \
|  \   ||_   ||  //||  //  || ||__\|
|   \  | _|  || // || //   || \___ \
| |\ \ ||__  ||//  ||//    || |\__||
| | \ \|___\ |_/   |_/     || \____/
| |  \ \      _____    _______
| |   \ \     | __ \  | _   _ |
| |    \ \    ||__||  |/ | | \|
| |     \ \   | __ /     | |
| |______\ \  ||  \\     | |
|___________\ ||  ||     |_|
Keroltarr at hotmail.com

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

new topic     » topic index » view message » categorize

2. Re: Rotating Bitmaps

>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 message » categorize

3. Re: Rotating Bitmaps

Hello again,

>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

Thanks a lot Einar, and Jiri of course (and anyone else that
is going to respond before I get this letter out).  I have
seen Pete's texturemapping demo and tried it but it requires
memory addresses and the four corners of the bm as coords.
It also requires that the foreground and background images be
in the same bitmap I think.  And all I want is the foreground
(I can take care of the masking or let mode X do it for me).

Thanks again everybody, and I hope to have a game done
sometime. :)

Sincerely,
Lewis Townsend
|\      ____ _     _     _ _    __
| \    | __/ ||   / |   // || / __ \
|  \   ||_   ||  //||  //  || ||__\|
|   \  | _|  || // || //   || \___ \
| |\ \ ||__  ||//  ||//    || |\__||
| | \ \|___\ |_/   |_/     || \____/
| |  \ \      _____    _______
| |   \ \     | __ \  | _   _ |
| |    \ \    ||__||  |/ | | \|
| |     \ \   | __ /     | |
| |______\ \  ||  \\     | |
|___________\ ||  ||     |_|
Keroltarr at hotmail.com

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

new topic     » goto parent     » topic index » view message » categorize

4. Re: Rotating Bitmaps

Hello,

Thanks again to Jiri and Einar for the bitmap rotating
routine.  I renamed it to "rotatebm" to avoid conflicts.
It isn't perfect for small bitmaps (sprites) but it's good
enough.  If you want to see some really funky image
corruption try something like this:

--untested code (at least this version)
--you'll need to define bm and the rotate funcion
--and include graphics.e

bm = read_bitmap ("bitmap.bmp")
all_palette (bm [1])
bm = bm [2]
while get_key() != 27 do
    display_image(bm, {0, 0}) --or is that ({0,0},bm) ?
    bm = rotatebm(bm, 10, 0)
end while

-- end untested code

I haven't tried it with bigger images but this looks so
cool that I think it could find a home in a screen saver
or some such thing. :)

I am now actually getting something done on my "Balenfaire" game.  It
should be playable by Monday but I'm not promising anything. smile

Sincerely,
Lewis Townsend
|\      ____ _     _     _ _    __
| \    | __/ ||   / |   // || / __ \
|  \   ||_   ||  //||  //  || ||__\|
|   \  | _|  || // || //   || \___ \
| |\ \ ||__  ||//  ||//    || |\__||
| | \ \|___\ |_/   |_/     || \____/
| |  \ \      _____    _______
| |   \ \     | __ \  | _   _ |
| |    \ \    ||__||  |/ | | \|
| |     \ \   | __ /     | |
| |______\ \  ||  \\     | |
|___________\ ||  ||     |_|
Keroltarr at hotmail.com

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu