• Welcome to Dark Bit Factory & Gravity.
 

Radial Displaced Lensmapping

Started by relsoft, May 10, 2006

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

relsoft

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$<>""
Challenge Trophies Won:

Clyde

Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Rbz

Challenge Trophies Won:

Shockwave

Really nice effect there (again!) :)
Shockwave ^ Codigos
Challenge Trophies Won:

Optimus

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.
Challenge Trophies Won:

relsoft

I'm waiting for your next prod mate. :*)
Challenge Trophies Won:

Clyde

Hmmm, wonder how to use this to have the lens texture as the screen. or preloaded bmp?

Cheers and thanks,
Clyde
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

relsoft

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)
Challenge Trophies Won:

Clyde

Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

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.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won: