Dark Bit Factory & Gravity

PROGRAMMING => Freebasic => Topic started by: relsoft on May 11, 2006

Title: Radial Displaced Lensmapping
Post by: relsoft on May 11, 2006
For those who wondered how I made the flower tunnel in ASM, here's an example of the radial displacement I used.


Code: [Select]
'lens mapping with style
'sat this morning and made this
'never thought it would be this easy.
'relsoft 2006
'rel.betterwebber.com
option explicit
const SCR_WIDTH = 320 * 1
const SCR_HEIGHT = 240 * 1

const PI = 3.141593

const XMID = SCR_WIDTH \ 2
const YMID = SCR_HEIGHT \ 2
const radius = 64

cls
screen 14,,2

  Â  
  Â  dim wid, hei as integer
  Â  dim hypotsquared, radiussquared, h as integer
  Â  dim sx, sy, x1, y1, yt, xt as integer
  Â  dim px, py as integer
  Â  dim minx, miny as integer
  Â  dim pixel as integer
  Â  dim wtemp, htemp as integer
  Â  dim sphereheight, cleaner as integer
  Â  dim angle as single
  Â  dim frame as single

  Â  sphereheight = (radius shr 1)
  Â  cleaner = sphereheight * 10

  Â  RadiusSquared = Radius * Radius

  Â  wid = Radius shl 1
  Â  hei = Radius shl 1

  Â  dim  as single fold_off = 0.02
  Â  dim  as single fold_scale = 0.07' * sin(timer / 512.0)
  Â  dim  as integer fold_num = 3
  Â  dim  as integer min_fold_num = 3
  Â  dim  as integer fold_counter = 0
  Â  dim  as integer old_scale_sign = 0
  Â  dim  as integer x, y
  Â  x = 90
  Â  y = 50
  Â  old_scale_sign = sgn(.5 * sin(timer / 4))
do
  Â  screenset 1, 0

  Â  line(0,0)-(319,239),0,bf
  Â  
  Â  frame +=1
  Â  fold_off += 0.2  Â  
  Â  fold_scale = .5 * sin(timer / 4)
  Â  if sgn(fold_scale*10) <> old_scale_sign then
  Â  Â  Â  fold_num = (fold_num+1) mod 6
  Â  Â  Â  old_scale_sign = sgn(fold_scale*10)
  Â  end if


FOR yt = -(radius\2) TO hei - 1 + (radius\1)
 FOR xt = -(radius\2) TO wid - 1 + (radius\1)
  Â  Â  x1 = (xt - Radius)
  Â  Â  y1 = (yt - Radius)

  Â  Â  HypotSquared = (x1 * x1) + (y1 * y1)
  Â  Â  angle = atan2(y1,x1)
  Â  Â  HypotSquared = (HypotSquared) * (((sin((fold_off+PI) + (fold_num) * angle)) * fold_scale)+1)
  Â  Â  'try this
  Â  Â  'HypotSquared = (HypotSquared) * (((sin((fold_off+PI) + (min_fold_num+fold_num) * angle)) * fold_scale)+1)
  Â  Â  IF HypotSquared < (RadiusSquared - Cleaner) THEN
  Â  Â  Â H = (Sqr(RadiusSquared - HypotSquared))  Â  Â  Â  
  Â  Â  Â Sx = (SphereHeight - H)
  Â  Â  Â Sy = (SphereHeight - H)
  Â  Â  Â Sx = Sx * ((x1 shl 16) \ H)
  Â  Â  Â Sy = Sy * ((y1 shl 16) \ H)
  Â  Â  Â py = ((Sy shr 16) + yt +x)
  Â  Â  Â px = ((Sx shr 16) + xt +y)
  Â  Â  Â pset(xt+x,yt+y), px xor py
  Â  Â  END IF
 NEXT xt
NEXT yt

  Â  screensync
  Â  screencopy

loop until inkey$<>""
Title: Re: Radial Displaced Lensmapping
Post by: Clyde on May 11, 2006
Cool effect dude. 8)
Title: Re: Radial Displaced Lensmapping
Post by: Rbz on May 11, 2006
Neat  8)
Title: Re: Radial Displaced Lensmapping
Post by: Shockwave on May 11, 2006
Really nice effect there (again!) :)
Title: Re: Radial Displaced Lensmapping
Post by: Optimus on May 16, 2006
I like lens mapping. This is so cool. Looks like one of ideas I wanted to code, lens that is not just a sphere but changes shapes and to experiment with new stuff (e.g. lens blobs on a background would be neat), I never did.
Title: Re: Radial Displaced Lensmapping
Post by: relsoft on May 16, 2006
I'm waiting for your next prod mate. :*)
Title: Re: Radial Displaced Lensmapping
Post by: Clyde on May 18, 2006
Hmmm, wonder how to use this to have the lens texture as the screen. or preloaded bmp?

Cheers and thanks,
Clyde
Title: Re: Radial Displaced Lensmapping
Post by: relsoft on May 19, 2006
These lines:

Code: [Select]
py = ((Sy shr 16) + yt +x)
 px = ((Sx shr 16) + xt +y)
 pset(xt+x,yt+y), px xor py



PX and PY would represent your texture coord.  so if you want to use a texture:

Assuming your texture is (256*256)

 py = ((Sy shr 16) + yt +x) and 255
 px = ((Sx shr 16) + xt +y) and 255
 pset(xt+x,yt+y), texture(px,py)
Title: Re: Radial Displaced Lensmapping
Post by: Clyde on May 19, 2006
Cheers matey.
Clyde.
Title: Re: Radial Displaced Lensmapping
Post by: Clyde on May 20, 2006
How would the example project that you did with the spherical lens mapping be adapted to use this wonderfull awesome, Radial Spherical map. As I've a real neat idea for a demo using this Radial Displaced mapping.

If you could show us, that would be awesome of you dude.

Cheers and many thanks,
Clyde.