Posts: 480
Threads: 24
Joined: Mar 2003
i've been learning about this POKE thing, and starting to understand the mechanics of the program. here's a quicker update:
Code: '$DYNAMIC
DEFINT A-Z
DIM PIC(63, 63)
DIM buffer(32001) AS INTEGER
DIM Sine(1920) AS SINGLE, Cosine(1920) AS SINGLE
DIM Raylength(99) AS INTEGER
t# = TIMER
CameraHeight = 100
CameraDistance = 128
FOR i# = 0 TO 6.28165 STEP 6.28165 / 1920
Sine(a) = SIN(i#)
Cosine(a) = COS(i#)
a = a + 1
NEXT i#
FOR y = 0 TO 63
FOR x = 0 TO 63
PIC(x, y) = COS(x / 30) * SIN(y / 30) * 4 + 24
NEXT x
NEXT y
FOR y = 0 TO 99
Raylength(y) = (CameraHeight / (CameraHeight - y)) * CameraDistance
NEXT y
SCREEN 13
buffer(0) = 2560: buffer(1) = 200
DEF SEG = VARSEG(buffer(0))
DO
PlayerY = PlayerY + 10
FOR y = 0 TO 99 STEP 2
FOR x = 0 TO 159 STEP 2
xang = 320 + x
vx = (ABS(Raylength(y) * Cosine(xang))) AND 63
vy = (PlayerY + Raylength(y) * Sine(xang)) AND 63
m = 320 * (99 - y)
POKE 32004& - m + x, (PIC(vx, vy))
POKE 32004& - m + (318 - x), (PIC(vx, vy))
POKE 32004& + m + x, (PIC(vx, vy))
POKE 32004& + m + (318 - x), (PIC(vx, vy))
NEXT x
NEXT y
frames& = frames& + 1
PUT (0, 0), buffer, PSET
FOR y = 1 TO 99 STEP 2
FOR x = 1 TO 159 STEP 2
m = 320 * (99 - y)
c = (POINT(x - 1, y) + POINT(x + 1, y) + POINT(x - 1, y + 2) + POINT(x + 1, y + 2)) / 4
POKE 32004& - m + x, c
POKE 32004& - m + (318 - x), c
POKE 32004& + m + x, c
POKE 32004& + m + (318 - x), c
NEXT x
NEXT y
PUT (0, 0), buffer, PSET
FOR y = 1 TO 99
FOR x = y MOD 2 TO 159 STEP 2
m = 320 * (99 - y)
IF x MOD 2 THEN
c = (POINT(x + 1, y) + POINT(x - 1, y)) / 2
ELSE
c = (POINT(x, y + 1) + POINT(x, y - 1)) / 2
END IF
POKE 32004& - m + x - 320, c
POKE 32004& - m + (320 - x) - 320, c
POKE 32004& + m + x + 320, c
POKE 32004& + m + (320 - x) + 320, c
NEXT x
NEXT y
PUT (0, 0), buffer, PSET
LOOP UNTIL INKEY$ <> ""
COLOR 63: PRINT frames& / (TIMER - t#)
SYSTEM
next task is to figure out how to do the math without using the POINT command (thereby only having to do the PUT command once at the end of each loop). This would increase performance, but I'm not sure how to do the math. But I hope you get the main idea of this one.. doing a STEP 2, STEP 2 loop, then filling in the spaces between them with the averages of the colors around them.
*peace*
Meg.
Posts: 1,166
Threads: 62
Joined: Apr 2003
I fixed the points with PEEK, but it has strange black dots through the middles of the screen (x and y)
It has strange colors compiled too, but not in the IDE... I don't get it
Code: '$DYNAMIC
DEFINT A-Z
DIM PIC(63, 63)
DIM buffer(32001) AS INTEGER
DIM Sine(1920) AS SINGLE, Cosine(1920) AS SINGLE
DIM Raylength(99) AS INTEGER, ysl(199) AS LONG
FOR i = 0 to 199
ysl(i)=320&*i+4
NEXT
t# = TIMER
CameraHeight = 100
CameraDistance = 128
FOR i# = 0 TO 6.28165 STEP 6.28165 / 1920
Sine(a) = SIN(i#)
Cosine(a) = COS(i#)
a = a + 1
NEXT i#
FOR y = 0 TO 63
FOR x = 0 TO 63
PIC(x, y) = COS(x / 30) * SIN(y / 30) * 4 + 24
NEXT x
NEXT y
FOR y = 0 TO 99
Raylength(y) = (CameraHeight / (CameraHeight - y)) * CameraDistance
NEXT y
SCREEN 13
buffer(0) = 2560: buffer(1) = 200
DEF SEG = VARSEG(buffer(0))
DO
PlayerY = PlayerY + 10
FOR y = 0 TO 99 STEP 2
FOR x = 0 TO 159 STEP 2
xang = 320 + x
vx = (ABS(Raylength(y) * Cosine(xang))) AND 63
vy = (PlayerY + Raylength(y) * Sine(xang)) AND 63
m = 320 * (99 - y)
POKE 32004& - m + x, (PIC(vx, vy))
POKE 32004& - m + (318 - x), (PIC(vx, vy))
POKE 32004& + m + x, (PIC(vx, vy))
POKE 32004& + m + (318 - x), (PIC(vx, vy))
NEXT x
NEXT y
frames& = frames& + 1
PUT (0, 0), buffer, PSET
FOR y = 1 TO 99 STEP 2
FOR x = 1 TO 159 STEP 2
m = 320 * (99 - y)
c = (PEEK (x + ysl(y)-1 ) + PEEK(x + ysl(y)+1 ) + PEEK(x + ysl(y+1)-1 ) + PEEK(x + ysl(y+2)+1 )) / 4
POKE 32004& - m + x, c
POKE 32004& - m + (318 - x), c
POKE 32004& + m + x, c
POKE 32004& + m + (318 - x), c
NEXT x
NEXT y
PUT (0, 0), buffer, PSET
FOR y = 1 TO 99
FOR x = y MOD 2 TO 159 STEP 2
m = 320 * (99 - y)
IF x MOD 2 THEN
c = (PEEK(x +ysl(y)+ 1) + PEEK(x +ysl(y)- 1)) / 2
ELSE
c = (PEEK(x+ ysl(y + 1)) + PEEK(x+ysl( y - 1))) / 2
END IF
POKE 32004& - m + x - 320, c
POKE 32004& - m + (320 - x) - 320, c
POKE 32004& + m + x + 320, c
POKE 32004& + m + (320 - x) + 320, c
NEXT x
NEXT y
PUT (0, 0), buffer, PSET
LOOP UNTIL INKEY$ <> ""
COLOR 63: PRINT frames& / (TIMER - t#)
SYSTEM
am an asshole. Get used to it.
Posts: 788
Threads: 53
Joined: Nov 2002
Alright this is interpolation
Code: defint a-z
const dist = 128
const hght = 100
const pi = 3.14159265359#
dim vwrang as integer
dim x as integer, y as integer
dim i as integer, ptr as integer
dim vwrx as single, vwry as single
dim frames as single
dim tmrIni as single, tmrEnd as single
dim u1 as single, u2 as single
dim v1 as single, v2 as single
dim dudx as single, dvdx as single
dim curu as single, curv as single
dim keyb as string
dim ray( 99 ) as single
dim cosTB( 1920 ) as single
dim sinTB( 1920 ) as single
dim textr( 63, 63 ) as integer
''
'' Setup
''
screen 13
for i = 0 to 1920
cosTB(i) = cos( (pi / 960.0) * i )
sinTB(i) = sin( (pi / 960.0) * i )
next i
for y = 0 to 63
for x = 0 to 63
textr(x, y) = x xor y
next x
next y
for i = 0 to 99
ray(i) = hght * dist / (hght - i)
next i
for i = 0 to 63
out &h3c8, i
out &h3c9, i
out &h3c9, i
out &h3c9, i
next i
vwrang = 1920 \ 4
''
'' Draw
''
tmrIni = timer
do
keyb = inkey$
vwrx = vwrx + 10.0*cosTB(vwrang)
vwry = vwry + 10.0*sinTB(vwrang)
ptr = 0
def seg = &ha7d0
for y = 99 to 0 step -1
strang = vwrang + 0
endang = vwrang + 320
if ( strang > 1920 ) then strang = strang - 1920
if ( endang > 1920 ) then endang = endang - 1920
u1 = vwrx + ray(y)*cosTB( strang )
v1 = vwry + ray(y)*sinTB( strang )
u2 = vwrx + ray(y)*cosTB( endang )
v2 = vwry + ray(y)*sinTB( endang )
curu = u1
curv = v1
dudx = (u2-u1) / 320.0
dvdx = (v2-v1) / 320.0
for x = 0 to 319 step 8
poke ptr+0, textr( curu and 63, curv and 63 )
curu = curu + dudx
curv = curv + dvdx
poke ptr+1, textr( curu and 63, curv and 63 )
curu = curu + dudx
curv = curv + dvdx
poke ptr+2, textr( curu and 63, curv and 63 )
curu = curu + dudx
curv = curv + dvdx
poke ptr+3, textr( curu and 63, curv and 63 )
curu = curu + dudx
curv = curv + dvdx
poke ptr+4, textr( curu and 63, curv and 63 )
curu = curu + dudx
curv = curv + dvdx
poke ptr+5, textr( curu and 63, curv and 63 )
curu = curu + dudx
curv = curv + dvdx
poke ptr+6, textr( curu and 63, curv and 63 )
curu = curu + dudx
curv = curv + dvdx
poke ptr+7, textr( curu and 63, curv and 63 )
curu = curu + dudx
curv = curv + dvdx
ptr = ptr + 8
next x
next y
frames = frames + 1.0
loop until ( keyb = chr$ ( 27 ) )
tmrEnd = timer
screen 0
width 80, 25
print "Frames per second:" + str$( frames / (tmrEnd-tmrIni) )
oship me and i will give you lots of guurrls and beeea
Posts: 788
Threads: 53
Joined: Nov 2002
And obviously, you need to use ffix to get the real performance.
oship me and i will give you lots of guurrls and beeea
Posts: 788
Threads: 53
Joined: Nov 2002
This one blurs the texture, giving a much smoother look. Not really related to this post, but still.
Code: defint a-z
const dist = 128
const hght = 100
const pi = 3.14159265359#
dim vwrang as integer
dim x as integer, y as integer
dim i as integer, ptr as integer
dim vwrx as single, vwry as single
dim frames as single
dim tmrIni as single, tmrEnd as single
dim u1 as single, u2 as single
dim v1 as single, v2 as single
dim dudx as single, dvdx as single
dim curu as single, curv as single
dim keyb as string
dim ray( 99 ) as single
dim cosTB( 1920 ) as single
dim sinTB( 1920 ) as single
dim textr( 63, 63 ) as integer
''
'' Setup
''
screen 13
for i = 0 to 1920
cosTB(i) = cos( (pi / 960.0) * i )
sinTB(i) = sin( (pi / 960.0) * i )
next i
for y = 0 to 63
for x = 0 to 63
textr(x, y) = x xor y
next x
next y
for i = 0 to 99
ray(i) = hght * dist / (hght - i)
next i
for i = 0 to 63
out &h3c8, i
out &h3c9, i
out &h3c9, i
out &h3c9, i
next i
vwrang = 1920 \ 4
''
'' Draw
''
tmrIni = timer
do
keyb = inkey$
vwrx = vwrx + 10.0*cosTB(vwrang)
vwry = vwry + 10.0*sinTB(vwrang)
ptr = 0
def seg = &ha7d0
for y = 99 to 0 step -1
strang = vwrang + 0
endang = vwrang + 320
if ( strang > 1920 ) then strang = strang - 1920
if ( endang > 1920 ) then endang = endang - 1920
u1 = vwrx + ray(y)*cosTB( strang )
v1 = vwry + ray(y)*sinTB( strang )
u2 = vwrx + ray(y)*cosTB( endang )
v2 = vwry + ray(y)*sinTB( endang )
curu = u1
curv = v1
dudx = (u2-u1) / 320.0
dvdx = (v2-v1) / 320.0
for x = 0 to 319 \ 4
cola = textr( (curu+1) and 63, curv and 63 )
colb = textr( (curu-1) and 63, curv and 63 )
colc = textr( curu and 63, (curv+1) and 63 )
cold = textr( curu and 63, (curv-1) and 63 )
poke ptr, (cola+colb+colc+cold) \ 4
curu = curu + dudx
curv = curv + dvdx
cola = textr( (curu+1) and 63, curv and 63 )
colb = textr( (curu-1) and 63, curv and 63 )
colc = textr( curu and 63, (curv+1) and 63 )
cold = textr( curu and 63, (curv-1) and 63 )
poke ptr+1, (cola+colb+colc+cold) \ 4
curu = curu + dudx
curv = curv + dvdx
cola = textr( (curu+1) and 63, curv and 63 )
colb = textr( (curu-1) and 63, curv and 63 )
colc = textr( curu and 63, (curv+1) and 63 )
cold = textr( curu and 63, (curv-1) and 63 )
poke ptr+2, (cola+colb+colc+cold) \ 4
curu = curu + dudx
curv = curv + dvdx
cola = textr( (curu+1) and 63, curv and 63 )
colb = textr( (curu-1) and 63, curv and 63 )
colc = textr( curu and 63, (curv+1) and 63 )
cold = textr( curu and 63, (curv-1) and 63 )
poke ptr+3, (cola+colb+colc+cold) \ 4
curu = curu + dudx
curv = curv + dvdx
ptr = ptr + 4
next x
next y
frames = frames + 1.0
loop until ( keyb = chr$ ( 27 ) )
tmrEnd = timer
screen 0
width 80, 25
print "Frames per second:" + str$( frames / (tmrEnd-tmrIni) )
oship me and i will give you lots of guurrls and beeea
Posts: 480
Threads: 24
Joined: Mar 2003
Here we go: this code has no POINT commands, and only one PUT statement at the end of the loop.
Code: '$DYNAMIC
DEFINT A-Z
DIM PIC(63, 63)
DIM buffer(32001) AS INTEGER
DIM Sine(1920) AS SINGLE, Cosine(1920) AS SINGLE
DIM Raylength(99) AS INTEGER
DIM m(100) AS INTEGER
CameraHeight = 100
CameraDistance = 128
FOR i# = 0 TO 6.28165 STEP 6.28165 / 1920
Sine(a) = SIN(i#)
Cosine(a) = COS(i#)
a = a + 1
NEXT i#
FOR y = 0 TO 63
FOR x = 0 TO 63
PIC(x, y) = COS(x / 30) * SIN(y / 30) * 4 + 24
NEXT x
NEXT y
FOR y = 0 TO 99
Raylength(y) = (CameraHeight / (CameraHeight - y)) * CameraDistance
NEXT y
FOR y = 0 TO 100
m(y) = 320 * (99 - y)
NEXT y
SCREEN 13
buffer(0) = 2560: buffer(1) = 200
DEF SEG = VARSEG(buffer(0))
DO
PlayerY = PlayerY + 10
FOR y = 0 TO 99 STEP 2
FOR x = 0 TO 159 STEP 2
xang = 320 + x
vx = (ABS(Raylength(y) * Cosine(xang))) AND 63
vy = (PlayerY + Raylength(y) * Sine(xang)) AND 63
POKE 32004& - m(y) + x, (PIC(vx, vy))
POKE 32004& - m(y) + (318 - x), (PIC(vx, vy))
POKE 32004& + m(y) + x, (PIC(vx, vy))
POKE 32004& + m(y) + (318 - x), (PIC(vx, vy))
NEXT x
NEXT y
FOR y = 1 TO 99 STEP 2
FOR x = 1 TO 159 STEP 2
c1 = PEEK(32004& - m(y) + x - 321)
c2 = PEEK(32004& - m(y) + x - 319)
c3 = PEEK(32004& - m(y) + x + 319)
c4 = PEEK(32004& - m(y) + x + 321)
c = (c1 + c2 + c3 + c4) / 4
POKE 32004& - m(y) + x, c
POKE 32004& - m(y) + (318 - x), c
POKE 32004& + m(y) + x, c
POKE 32004& + m(y) + (318 - x), c
NEXT x
NEXT y
FOR y = 1 TO 100
FOR x = y MOD 2 TO 160 STEP 2
IF x MOD 2 THEN
c1 = PEEK(32004& - m(y) + x - 321)
c2 = PEEK(32004& - m(y) + x - 319)
ELSE
c1 = PEEK(32004& - m(y) + x - 640)
c2 = PEEK(32004& - m(y) + x)
END IF
c = (c1 + c2) / 2
POKE 32004& - m(y) + x - 320, c
POKE 32004& - m(y) + (318 - x) - 320, c
POKE 32004& + m(y) + x + 320, c
POKE 32004& + m(y) + (318 - x) + 320, c
NEXT x
NEXT y
PUT (0, 0), buffer, PSET
LOOP UNTIL INKEY$ <> ""
SYSTEM
*peace*
Meg.
Posts: 480
Threads: 24
Joined: Mar 2003
I can't think of any way to optimize it better than that. I'm sure there ARE ways, but they'd involve doing things I know nothing about. So I'm pretty sure my help with this stops here unless I have some kind of revelation in my sleep.
Hope I was some help!
*peace*
Meg.
Posts: 480
Threads: 24
Joined: Mar 2003
I see that the final product, which is more blurred because it skips points and then fills in the space between them, is not all that much faster than just doing point by point.. so i'm afraid that to optimize this further you'd might be better off forgetting the whole 'filling in between points thing and working with the earlier code I posted (the short one).
*peace*
Meg.
Posts: 1,166
Threads: 62
Joined: Apr 2003
I still don't understand why it's using really weird colors after compilation...
am an asshole. Get used to it.
Posts: 788
Threads: 53
Joined: Nov 2002
Where? Did you try the code i posted?
oship me and i will give you lots of guurrls and beeea
|