Hello there!
I am trying to make 3D lines with 2D commands, but it lags after about 4 lines and I certainly can't use this for 500 lines. Is there another way?
Here is the code for my "3D Lines" using 2D commands:
rem 3D Lines
rem by TheComet
rem setup screen
set display mode 1280,800,32
sync on
sync rate 60
backdrop off
hide mouse
rem setup enviorment
gosub generate_textures
gosub create_landscape
gosub create_pillars
gosub create_poles
backdrop on
rem main loop
do
rem user help
ink rgb(255,255,255),0
set cursor 0,0
if stext=1
print "Use W,S,A,D to stear"
print "Use Mouse to Look around"
print "Screen FPS : "+str$(screen fps())
print "The yellow Spheres should be joined together by"
print "blue lines. If you walk behind a pillar, the lines"
print "will still be visible."
endif
center text screen width()/2,10,"Press <H> to toggle help"
if inkey$()="h" and push=0 then push=1:inc stext:if stext=2 then stext=0
if inkey$()<>"h" then push=0
rem scroll fog
scroll object texture 7,0.001,0.0005
rem rotate camera
rx#=wrapvalue(rx#+mousemovey()/3)
ry#=wrapvalue(ry#+mousemovex()/3)
if rx#<180 then if rx#>70 then rx#=70
if rx#>180 then if rx#<290 then rx#=290
rem move camera
if keystate(17)=1 then speed#=curvevalue(2,speed#,30):a#=wrapvalue(ry#+0):if keystate(32)=1 then a#=wrapvalue(ry#+45)
if keystate(32)=1 then speed#=curvevalue(2,speed#,30):a#=wrapvalue(ry#+90):if keystate(31)=1 then a#=wrapvalue(ry#+135)
if keystate(31)=1 then speed#=curvevalue(2,speed#,30):a#=wrapvalue(ry#+180):if keystate(30)=1 then a#=wrapvalue(ry#+225)
if keystate(30)=1 then speed#=curvevalue(2,speed#,30):a#=wrapvalue(ry#+270):if keystate(17)=1 then a#=wrapvalue(ry#+315)
if keystate(17)=0 and keystate(31)=0 and keystate(30)=0 and keystate(32)=0 then speed#=curvevalue(0,speed#,30)
rem new player positions
x#=newxvalue(x#,a#,speed#)
z#=newzvalue(z#,a#,speed#)
if x#>500 then x#=500
if x#<-500 then x#=-500
if z#>500 then z#=500
if z#<-500 then z#=-500
rem update camera
position camera x#,20,z#
rotate camera rx#,ry#,0
rem connect spheres together with 2d lines
ink rgb(0,0,255),0
for t=22 to 25
for r=23 to 25
if object in screen(t)=1 and object in screen(r)=1
x1=object screen x(t)
y1=object screen y(t)
x2=object screen x(r)
y2=object screen y(r)
line x1,y1,x2,y2
endif
next r
next t
rem refresh screen
sync
rem end of main loop
loop
rem -####--#---#--####---####----###---#---#--#####--#####--#---#--#####---####--
rem #------#---#--#---#--#---#--#---#--#---#----#------#----##--#--#------#------
rem -###---#---#--####---####---#---#--#---#----#------#----#-#-#--#####---###---
rem ----#--#---#--#---#--#-#----#---#--#---#----#------#----#--##--#----------#--
rem ####----###---####---#--#----###----###-----#----#####--#---#--#####--####---
generate_textures:
rem make a texture for landscape
load(1,15,"generating landscape texture")
create bitmap 1,256,256
ink RGB(11,99,1),0
box 0,0,255,255
for t=0 to 50000
ink rgb(rnd(30),rnd(110),1),0
dot rnd(255),rnd(255)
next t
for t=0 to 80
ink rgb(rnd(74),rnd(40),6),0
sx=rnd(235)
sy=rnd(235)
ex=sx+rnd(10)
ey=sy+rnd(10)
if rnd(1)=1
box sx,sy,ex,ey
else
radius=((ex-sx)+(ey-sy))/2
for r=0 to radius
for s=0 to 1
circle sx+s,sy,r
next s
next r
endif
next t
get image 1,0,0,256,256
delete bitmap 1
rem brick texture
load(2,15,"generating brick texture")
create bitmap 1,80,50
for t=0 to 5
c=(t*12)+40
ink rgb(c,c,c),0
box t,t,79-t,49-t
next t
for t=0 to 10000
c=rnd(128)+40
ink rgb(c,c,c),0
r=rnd(5)
circle rnd(60)+10,rnd(30)+10,r
next t
blur bitmap 1,1
get image 2,0,0,80,50
delete bitmap 1
rem fog texture
load(3,15,"generating fog texture")
create bitmap 1,64,64
for t=0 to 10000
c=rnd(128)
ink rgb(c,c,c),0
r=rnd(5)
circle rnd(64),rnd(64),r
next t
for t=0 to 100
ink 0,0
r=rnd(5)
circle rnd(64),rnd(64),r
next t
blur bitmap 1,5
get image 3,0,0,64,64
delete bitmap 1
rem create sky texture
load(4,15,"generating sky texture")
create bitmap 1,256,256
ink rgb(0,0,100),0
box 0,0,255,255
for t=0 to 10000
ink rgb(0,rnd(10),rnd(120)),0
circle rnd(255),rnd(255),rnd(4)
next t
ink rgb(255,255,255),0
for r=0 to 60
for s=0 to 1
circle 100+s,100,r
next s
next r
for t=0 to 10000
rx=rnd(55)
ry=rnd(55)
a=rnd(360)
x=(cos(a)*rx)+100
y=(sin(a)*ry)+100
r=rnd(4)
c=rnd(90)+165
ink rgb(c,c,c),0
circle x,y,r
next t
blur bitmap 1,4
get image 4,0,0,256,256
delete bitmap 1
return
create_landscape:
rem make floor
load(5,15,"making landscape")
make object plain 1,1000,1000
xrotate object 1,90
position object 1,0,0,0
texture object 1,1
rem make four walls
load(6,15,"making walls")
for t=2 to 5
make object plain t,1000,500
texture object t,2
scale object texture t,60,60
next t
position object 2,0,250,500
position object 3,-500,250,0:yrotate object 3,90
position object 4,0,250,-500:yrotate object 4,180
position object 5,500,250,0:yrotate object 5,270
rem make sky
load(7,15,"making sky")
make object plain 6,1000,1000
xrotate object 6,270
position object 6,0,500,0
texture object 6,4
rem make fog
load(8,15,"making fog")
make object plain 7,1000,1000
xrotate object 7,90
position object 7,0,1,0
texture object 7,3
ghost object on 7
scale object texture 7,3,3
return
create_pillars:
rem make 10 pillars
load(9,15,"making pillars")
for t=8 to 17
make object box t,50,300,50
texture object t,2
scale object texture t,6,36
rx=rnd(200)+200
ry=rnd(200)+200
a=rnd(360)
x=cos(a)*rx
y=sin(a)*ry
position object t,x,150,y
make object collision box t,-25,-150,-25,25,150,25,0
next t
return
create_poles:
rem small one in the middle
load(10,15,"making poles")
make object cylinder 18,5
scale object 18,100,200,100
position object 18,0,5,0
rem medium one on the left top
load(11,15,"making poles")
make object cylinder 19,5
scale object 19,100,500,100
position object 19,-100,12.5,80
rem big on the back
load(12,15,"making poles")
make object cylinder 20,5
scale object 20,100,1000,100
position object 20,0,25,-120
rem tiny one on the left
load(13,15,"making poles")
make object cylinder 21,5
position object 21,-70,2.5,-30
rem texture
load(14,15,"texturing")
for t=18 to 21
texture object t,2
next t
rem make spheres on top
load(15,15,"making spheres")
for t=22 to 25
make object sphere t,15
x=object position x(t-4)
y=object position y(t-4)+object size y(t-4)
z=object position z(t-4)
position object t,x,y,z
color object t,rgb(200,180,0)
next t
return
rem #####--#---#--#---#---###---#####--#####---###---#---#---####--
rem #------#---#--##--#--#---#----#------#----#---#--##--#--#------
rem #####--#---#--#-#-#--#--------#------#----#---#--#-#-#---###---
rem #------#---#--#--##--#---#----#------#----#---#--#--##------#--
rem #-------###---#---#---###-----#----#####---###---#---#--####---
function load(done,max,text$)
rem screen width and height
cls
sx#=screen width()/2
sy#=screen height()/2
rem calculate a few things
done#=done
max#=max
per#=100.0/max#*done#
bar=per#*2
rem draw box
ink rgb(255,255,255),0
box sx#-101,sy#-26,sx#+101,sy#+26
ink 0,0
box sx#-100,sy#-25,sx#+100,sy#+25
rem fill box
for t=1 to bar
col=2.55*(t/2.0)
ink rgb(255,col,0),0
line t+sx#-100,sy#-25,t+sx#-100,sy#+25
next t
rem text
text sx#-100,sy#-60,text$
rem refresh screen
sync
endfunction
The code is media-less.
TheComet
Peachy, and the Chaos of the Gems
