Dark Bit Factory & Gravity
PROGRAMMING => Freebasic => Topic started 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.
'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$<>""
-
Cool effect dude. 8)
-
Neat 8)
-
Really nice effect there (again!) :)
-
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.
-
I'm waiting for your next prod mate. :*)
-
Hmmm, wonder how to use this to have the lens texture as the screen. or preloaded bmp?
Cheers and thanks,
Clyde
-
These lines:
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)
-
Cheers matey.
Clyde.
-
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.