image scaling & rotation

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

On Thu, 2 Oct 1997 Robert B Pilkington wrote:

>>the rotate_image() function below is something I cooked up last night
>>for Einar Mogen. It rotates an image in its own space about its centre.

>I know this reply is VERY late........
>But I was thinking, most programs need to have a picture of each possible
>rotation, so that it can display all the rotations for the picture. (Like
>a top-down racing game like Super Sprint or Micro Machines.)
>If a rotate routine that works perfectly, even slowly, like those in
>paint programs, were to just save the information to a look up table,
>then each rotation could be accessed as if they were loaded up from the
>file normally. But only one image would be needed!

I know this reply is VERY, VERY late...
But the routine below is much better than the original one, and it
might just do what you wanted. I am also attaching a rescale function
that can be used to resize (remap) any rectangular image.

I realize all that can be done using Pete's marvelous texture mapping
routine, but if you need a simple tool... Jiri


-- snip ------------------------------------------------------------------------

function rotate(sequence s,atom a, integer c)
   -- 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

function rescale(sequence os,integer nw,integer nh)
   -- resize (remap) rectangular image os
   -- to new width nw, and new height nh
   sequence ns
   atom dx,dy,x,y
   integer oh,ow
   ns=repeat(repeat(0,nw),nh)
   oh=length(os)
   ow=length(os[1])
   dx=ow/nw
   dy=oh/nh
   y=1
   for i=1 to nh do
      x=1
      for j=1 to nw do
         ns[i][j]=os[y][x]
         x=x+dx
      end for
      y=y+dy
   end for
   return ns
end function

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

Search



Quick Links

User menu

Not signed in.

Misc Menu