Here is a 3D rain effect.
Rem Project: 3D Rain
Rem Created: 09/11/2004 19:28:15
Rem ***** Main Source File *****
sync on
sync rate 60
autocam off
color backdrop 0
randomize timer()
rem Make a dummy object to be moved with the camera as camera angles give funny results.
make object box 1,.1,.1,.1
hide object 1
set ambient light 50
sw=screen width()
while spacekey()=0
speed#=0
if inkey$()="w" then speed#=.4
if inkey$()="s" then speed#=-.4
move camera speed#
move object 1,speed#
gosub draw_rain
text 0,0,"3D Rain - Written by Jason Clogg"
text 0,20,"fps= "+str$(screen fps())
text 0,40,"'w' move forward - 's' move backwards"
sync
endwhile
end
draw_rain:
rem base sprite number
base=600
rem How many raindrops to display
raindrops=100
`Calculate a point in front of the camera to start drawing the starfield
cx#=camera position x()
cy#=camera position y()
cz#=camera position z()
if object exist(base)=0
make object box base,.1,.1,.1
set object light base,1
ghost object on base
color object base,rgb(0,0,255)
fade object base,15
set object collision off base
for i=base+1 to base+raindrops
clone object i,base
rem rain should not be affected by light or included in collisions
set object light i,1
ghost object on i
color object i,rgb(0,0,255)
fade object i,15
set object collision off i
` position object i,rnd(spread*2)-spread,rnd(spread*2)-spread,camera position z()+rnd(dist)
next i
endif
for i=base to base+raindrops
`reposition rain if they are out of camera shot
if object in screen(i)=0
screenx#=rnd(sw):screeny#=0
dist#=rnd(200)+10
pick screen screenx#,screeny#,dist#
sx#=get pick vector x()
sy#=get pick vector y()
sz#=get pick vector z()
position object i,cx#+sx#,cy#+sy#,cz#+sz#
endif
`Calculate distance of star from camera and scale star accordingly
scale object i,100,10,10*rnd(300)
set object to object orientation i,1
pitch object down i,90
move object i,1+dist#/100
next i
return
function distance(x1#,y1#,z1#,obj)
x2#=object position x(obj)
y2#=object position y(obj)
z2#=object position z(obj)
dist#=sqrt((x1#-x2#)*(x1#-x2#)+(y1#-y2#)*(y1#-y2#)+(z1#-z2#)*(z1#-z2#))
endfunction dist#
I still have lots of improvements to be made, for example I currently can't appear to texture the rain, but I thought I would post this example anyway.
Cheers,
Cloggy