I wrote a short program in DarkBASIC Classic to demonstrate how to make a matrix, move around it and place objects in it.
rem matrix example - LBFN 8/9/2011
sync on : sync rate 60 : ` using manual syncing so we can redraw the screen when we want to
randomize timer() : ` we want things to be random - thise seeds the generator with a number based upon what the timer() is
patchwork = 100 : true = 1 : false = 0 : NextObject = 100 : ScrWid = screen width()
gosub MakeImages : ` subroutine to make images that we can use for the matrix
make matrix 1,1000,1000,20,20 : ` show the actual matrix
prepare matrix texture 1,patchwork,2,2 : ` necessary to have texture images available
randomize matrix 1,50
for y = 0 to 19 : ` tile the matrix with textures 1 - 4 randomly
for x = 0 to 19
set matrix tile 1,x,y,rnd(3) + 1
next x
next y
update matrix 1
repeat
OldCamX# = camera position x() : OldCamY# =camera position y() : OldcamZ# = camera position z() : ` store the current camera position
if returnkey() = true then gosub PlaceObject
if upkey() = true then move camera 2.0 : ` moves the camera forward
if downkey() = true then move camera -2.0
if rightkey() = true : ` rotates the camera clockwise
y# = camera angle y()
y# = wrapvalue(y# + 2.0)
yrotate camera y#
endif
if leftkey() = true : ` rotates the camera counter-clockwise
y# = camera angle y()
y# = wrapvalue(y# - 2.0)
yrotate camera y#
endif
camX# = camera position x() : camZ# = camera position z()
if camX# < 16.0 or camX# > 984.0 or camZ# < 16.0 or camZ# > 984.0 : ` checks to see if the camera is within the boundaries of the matrix
position camera oldCamX#,oldCamY#,OldCamZ# : ` outside of the boundaries - put it back where it was before
else
y# = get ground height(1,camera position x(),camera position z() ) : ` update the camera's new position
position camera camera position x(),y# + 15.0,camera position z()
endif
ink rgb(255,255,0),0
a$ = "Press [ENTER] to place an item" : ` tell the user the options available
a = (text width(a$) / 2)
b$ = "Click mouse to quit."
b = (text width(b$) / 2)
text (ScrWid /2) - a,10,a$
text (ScrWid / 2) - b,30,b$
sync
until mouseclick() > 0 : ` keep running until the user clicks a mouse button
delete matrix 1
end
MakeImages:
` red
ink rgb(255,0,0),0
box 0,0,32,32
` blue inside
ink rgb(0,0,255),0
box 5,5,27,27
` yellow
ink rgb(255,255,0),0
box 32,0,64,32
` brown inside
ink rgb(255,128,0),0
box 37,5,59,27
` green
ink rgb(0,255,0),0
box 0,32,32,64
` grey inside
ink rgb(128,128,128),0
box 5,37,27,59
` purple
ink rgb(255,0,255),0
box 32,32,64,64
` dark blue inside
ink rgb(0,0,128),0
box 37,37,59,59
get image patchwork,0,0,64,64 : ` gets an image which has 4 distinct colors/patterns - we will use this to randomly texture the matrix
return
PlaceObject:
rem user wants to place an object, give them choices
xpos = ( ScrWid / 2) - 100
repeat
key = 0
text xpos,80,"Select an object to place."
text xpos,100,"1. Select a cube"
text xpos,120,"2. Select a cone"
text xpos,140,"3. Select a cylinder"
text xpos,160,"4. Select a sphere"
text xpos,180,"5. Do not place an object and return"
key = scancode() : ` record the scancode
sync
until (key >= 2 and key<= 6) or (key >= 79 and key <= 81) or key = 75 or key = 76 : ` checks to see if one of the 1 - 5 keys are pressed on the keyboard or numpad
x# = camera position x() : z# = camera position z() : ` store the current camera positions
y# = get ground height(1,x#,z#)
if key = 2 or key = 79 : ` has user selected a cube? note these are scancodes, not the actual values of the key
make object cube NextObject,15 : ` yes
position object NextObject,x#,y# + 7.5,z#
r = rnd(128) + 127 : g = rnd(128) + 127 : b = rnd(128) + 127
color object NextObject,rgb(r,g,b)
inc NextObject
endif
if key = 3 or key = 80
make object cone NextObject,15 : ` user selected a cone
position object NextObject,x#,y# + 7.5,z#
r = rnd(128) + 127 : g = rnd(128) + 127 : b = rnd(128) + 127
color object NextObject,rgb(r,g,b)
inc NextObject
endif
if key = 4 or key = 81
make object cylinder NextObject,15 : `user selected a cylinder
position object NextObject,x#,y# + 7.5,z#
r = rnd(128) + 127 : g = rnd(128) + 127 : b = rnd(128) + 127
color object NextObject,rgb(r,g,b)
inc NextObject
endif
if key = 5 or key = 75
make object sphere NextObject,15 : ` user selected a sphere
position object NextObject,x#,y# + 7.5,z#
r = rnd(128) + 127 : g = rnd(128) + 127 : b = rnd(128) + 127
color object NextObject,rgb(r,g,b)
inc NextObject
endif
return
While this is far from being a tutorial, it gives you basic stuff to get a matrix up and running.
Use the arrow keys to move around. When you are at the spot where you want to place an object, press ENTER (or RETURN) and a menu will come up that gives you choices of what to place.
Click any mouse button (or press ESCAPE) to quit.
Hope this helps you.