Hello, 047
Here's a simple way how to implement a rearview mirror with no flicker or visible fps loss. I wrote this small prog. when I was trying to make my own racing game
`Init ######################################################
sync on
sync rate 80
hide mouse
backdrop off
autocam off
if check display mode(1024,768,32)=1 then set display mode 1024,768,32
cls
`Setup background
box 0,0,319,199,rgb(5,53,134),rgb(228,228,228),rgb(5,123,204),rgb(255,245,205)
get image 1,0,0,319,199
make object plain 1,screen width(),screen height()
set object texture 1,1,0
set object cull 1,0
set object light 1,0
texture object 1,1
position object 1,0,0,300
scale object 1,300,300,300
`Copy sky background to be seen in rear view mirror
clone object 2,1
`Create flying saucer
`Make a texture
val1=rgb(255,0,0)
val2=rgb(245,10,0)
val3=rgb(100,0,0)
val4=rgb(100,10,0)
box 0,0,199,199,val1,val2,val3,val4
val1=rgb(0,255,0)
val2=rgb(0,245,10)
val3=rgb(0,100,0)
val4=rgb(0,100,10)
box 200,0,399,199,val1,val2,val3,val4
val1=rgb(0,0,255)
val2=rgb(0,10,245)
val3=rgb(0,0,100)
val4=rgb(0,10,100)
box 0,200,199,399,val1,val2,val3,val4
val1=rgb(255,255,0)
val2=rgb(245,245,0)
val3=rgb(100,100,0)
val4=rgb(100,100,10)
box 200,200,399,399,val1,val2,val3,val4
ink 0,0
for i=1 to 20
line 0,210-i,399,210-i
line 210-i,0,210-i,399
next i
get image 4,0,0,399,399
make object sphere 3,5 ,40,40
position object 3,0,0,0
scale object 3,100,30,100 `by modifying y factor to 30% we get a saucer shape from the sphere
texture object 3,4
`Setup road
`This creates a 100x100 image resembling a basic road ( 3 vertical stripes )
randomize timer()
for x=0 to 599
for y=0 to 599
if x<200 or x>400
col=rgb(0,150+rnd(105),0) `green scale
else
value=100+rnd(155)
col=rgb(value,value,value) `gray scale
endif
dot x,y,col
next y
next x
get image 2,0,0,599,599
`Terrain height data ~18% resolution compared to image
dim h(33,33)
for x=1 to 33
for y=1 to 33
if x<10 or x>21
if x<10
value=100-(10*x)+rnd(64) `Make elevation more accentuated by the edges
else
value=(x-21)*10+rnd(64)
endif
color=rgb(value,value,value)
else
value=rnd(15)
color=rgb(value,value,value) `<-- almost black, very low elevation variations for the road
endif
h(x,y)=color
next y
next x
`Create terrain
for i=0 to 7
make matrix 1+i,512,512,32,32
position matrix 1+i,-256,0,512*i
prepare matrix texture 1+i,2,33,33
set matrix texture 1+i,2,1
next i
tc=1
for z=0 to 31
for x=0 to 31
col=h(x,z)
h#=rgbr(col)/4.0
for m=0 to 7
set matrix height 1+m,x,z,h#
set matrix tile 1+m,31-x,z,tc
next m
inc tc
next x
inc tc
next z
for i=0 to 7
update matrix 1+i
next i
`Make camera + lights
make camera 1
position camera 1,0,0,-20
point camera 1,0,0,0
set camera range 1,1.5,6000
make camera 2
set camera range 2,1.5,6000
set camera to image 2,3,256,256
sprite 1,100,450,3
mirror sprite 1
position camera 2,-1,0,-20
point camera 2,0,0,-40
set ambient light 45
set current camera 1
cz#=2048
speed#=4.0
alpha#=0
beta#=0.6
gamma#=6
radius#=25
amplitude#=2.5
maxx#=45
do
cz#=cz#+speed#
alpha#=alpha#+beta#
if alpha#>360 then alpha#=alpha#-360
if cz#>2560 then cz#=2048
delta#=sin(wrapvalue(alpha#))
epsilon#=sin(wrapvalue(alpha#*gamma#))
zeta#=cos(wrapvalue(alpha#))
xvalue#=maxx#*delta#
yvalue#=amplitude#*epsilon#
position camera 1,0,20,cz#
rotate camera 1,10,0,0
position camera 2,-4,20,cz#
point camera 2,-10,90,0
position object 3,radius#*delta#,20+yvalue#,cz#+radius#*zeta#
rotate object 3,xvalue#,wrapvalue(alpha#*gamma#/1.2),0
position object 1, 0,0,cz#+1500 `background sky ahead
position object 2, 0,30,cz#-400 `background sky behind
box 95,445,361,711,0,0,0,0
paste sprite 1,100,450 `mirror
sync
loop
Hope it helps