This snippet show how to create a simple raycasting like in Splinter cell. The only problem is that we can only cubes (maybe spheres) but no complex objets (In this case, dl the great sparky's dll ^^)
sync on : sync rate 60
ink rgb(255,192,0),0 : box 0,0,16,16 : get image 1,0,0,16,16
rays=20
dim startx(rays) : dim starty(rays) : dim startz(rays)
dim endx(rays) : dim endy(rays) : dim endz(rays)
rem create rays
for r=1 to rays
make object box r,1,1,100
ghost object on r : set object light r,0 : texture object r,1
decal=(r>rays/2.0)
startx(r)=(r-1)*2-decal*20 : starty(r)=20+decal*2 : startz(r)=20
endx(r)=startx(r)+50 : endy(r)=decal*5 : endz(r)=-100
distance#=sqrt((endx(r)-startx(r))^2+(endy(r)-starty(r))^2+(endz(r)-startz(r))^2)
next r
rem create a cube
global x : global y : global z : y=10
make object cube rays+1,20 : ghost object on rays+1
ink rgb(255,255,255),0
do
set cursor 0,0 : print screen fps()
rem move a little bit the cube
x=20+20.0*sin(timer()/10.0)
position object rays+1,x,y,z
for r=1 to rays
cast(r,distance#)
next r
ax#=wrapvalue(ax#+mousemovey()*0.2)
ay#=wrapvalue(ay#+mousemovex()*0.2)
rotate camera ax#,ay#,0
move camera (upkey()-downkey())*5
sync
loop
function cast(ray,dist)
position object ray,startx(ray),starty(ray),startz(ray) : point object ray,endx(ray),endy(ray),endz(ray)
ax#=object angle x(ray):ay#=object angle y(ray)
nx=startx(ray) : ny=starty(ray) : nz=startz(ray)
for D=1 to dist
nx=startX(ray)+sin(aY#)*cos(ax#)*D : ny=starty(ray)-sin(aX#)*D : nz=startz(ray)+cos(aY#)*cos(aX#)*D
if nx>x-10 then if nx<x+10
if ny>y-10 then if ny<y+10
if nz>z-10 then if nz<z+10
rem if if the point is inside the cube, we stop raycasting
exit
endif
endif
endif
next D
rem position the ray
position object ray,(nx+startx(ray))/2.0,(ny+starty(ray))/2.0,(nz+startz(ray))/2.0
dist#=sqrt((nx-startx(ray))^2+(ny-starty(ray))^2+(nz-startz(ray))^2)
scale object ray,100,100,dist#
endfunction