Warp Speed

Post Reply
Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

Warp Speed

Post by Operator »

After several tries :)
Any suggestions or improvements are welcome,
I'm still learning !! Enjoy...


Rem Warp Speed using perspective projection
Rem ported and expanded sample out off:
Rem http://www.o-bizz.de/qbtuts/3dtut1.zip (German)
Rem SB V3.3, iPad Mini 1. Gen. / iOS 7.0.4
Rem by Operator
Rem .....

option base 1
option angle degrees
Graphics
Draw Color 1,1,1

start:
t_out = 0 'time out, sequence
free_spot = 150 'star creation out of this range
focus = 2000.001 'distance of observer to "window"
max_stars = 120 'reduce or expand to play around
stars_speed = 3
stars_far_speed = 6*stars_speed
warp_speed = 8.5*stars_speed
x = 1 ! y = 2 ! z = 3
sch = Screen_Height()
scw = Screen_Width()
y_offset = sch/2
x_offset = scw/2

Dim stars(max_stars,3) '3-> x,y,z
Dim stars_far(max_stars,1) '1-> z_far

'preload stars array with initial star position
'x,y,z avoiding stars near the focal axis
For i = 1 to max_stars
alfa = rnd(360)
stars(i,x) = (free_spot+rnd(300)) * cos(alfa)
stars(i,y) = (free_spot+rnd(300)) * sin(alfa)
stars(i,z) = 300 + rnd(400)
next i


t = Timer()
Do
Graphics Lock
Graphics Clear

For i = 1 to max_stars
'apply perspective projection
x_p = -(stars(i,x)*focus/(stars(i,z)+focus)) + x_offset
y_p = -(stars(i,y)*focus/(stars(i,z)+focus)) + y_offset

'draw stars, star size distance (z) dependant, reducing focus to move them
'a bit faster
if t_out = 0 Then
Fill Rect x_p,y_p Size 6*80/(stars(i,z)+80)
focus += 0.5
end if

'move stars
stars(i,z) -= stars_speed

'after some time remember actual star z-pos
'to start warp effect
if Timer()-t >= 2000 AND t_out = 0 Then
for ii = 1 to max_stars
stars_far(ii,1) = stars(ii,z)
next ii
t_out = 1
end if

if t_out = 1 Then
'apply pers. proj. to far stars and reduce focus to min 100
focus = focus -50
if focus <= 100 Then focus = 100
x_pfar = -(stars(i,x)*focus/(stars_far(i,1) + focus)) + x_offset
y_pfar = -(stars(i,y)*focus/(stars_far(i,1) + focus)) + y_offset

'draw lines (far star to actual star position)
drawsize_star_line = 1*100/(abs(stars(i,z)+100.1))
Draw Size drawsize_star_line
Draw Line x_pfar, y_pfar TO x_p, y_p
stars_far(i,1) -= stars_far_speed

'increase star speed
stars_speed += 0.1
if stars_speed > warp_speed Then
stars_speed = warp_speed
end if
end if

'reset star (z) position and its corresponding star_far (z) pos.
if stars(i,z)< -50 AND t_out = 1 Then
stars(i,z) = 200 + rnd(300)
stars_far(i,1) = stars(i,z)+300

'trigger reinitiation
iiii += 1
if iiii >= max_stars*2 Then
graphics clear 1,1,1
graphics unlock
iiii = 0
goto start
end if
end if
next i

Graphics Unlock
Until Timer() - t >= 700000
end
Attachments
image.jpg
image.jpg (14.67 KiB) Viewed 2584 times

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Warp Speed

Post by Henko »

Nice done! Are you programming "star trek" ?

Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

Re: Warp Speed

Post by Operator »

Thx., no not at all, my son just has Star War's
fever and got it a try looking at 100 youtube
videos of warp speed or light speed jump
effects...

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Warp Speed

Post by Mr. Kibernetik »

Very interesting!
I was playing with it all night long... :lol:

BTW, have you tried a game "EVE Online"? It is all dedicated to this effect and star wars!

Post Reply