' Sky cylinder.

set window 32, 32, 640, 360

' Load a sky image. This image can be of any size. The image will be mapped to
' the inside of a cylinder.
load image 1, "sky.png"

' Field of view.
fov# = 90.0

' Create some lookup tables.
w = width(primary)
h = height(primary)
hw = w/2
hh = h/2
unit# = float(hw)/tan(fov*0.5)
angleOffset#[w]
cylHeight[w]
for x = 0 to hw - 1
	angleOffset[hw + x] = atan(float(x)/unit)
	angleOffset[hw - 1 - x] = -angleOffset[hw + x]	
	cylHeight[hw + x] = int(float(h)/cos(angleOffset[hw + x]))
	cylHeight[hw - 1 - x] = cylHeight[hw + x]
next

' Player's angle.
viewAngle# = 0.0

set redraw off

do
	' Increase angle.
	viewAngle = viewAngle + 1.0
	_WrapAngle viewAngle

	' Set alpha to 0, since the alpha channel represents the "fog density"
	' when using the raster commands.
	set color 255, 255, 255, 0

	' Draw.	
	for x = 0 to w - 1
		tileHeight = cylHeight[x]
		a# = viewAngle + angleOffset[x]
		_WrapAngle a
		u# = a/360.0
		draw vraster 1, x, hh - tileHeight/2, hh + tileHeight/2, u, 0.0, u, 1.0
	next

	redraw
	wait 16
loop

procedure WrapAngle(&a#)
	while a < 0.0; a = a + 360.0; wend
	while a > 360.0; a = a - 360.0; wend
endproc
