Okay, I tried that. It didn't work.
I think I need to show you the code:
sync on
sync rate 0
load image "C:landscapeimg2.jpg",1
load image "C:Program FilesCShoptexturesCloudscloud_tile07.jpg",1000
hide mouse
for i=1 to 3
null=make vector3(i)
next i
make object cube 1,20
make object sphere 1000,-10000
xrotate object 1000,-60
texture object 1000,1000
make matrix 1,3000,3000,60,60
prepare matrix texture 1,1,4,1
fill matrix 1,0,3
position camera 500,200,0
set object ambient 1000,0
heighty#=0
speed#=0.05
height#=0
xguy=0
zguy=0
mode=1
texsize=1
tex=1
reset=0
texguy=1
zoom#=300
zoom=300
stop=0
stop2=0
set camera range 1,90000
do
position object 1000,object position x(1),object position y(1),object position z(1)
scroll object texture 1000,0.00001,0.000001
box 0,0,screen width(),15,rgb(500,50,50),rgb(100,0,0),rgb(500,50,50),rgb(100,0,0)
box 0,screen height()-25,screen width(),screen height(),rgb(500,50,50),rgb(100,0,0),rgb(500,50,50),rgb(100,0,0)
if mode=1 then text 0,screen height()-20,"Now in Terrain Mode"
if mode=2 then text 0,screen height()-20,"Now in Texture Mode"
text 0,0,"EARTHWORKS"
text screen width()-50,0,"V-0.9"
if keystate(59)=1 then mode=1
if keystate(60)=1 then mode=2
if keystate(63)=1 then texguy=0
if keystate(64)=1 then texguy=1
if keystate(65)=1 then texsize=1
if keystate(66)=1 then texsize=2
if texguy=1 and stop=0 then set matrix wireframe off 1
if texguy=0 and stop=0 then set matrix wireframe on 1
if mode=2 and keystate(2)=1 then tex=1
if mode=2 and keystate(3)=1 then tex=2
if mode=2 and keystate(4)=1 then tex=3
if mode=2 and keystate(5)=1 then tex=4
xguy=object position x(1)/50
zguy=object position z(1)/50
height#=get ground height(1,object position x(1),object position z(1))
position object 1,object position x(1),height#,object position z(1)
if mode=1 and mouseclick()=1 then heighty#=heighty#+speed# : set matrix height 1,xguy,zguy,heighty# : reset=1
if mode=1 and mouseclick()=2 then heighty#=heighty#-speed# : set matrix height 1,xguy,zguy,heighty# : reset=1
if reset=1 and mouseclick()=0 then heighty#=0
if mode=2 and texsize=1 and mouseclick()=1 then set matrix tile 1,xguy,zguy,tex
if mode=2 and texsize=2 and mouseclick()=1 then set matrix tile 1,xguy,zguy,tex
if mode=2 and texsize=2 and mouseclick()=1 then set matrix tile 1,xguy-1,zguy,tex
if mode=2 and texsize=2 and mouseclick()=1 then set matrix tile 1,xguy+1,zguy,tex
if mode=2 and texsize=2 and mouseclick()=1 then set matrix tile 1,xguy,zguy-1,tex
if mode=2 and texsize=2 and mouseclick()=1 then set matrix tile 1,xguy,zguy+1,tex
if mode=2 and texsize=2 and mouseclick()=1 then set matrix tile 1,xguy-1,zguy-1,tex
if mode=2 and texsize=2 and mouseclick()=1 then set matrix tile 1,xguy+1,zguy+1,tex
if mode=2 and texsize=2 and mouseclick()=1 then set matrix tile 1,xguy-1,zguy+1,tex
if mode=2 and texsize=2 and mouseclick()=1 then set matrix tile 1,xguy+1,zguy-1,tex
if leftkey()=1 and stop=0 then yrotate object 1,object angle y(1)+90 : stop=1
if leftkey()=0 and rightkey()=0 then stop=0
if rightkey()=1 and stop=0 then yrotate object 1,object angle y(1)-90 : stop=1
if upkey()=1 then zoom#=zoom#-0.7
if downkey()=1 then zoom#=zoom#+0.7
zoom=zoom#
update(1,3000,3000,60,60)
set camera to follow object position x(1),object position y(1),object position z(1),object angle y(1),zoom+100,zoom,100,0
point camera object position x(1),object position y(1),object position z(1)
mouse(1)
if texsize=1 or mode=1 or mode=2 then matrix_restraint(1,2990,2990)
if texsize=2 and mode=2 then matrix_restraint2(1,2900,2900)
if spacekey()=1 and stop2=0 then gosub save : stop2=1
if spacekey()=0 then stop2=0
sync
loop
save:
matrix_to_object(777,1,3000,3000,60,60,1,1,2,2,1,1)
save object "C:mymatrixmap.x",777
return
function mouse(obj)
move object right obj,mousemovex()
move object obj,-mousemovey()
endfunction
function matrix_restraint(obj,mx,mz)
if object position x(obj)<-1 then position object obj,0,object position y(obj),object position z(obj)
if object position x(obj)>mx+1 then position object obj,mx,object position y(obj),object position z(obj)
if object position z(obj)<-1 then position object obj,object position x(obj),object position y(obj),0
if object position z(obj)>mz+1 then position object obj,object position x(obj),object position y(obj),mz
endfunction
function matrix_restraint2(obj,mx,mz)
if object position x(obj)<50 then position object obj,50,object position y(obj),object position z(obj)
if object position x(obj)>mx+1 then position object obj,mx,object position y(obj),object position z(obj)
if object position z(obj)<50 then position object obj,object position x(obj),object position y(obj),50
if object position z(obj)>mz+1 then position object obj,object position x(obj),object position y(obj),mz
endfunction
function update(num,width,height,xtiles,ztiles)
set vector3 1,camera position x(),camera position y(),camera position z()
for x=0 to xtiles
for z=0 to ztiles
set vector3 2,x*width/(xtiles+0.0),get matrix height(num,x,z),z*height/(ztiles+0.0)
subtract vector3 3,2,1
dist#=length vector3(3)
t=1
if dist#<1000
t=2
endif
if dist#<800
t=3
endif
if dist#<400
t=4
endif
if dist#<200
t=5
endif
set matrix normal num,x,z,t/5.0,t/5.0,t/5.0
next z
next x
update matrix num
endfunction
function Matrix_to_Object( object, matrixnum, matxsize#, matzsize#, matxsegs, matzsegs, tilex, tilez, limbx, limbz, begtexnum, endtexnum )
`safety in case matxsegs and matzsegs is not evenly divisible by tilex and tilez
if matxsegs mod tilex > 0
EXIT PROMPT "Number of matrix xsegs not evenly divisible by tilex", "Texture tilex error"
end
endif
if matzsegs mod tilez > 0
EXIT PROMPT "Number of matrix zsegs not evenly divisible by tilez", "Texture tilez error"
end
endif
`safety in case limbx and limbz is smaller than the texture x and z
a = 0
if limbx < tilex then limbx = tilex : a = 1
if limbz < tilez then limbz = tilez : a = 1
if a > 0
sync
print "limbx or limbz was less than tilex or tilez : Error corrected"
sync
wait key
endif
`calc the number of polys in the matrix
num_mat_polys = (matxsegs*matzsegs)*2
`make array to store vert info
`storage indexs = poly number, vert number, x/y/z vert pos/norm/uv
`polys are numbered starting from left to right, front to
`back, one row at a time (with 2 polys per tile)
dim vert_store#(num_mat_polys,2,7)
`calc the width and depth of each tile on the matrix
`formula size#/number
mat_x_wide# = matxsize#/matxsegs
mat_z_deep# = matzsize#/matzsegs
`******************************************************************************
`get vert position data
`placeholder variable for poly numbers
a = 1
`one row at a time (front to back)
for j = 0 to matzsegs - 1
`one tile at a time (left to right)
for i = 0 to matxsegs - 1
`tile top left poly info
`bottom left vert (x,y,z)
vert_store#(a,0,0) = i*mat_x_wide#
vert_store#(a,0,1) = GET MATRIX HEIGHT(matrixnum, i, j)
vert_store#(a,0,2) = j*mat_z_deep#
`top left vert (x,y,z)
vert_store#(a,1,0) = i*mat_x_wide#
vert_store#(a,1,1) = GET MATRIX HEIGHT(matrixnum, i, j+1)
vert_store#(a,1,2) = (j+1)*mat_z_deep#
`top right vert (x,y,z)
vert_store#(a,2,0) = (i+1)*mat_x_wide#
vert_store#(a,2,1) = GET MATRIX HEIGHT(matrixnum, i+1, j+1)
vert_store#(a,2,2) = (j+1)*mat_z_deep#
inc a, 1
`tile bottom right poly info
`bottom left vert (x,y,z)
vert_store#(a,0,0) = i*mat_x_wide#
vert_store#(a,0,1) = GET MATRIX HEIGHT(matrixnum, i, j)
vert_store#(a,0,2) = j*mat_z_deep#
`top right vert (x,y,z)
vert_store#(a,1,0) = (i+1)*mat_x_wide#
vert_store#(a,1,1) = GET MATRIX HEIGHT(matrixnum, i+1, j+1)
vert_store#(a,1,2) = (j+1)*mat_z_deep#
`bottom right vert (x,y,z)
vert_store#(a,2,0) = (i+1)*mat_x_wide#
vert_store#(a,2,1) = GET MATRIX HEIGHT(matrixnum, i+1, j)
vert_store#(a,2,2) = j*mat_z_deep#
inc a, 1
next i
next j
`******************************************************************************
`******************************************************************************
`calc normals for polys
`Thanks to ADR for posting this code on the DBP forums :)
for i = 1 to num_mat_polys
`acuire vert positions
P1X# = vert_store#(i,0,0)
P1Y# = vert_store#(i,0,1)
P1Z# = vert_store#(i,0,2)
P2X# = vert_store#(i,1,0)
P2Y# = vert_store#(i,1,1)
P2Z# = vert_store#(i,1,2)
P3X# = vert_store#(i,2,0)
P3Y# = vert_store#(i,2,1)
P3Z# = vert_store#(i,2,2)
null = make vector3(1)
null = make vector3(2)
null = make vector3(3)
` -- calculate the two directional vectors for the adj and opp edges...
set vector3 1, P1X#, P1Y#, P1Z#
set vector3 2, P2X#, P2Y#, P2Z#
set vector3 3, P3X#, P3Y#, P3Z#
subtract vector3 2, 2, 1
subtract vector3 3, 3, 1 ` -- vector 3 and 1 are now directional vectors
normalize vector3 2,2 ` -- normalize em
normalize vector3 3,3
cross product vector3 1, 2,3 ` -- use the origin vector (1) to store the face normal
normalize vector3 1,1
`save normals (all 3 verts have same normals)
vert_store#(i,0,3) = x vector3(1)
vert_store#(i,0,4) = y vector3(1)
vert_store#(i,0,5) = z vector3(1)
vert_store#(i,1,3) = vert_store#(i,0,3)
vert_store#(i,1,4) = vert_store#(i,0,4)
vert_store#(i,1,5) = vert_store#(i,0,5)
vert_store#(i,2,3) = vert_store#(i,0,3)
vert_store#(i,2,4) = vert_store#(i,0,4)
vert_store#(i,2,5) = vert_store#(i,0,5)
null = delete vector3(1)
null = delete vector3(2)
null = delete vector3(3)
next i
`******************************************************************************
`******************************************************************************
`calc UV data for polys
`save current x tile number
xtiles = 1
`save current z tile number
ztiles = 1
`calc how much to step each u data per tile
stepu# = (1.0/tilex)
`calc how much to step each v data per tile
stepv# = (1.0/tilez)
`set base u data for new set of tiles
baseu# = 0
`set base v data for new set of tiles
basev# = 1-stepv#
`poly number placeholder variable
i = 1
`from front to back
for k = 1 to matzsegs
`reset the number of x tiles to 1 and the u base to 0
`at the beginning of each row
xtiles = 1
baseu# = 0
`from left to right
for l = 1 to matxsegs
`2 polys per tile
for m = 1 to 2
`write all 3 verts of each matrix poly
for j = 0 to 2
`select which formula to apply depending on polygon side
`and vert number (0 to 2)
`j selects the vert number
`m selects the polygon side (back/left or front right : 1 or 2)
select j
case 0
if m = 1
testu# = baseu#
testv# = basev#+stepv#
else
testu# = baseu#
testv# = basev#+stepv#
endif
endcase
case 1
if m = 1
testu# = baseu#
testv# = basev#
else
testu# = baseu#+stepu#
testv# = basev#
endif
endcase
case 2
if m = 1
testu# = baseu#+stepu#
testv# = basev#
else
testu# = baseu#+stepu#
testv# = basev#+stepv#
endif
endcase
endselect
`store calculated data for each vert of each poly
`u data
vert_store#(i,j,6) = testu#
`v data
vert_store#(i,j,7) = testv#
next j
inc i, 1
`next polygon side of this tile
next m
`update u data and xtiles place holder
inc baseu#, stepu#
inc xtiles, 1
`reset data when texture tile width has been reached
if xtiles > tilex
baseu# = 0
xtiles = 1
endif
`next x tile
next l
`update v data and ztiles place holder
dec basev#, stepv#
inc ztiles, 1
`reset data when texture depth has been reached
if ztiles > tilez
basev# = 1-stepv#
ztiles = 1
endif
`next z tile
next k
`******************************************************************************
`******************************************************************************
`make object from matrix verts
`calc number of memblocks needed
tempx = matxsegs/limbx
tempz = matzsegs/limbz
tempmem = tempx * tempz
`make arrays to store memblock positions and memblock numbers
dim membhold(tempx, tempz)
dim mempos(tempmem)
`enter memblock numbers for each texture tile based on the x and z limbs to use
a = 1
for i = 1 to tempz
for j = 1 to tempx
membhold(j, i) = a
inc a, 1
next j
next i
`calc the memblock size
`formula is 12 byte header + ((( 32 bytes per vert * limb x segs)*(limb z segs * 2 polys))* 3 verts per poly)
mat_mem_size = 12+(((32*limbx)*(limbz*2))*3)
`make memblocks and write headers for each memblock and set the beginning
`position for vert data to 12
for i = 1 to tempmem
make memblock i, mat_mem_size
`write objects fvf format as 274
write memblock dword i, 0, 274
`write bytes per vert as 32 (8 floats xpos#,ypos#,zpos#,xnorm#,ynorm#,znorm#,u#,v#)
write memblock dword i, 4, 32
`write number of verts in matrix (polys*3)
write memblock dword i, 8, ((limbx*limbz)*2)*3
`set beginning position for vert data after header(0-8)+4 = 12
mempos(i) = 12
next i
`image tile, row, and memblock placeholders
xtile = 1
ztile = 1
xrow = 1
xmem = 1
zmem = 1
`polygon placeholders (b=2 is 1 tile complete)
b = 1
`enter all polys' verts to memblock
for i = 1 to num_mat_polys
`select memblock number to write to use current x and z limb tile to pick
tempmemnum = membhold(xmem, zmem)
`write all 3 verts of each matrix poly
for j = 0 to 2
`xpos
write memblock float tempmemnum, mempos(tempmemnum), vert_store#(i,j,0)
`increment the current memblock position
inc mempos(tempmemnum), 4
`ypos
write memblock float tempmemnum, mempos(tempmemnum), vert_store#(i,j,1)
inc mempos(tempmemnum), 4
`zpos
write memblock float tempmemnum, mempos(tempmemnum), vert_store#(i,j,2)
inc mempos(tempmemnum), 4
`xnorm
write memblock float tempmemnum, mempos(tempmemnum), vert_store#(i,j,3)
inc mempos(tempmemnum), 4
`ynorm
write memblock float tempmemnum, mempos(tempmemnum), vert_store#(i,j,4)
inc mempos(tempmemnum), 4
`znorm
write memblock float tempmemnum, mempos(tempmemnum), vert_store#(i,j,5)
inc mempos(tempmemnum), 4
`u data
write memblock float tempmemnum, mempos(tempmemnum), vert_store#(i,j,6)
inc mempos(tempmemnum), 4
`v data
write memblock float tempmemnum, mempos(tempmemnum), vert_store#(i,j,7)
inc mempos(tempmemnum), 4
next j
`after each poly increase b by 1
inc b, 1
`after 2 polys have been completed 1 tile has been entered
if b > 2
`reset poly count to 1
b = 1
`move to next x tile
inc xtile, 1
`if at the next limb
if xtile > limbx
`reseet the x tile to 1
xtile = 1
`update the tile count to know when to move to the next row
inc xrow, limbx
`inc the xmem selector placeholder
inc xmem, 1
`if at the last xmem wide then start back at the begining
if xmem > tempx
xmem = 1
endif
endif
`when at the end of the row
if xrow > matxsegs
`go back to the far left
xrow = 1
`update the number of rows done
inc ztile, 1
`when the number of rows done is > the preset depth
if ztile > limbz
`reset row count back to 1
ztile = 1
`move to the next zmem selector placeholder
inc zmem, 1
`if row count overlaps predetermined number
if zmem > tempz
`wrap to 1
zmem = 1
endif
endif
endif
endif
next i
`undim arrays when done with them
undim vert_store#(0,0,0)
undim membhold(0, 0)
undim mempos(0)
`set the mesh number to use (can be replaced with a findfreemesh function)
mesh = 1
`make object and limbs from data setup
for i = 1 to tempmem
`make temp mesh from info
make mesh from memblock mesh, i
`delete temp memblock
delete memblock i
`if it is the first memblock mesh, use it as the base object
if i = 1
`make temp object for NGC
make object object, mesh, begtexnum
`else turn each memblock mesh into limbs
else
add limb object, i-1, mesh
endif
`delete temp mesh
delete mesh mesh
next i
`texture limbs
j = begtexnum + 1
for i = 2 to tempmem
texture limb object, i-1, j
inc j, 1
if j > endtexnum then j = begtexnum
next i
`unrem this to make the lighting look exactly like a matrix
`set object light object, 0
`******************************************************************************
endfunction
sync
It's a matrix editor, that I am hoping to use for my games that use fairly big landscapes...
Hope you can find what is wrong!
BTW, here is the simple loading code I use...
hide mouse
load object "C:mymatrixmap.x",1
position camera 0,50,0
set ambient light 100
do
control camera using arrowkeys 0,0.1,0.05
loop