It can be 32 bit, it doesn't have to be 16 bit - you had mentioned that it was early on so I was trying to make sure you were consistant. If your mode was 32 bit, then you have to use 4 bytes and not 2 for the color. If it was 16 bit, then you would use 2 bytes.
Maybe it would be easier if I post the example. I was kinda hoping you'd figure it out though
The function, test_track() will return a 1 if the position in the memblock color matches the track color; a 0 otherwise. It also checks for the proper byte length by looking in the memblock header after the image is converted to a memblock.
I do an initial setup of the track color at the very top of the program. This is so that in 16 or 32 bit, the color can be matched in the memblock (a 2 byte versus a 3 byte number - very different values for the same color in 2 different modes). I'm also using only 1 color for the track. If your track is shaded, you'll have to adjust the color checking over a range. Remember, the comparison is the pixel value at a specific location in the image which you should have converted from the 3d world position.
rem detect position in texture based on color
rem using a memblock
rem by latch
rem 05/25/2008
set display mode 800,600,32
sync on
sync rate 60
randomize timer
autocam off
rem before we do anything, we need the track color
rem because the calculation differs inside the memblock
rem between 16 bit and 32 bit, we have to get our track color
rem out of the memblock so we have a consistant value to compare.
rem if this doesn't make sense, look up RGB 565 16 bit format
rem I already know the track color I'm gonna compare is
rem rgb(92,92,92) but this might be a different value in 16 bit
cls rgb(92,92,92)
get image 1,0,0,1,1
sync
make memblock from image 1,1
rem now check bit depth and get the color
if screen depth()=16
trackcolor=memblock word(1,12)
endif
if screen depth()=32 or screen depth()=24
trackcolor=memblock dword(1,12)
endif
delete memblock 1
rem create a grey track on a green background
rem the image will be 200 x 200
cls rgb(0,30,0)
for n=0 to 10000
ink rgb(rnd(50),rnd(60)+60,0),0
dot rnd(200),rnd(200)
next n
sync
ink rgb(92,92,92),0
for xr=30 to 50
for yr=60 to 80
ellipse 100,100,xr,yr
ellipse 100,99,xr,yr
next yr
next xr
sync
blur bitmap 0,1
box 0,0,50,50
get image 1,0,0,201,201
sync
rem make a matrix at 20 x 20 tiles
make matrix 1,5000,5000,20,20
rem tile it with the whole bitmap based on matrix size
prepare matrix texture 1,1,20,20
cell=0
for z=19 to 0 step -1
for x=0 to 19
inc cell
set matrix tile 1,x,z,cell
next x
next z
update matrix 1
sync
rem a memblock that we will use for checking the color
mem=1
ink rgb(255,255,255),0
do
move camera (upkey()-downkey())*10
turn camera right (rightkey()-leftkey())*2
rem assuming we haven't moved the matrix, the camera
rem position should be the matrix coordinates. We
rem have to derive an xpos and ypos for the image
xpos=camera position x()*(200.0/5000.0)
ypos=200-(camera position z()*(200.0/5000.0))
text 0,20,str$(xpos)
text 0,40,str$(ypos)
text 0,60,"FPS "+str$(screen fps())
ontrack=test_track(xpos,ypos,mem,1,trackcolor)
if ontrack
text 0,0,"Camera is on the track"
else
text 0,0,"Riding on the grass!!"
endif
sync
loop
function test_track(xpos,ypos,mem,img,trackcolor)
result=0
rem if we've already made the memblock, we won't
rem have to again
if memblock exist(mem)=0
make memblock from image mem,img
sync
endif
rem calculate the position inside the memblock
wd=memblock dword(mem,0)
ht=memblock dword(mem,4)
dp=memblock dword(mem,8)
bytes=dp/8
pos=xpos+(ypos*wd)
pos=12+(pos*bytes)
rem test track position against position in memblock based on
rem bike position
if bytes=2
if memblock word(mem,pos)=trackcolor then result=1
endif
if bytes=3 or bytes=4
if memblock dword(mem,pos)=trackcolor then result=1
endif
endfunction result
Enjoy your day.