***Updated*** Now includes texturing
I decided i needed that dbdn membership and set about writing something that people want and need, and i think i've done it!
It doesn't have many fancy features like more popular matrix editors but it keeps it simple and provides a great base for people to expand on and add there own features.
So my matrix editor currently
Features:
Creation of Matrices of any length/breadth/tile number*
Individual Height Point Editing
Randomize matrix feature
Flatten matrix
Save matrix, so you can use it in your own programs!
Load matrix function
Texture painter and texture flood fill
*limited by db's max number of polygons
Controls:
Mouselook-Camera control
Left mouse-move forward
Right mouse-move backward
Upkey-move editing sphere up(along z axis)
Downkey-move editing sphere down(along z axis)
Rightkey-move editing sphere right(along x axis)
Left key-move editing sphere left(along x axis)
+/- keys- raises/lowers the ground level where the editing sphere is
'r'- randomizes the matrix using the current height as the random seed
'f'-flattens the entire matrix ie, set all groud height to 0
's'-saves the matrix in its current state
spacebar-Paints the currently selected texture to the curren tile
't'-textures the entire matrix with the current selected tile
So here it is!!!
`MATRIX EDITOR
`By ReD_eYe
input "Matrix Length> ",length : input "Matrix Width> ",width : input "X tiles> ",xtile : input "Z tiles> ",ztile : input "Filename> ";file$ : input "Image Filename> ";image$ : load image image$,1 : xgap=length/xtile : zgap=width/ztile
dim height((xtile*ztile)*4) : dim info(3) : info(0)=length : info(1)=width : info(2)=xtile : info(3)=ztile : dim texture(xtile-1,ztile-1) : for a=0 to xtile-1 : for b=0 to ztile-1 : texture(a,b)=1 : next b : next a : make matrix 1,length,width,xtile,ztile
prepare matrix texture 1,1,2,2 : filter=1 : set matrix 1,0,1,1,filter,1,1,1: sync on : sync rate 50 : make object sphere 1,((xgap+zgap)/2)/4 : position camera 0,100,-100 : point camera 0,0,0 : cursel=2 : do : set cursor 0,100 : print "Ground height> ";y : print "Current texture> ";cursel
center text 320,0,"Simple Matrix Height Editor" : center text 320,10,"Use mouse to move camera and arrowkeys to move sphere" : center text 320,20,"+ and - raise and lower land" : if mouseclick()=1 : move camera 10 : endif : if mouseclick()=2 : move camera -10 : endif
if keystate(33)=1 : for a=0 to xtile : for b=0 to ztile : set matrix height 1,a,b,0 : next b : next a : update matrix 1 : endif : cax#=camera angle x() : cay#=camera angle y() : cay#=cay#+mousemovex() : cax#=cax#+mousemovey() : yrotate camera wrapvalue(cay#)
xrotate camera wrapvalue(cax#) : if upkey()=1 and u<=0 : z=z+zgap : u=10 : inc tilez : endif : if downkey()=1 and u<=0 : z=z-zgap : u=10 : dec tilez : endif : if rightkey()=1 and u<=0 : x=x+xgap : u=10 : inc tilex : endif
if leftkey()=1 and u<=0 : x=x-xgap : u=10 : dec tilex : endif : if keystate(19)=1 and press=0 : randomize matrix 1,get matrix height(1,tilex,tilez)+1 : update matrix 1 : press=1 : endif : if keystate(19)=0 : press=0 : endif
if tilex<0 : tilex=0 : endif : if tilex>xtile : tilex=xtile : endif : if tilez<0 : tilez=0 : endif : if tilez>ztile : tilez=ztile : endif : if x<0 : x=0 : endif : if x>length : x=length : endif : if z<0 : z=0 : endif : if z>width : z=width : endif : u=u-1
if keystate(78)=1 : set matrix height 1,tilex,tilez,get matrix height(1,tilex,tilez)+1 : update matrix 1 : endif : if keystate(74)=1 : set matrix height 1,tilex,tilez,get matrix height(1,tilex,tilez)-1 : update matrix 1 : endif : if tilex<=xtile-1
if tilez<=ztile-1 : if spacekey()=1 : set matrix tile 1,tilex,tilez,cursel : update matrix 1 : texture(tilex,tilez)=cursel : endif : endif : endif : if keystate(2)=1 : cursel=1 : endif : if keystate(3)=1 : cursel=2 : endif : if keystate(4)=1 : cursel=3 : endif
if keystate(5)=1 : cursel=4 : endif : if keystate(20)=1 : for a=0 to xtile-1 : for b=0 to ztile-1 : set matrix tile 1,a,b,cursel : texture(a,b)=cursel : next b : next a : update matrix 1 : endif
if keystate(31)=1 : for a=0 to xtile : for b=0 to ztile : height(t)=get matrix height(1,a,b) : inc t : next b : next a : t=0 : save array file$+"height",height(0) : save array file$+"info",info(0) : save array file$+"texture",texture(0) : print "Array Saved!!!" : endif
y=get ground height(1,x,z) : position object 1,x,y,z : sync : loop
loadmatrix function here:
function load_matrix(file$,image$) : dim info(3) : load array file$+"info",info(0) : dim height((info(2)*info(3))*4) : load array file$+"height",height(0) : dim texture(info(2)-1,info(3)-1) : load array file$+"texture",texture(0) : load image image$,1
make matrix 1,info(0),info(1),info(2),info(3) : prepare matrix texture 1,1,2,2 : filter=1 : set matrix 1,0,1,1,filter,1,1,1 : for x=0 to info(2) : for z=0 to info(3) : set matrix height 1,x,z,height(t) : inc t : update matrix 1 : next z : next x
for x=0 to info(2)-1 : for z=0 to info(3)-1 : set matrix tile 1,x,z,texture(x,z) : update matrix 1 : next z : next x : undim info(0) : undim height(0) : undim texture(0) : endfunction
Use the load matrix function just like any normal function, the file$ is the filename that you specified in the editor, and the image is the same image used in the editor.
Here is an example of how to use it:
load_matrix("map1","matrixtexture.bmp")
position camera 0,100,0
do
if mouseclick()=1 then move camera 10
if mouseclick()=2 then move camera -10
rem camera control
cax#=camera angle x()
cay#=camera angle y()
cay#=cay#+mousemovex()
cax#=cax#+mousemovey()
yrotate camera wrapvalue(cay#)
xrotate camera wrapvalue(cax#)
sync
loop
function load_matrix(file$,image$) : dim info(3) : load array file$+"info",info(0) : dim height((info(2)*info(3))*4) : load array file$+"height",height(0) : dim texture(info(2)-1,info(3)-1) : load array file$+"texture",texture(0) : load image image$,1
make matrix 1,info(0),info(1),info(2),info(3) : prepare matrix texture 1,1,2,2 : filter=1 : set matrix 1,0,1,1,filter,1,1,1 : for x=0 to info(2) : for z=0 to info(3) : set matrix height 1,x,z,height(t) : inc t : update matrix 1 : next z : next x
for x=0 to info(2)-1 : for z=0 to info(3)-1 : set matrix tile 1,x,z,texture(x,z) : update matrix 1 : next z : next x : undim info(0) : undim height(0) : undim texture(0) : endfunction
And thats about it!
*Note you need to make your texture image or use the one below for it to work now, currently only supports 4 tiles! Remember to save everything in a new project folder.
Thanks
ReD_eYe