I was asked for a solution to draw fancy skies in combination with raycasting on the naalaa forum. So I wrote these lines of code that creates some lookups for rendering an image on the inside of a cylinder:
' 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
The attachment contains the sourcecode, assets and an executable.
I know that naalaa is not a live language in these neighborhoods, but the only weird thing in the code above, that possibly couldn't be directly translated to other languages, is the 'draw vraster' command. 'draw vraster' and 'draw hraster' simply draws textured vertical and horizontal lines.