Time ago, I came up with a piece of code to check if there was a matrix collision. We can check if there is an intersection with a .x object. Now I have another code, that tells us if we are intersecting the matrix or an advanced terrain.This example shows a matrix with a grid of 10*10 , but it works in the same way as if it is 1000*1000.
The management is a bit of a mess, but you´ll be able to handle with it. I hope this can help somebody.
rem MATRIX INTERSECTING PROJECT
rem Chafari 12-MARZ-2010
autocam off
sync on
hide mouse
set ambient light 15
hide light 0
make light 1
position light 1,50,30,50
rem texture
ink rgb(0,100,0),1
box 0,0,100,100
ink rgb(0,80,0),1
box 5,5,95,95
get image 1,0,0,100,100,1
Dim toca(13) as float
make matrix 1,100,100,10,10
prepare matrix texture 1,1,1,1
rem player
make object box 1,1,1.5,1:
color object 1,rgb(255,255,0)
rem enemy
make object box 2,1,1.5,1
color object 2,rgb(255,255,0)
position object 2,20,0,20
make object sphere 100,5:ghost object on 100:fade object 100,50
rem ray cast
for i= 3 to 13
make object box i,0.2,0.2,4
color object i,rgb(0,0,255)
next i
position camera 50,30,0
point camera 0,0,0
cam#=50
ox=5
oz=3
x=2
z=6
ob=1 `selected object
do
rem selecting objects 1 or 2
if inkey$()="1" then ob=1
if inkey$()="2" then ob=2
position object 100,object position x(1),object position y(1),object position z(1)
if ob=1 then set object emissive 1,rgb(255,0,0):else set object emissive 1,rgb(80,80,80)
if ob=2 then set object emissive 2,rgb(255,0,0):else set object emissive 2,rgb(80,80,80)
oy=get matrix height (1,ox,oz)
rem calculating distance
dx#=object position x(2)-object position x(1)
dz#=object position z(2)-object position z(1)
distancia#=sqrt((dx#*dx#)+(dz#*dz#))
largo#=distancia#/13
for i= 3 to 13
position object i,object position x(2),object position y(2),object position z(2)
point object i,object position x(1),object position y(1),object position z(1)
move object i,largo#*i
next i
ink rgb(255,255,255),1
for i= 3 to 13
toca(i)=get ground height(1,object position x(i),object position z(i))
if object position y(i)<toca(i)-1 then set cursor 5,300:print "I don`t see you !"
next i
if ob=1
if upkey() then z=z+1 :sleep 400
if downkey() then z=z-1:sleep 400
if leftkey() then x=x-1:sleep 400
if rightkey() then x=x+1:sleep 400
endif
if ob=2
if upkey() then oz=oz+1 :sleep 400
if downkey() then oz=oz-1:sleep 400
if leftkey() then ox=ox-1:sleep 400
if rightkey() then ox=ox+1:sleep 400
endif
position object 2,ox*10,oy,oz*10
rem matrix borders
if x<0 then x=0
if x>10 then x=10
if z<0 then z=0
if z>10 then z=10
if ox<0 then ox=0
if ox>10 then ox=10
if oz<0 then oz=0
if oz>10 then oz=10
altura=get matrix height (1,x,z)
position object 1,x*10,altura,z*10
rem rising up & down matrix vertex
if mouseclick()=1
set matrix height 1,x,z,2+altura:sleep 300
update matrix 1
endif
if mouseclick()=2
set matrix height 1,x,z,-2+altura:sleep 300
update matrix 1
endif
set cursor 5,5
print "HELP H"
if inkey$()="h" or inkey$()="H"
set cursor 0,50
print "MOVE SELECTED OBJECT WITH CURSORKEYS"
print "PRESS KEY 1 TO SELECT OBJECT 1"
print "PRESS KEY 2 TO SELECT OBJECT 2"
print "MOUSE 1 PULL MATRIX VERTEX UP"
print "MOUSE 2 PUSH MATRIX VERTEX DOWN"
print "W - S + MOUSE MOVE CAMERA "
endif
rem camera movements
if inkey$()="w" or inkey$()="W" THEN cx#=NEWXVALUE(cx#,a#,0.1):cz#=NEWZVALUE(cz#,a#,0.1)
if inkey$()="s" or inkey$()="S" THEN cx#=NEWXVALUE(cx#,a#,-0.1):cz#=NEWZVALUE(cz#,a#,-0.1)
position camera cx#,20,cz#
a#=wrapvalue(a#+mousemovex()/2)
cam#=wrapvalue(cam#+mousemovey()/2)
rotate camera cam#,a#,0
sync
loop
I'm not a grumpy grandpa
