Posted: 20th Nov 2003 1:33
Here's a function (within a small demo program) that will make any matrix of equal x and z size (square) infinitely wrap around when you move your camera. No fuss just move your camera freely over your matrix and call this function...

(edit: Scroll down for the revised version...)

ScrollMatrix(MatrixNumber,MatrixSize,TileSize)

Tilesize is the number of tiles / your matrix size.


+ Code Snippet
sync on: sync rate 0

msize = 5000
msize2 = msize / 2
tiles = 10
tsize = msize/tiles

make matrix 1,msize,msize,tiles,tiles
randomize matrix 1,100
`set matrix 1,1,1,1,1,1,1,1
position matrix 1,-msize2,0,-msize2
update matrix 1
position camera -250,80,-250
rotate camera 0,0,0
hide mouse
do
`simple camera rotation and movement with cursor keys
if upkey()then move camera 10
if downkey() then move camera -10
if rightkey() then yrotate camera wrapvalue(camera angle y()+2)
if leftkey() then yrotate camera wrapvalue(camera angle y()-2)

`this takes care of the matrix
ScrollMatrix(1,msize,tsize)
sync
loop




function ScrollMatrix(mnum,msize,tsize)
cx = camera position x()
cz = camera position z()
mx = matrix position x(mnum)
mz = matrix position z(mnum)
dx=(mx+msize/2)-cx
dz=(mz+msize/2)-cz
 if dz > tsize
 shift matrix down mnum
 position matrix mnum,mx,0,mz-tsize
 endif
 if dz < -tsize
 shift matrix up mnum
 position matrix mnum,mx,0,mz+tsize
 endif
 if dx > tsize
 shift matrix right mnum
 position matrix mnum,mx-tsize,0,mz
 endif
 if dx < -tsize
 shift matrix left mnum
 position matrix mnum,mx+tsize,0,mz
 endif
update matrix mnum
endfunction
Posted: 21st Nov 2003 6:26
once again thank you zombiefied.
Posted: 21st Nov 2003 6:41
while this does help me a lot it does have a small problem that I've been trying to work out... the height map seams to remain in the original place and thus the camera dips below the matrix at some points and flys above it at others... I can't even imagine how to fix it do you have any suggestions?
Posted: 21st Nov 2003 7:37
Weird... I noticed that too. I'll look into that. I did notice the update matrix statement in the scrollmatrix function isn't needed. Try without that statement.
Posted: 21st Nov 2003 7:46
I don't get it. Why would the heightmap not update with the matrix? This would help me too.

Wait a minute...Maybe you're getting ground height before you call the scrollmatrix function? Make sure you call ScrollMatrix before you get ground height. I haven't tried it but it could be just that simple.
Posted: 21st Nov 2003 15:17
ok...so positioning the get ground height either before or after the function does weild different results but it dosn't help it just makes the problem a little more obvious now i soar much higher in places i shouldn't and sometimes the matrix dissapears altogether. I'll keep working on it and I'll post here if I figure it out.
Posted: 21st Nov 2003 19:07
Hmmm. I tried to just use the section of code in the tank program and it's doing pretty much the same thing.

I don't know why getground height isn't returning the right values. Also, shift matrix messes up your tiles (makes them off by 1) each time you shift the matrix. It's as though the tiles don't shift with it.

Help us out...
Posted: 21st Nov 2003 19:26
Try this:

+ Code Snippet
cls rgb(255,0,0)
box 2,2,30,30
get image 1,0,0,32,32
sync on: sync rate 0

msize = 5000
msize2 = msize / 2
tiles = 10
tsize = msize/tiles

make matrix 1,msize,msize,tiles,tiles
prepare matrix texture 1,1,1,1
randomize matrix 1,150
`set matrix 1,1,1,1,1,1,1,1
position matrix 1,-msize2,0,-msize2
update matrix 1
position camera -250,80,-250
rotate camera 0,0,0
hide mouse
do
`simple camera rotation and movement with cursor keys
if upkey()then move camera 2
if downkey() then move camera -2
if rightkey() then yrotate camera wrapvalue(camera angle y()+1)
if leftkey() then yrotate camera wrapvalue(camera angle y()-1)

`this takes care of the matrix
ScrollMatrix(1,msize,tsize)
h#=get ground height(1,camera position x()-matrix position x(1),camera position z()-matrix position z(1))
position camera camera position x(),h#+100,camera position z()
sync
loop




function ScrollMatrix(mnum,msize,tsize)
cx = camera position x()
cz = camera position z()
mx = matrix position x(mnum)
mz = matrix position z(mnum)
dx=(mx+msize/2)-cx
dz=(mz+msize/2)-cz
 if dz > tsize
 shift matrix down mnum
 position matrix mnum,mx,0,mz-tsize
 endif
 if dz < -tsize
 shift matrix up mnum
 position matrix mnum,mx,0,mz+tsize
 endif
 if dx > tsize
 shift matrix right mnum
 position matrix mnum,mx-tsize,0,mz
 endif
 if dx < -tsize
 shift matrix left mnum
 position matrix mnum,mx+tsize,0,mz
 endif
update matrix mnum
endfunction


Note the get ground height function has deduct current matrix position to work properly.
Posted: 21st Nov 2003 19:32
Haha I just figured that out and was about to post it! in the tank code all the get ground height have -mx and -mz in them!

That's funny.
Posted: 21st Nov 2003 19:55
My code isn't perfect still, it jumps now and then. I have a feeling I need to use floats for everything and that will fix it...
Posted: 21st Nov 2003 20:04
OK here it is revised. Still Jumpy-pants (sometimes). Now to figure out the tiling problem...

+ Code Snippet
sync on: sync rate 0

msize = 5000
msize2 = msize / 2
tiles# = 10
tsize = msize/tiles#


make matrix 1,msize,msize,tiles#,tiles#
`If you got an image for the texture put it here...
`load image "a.bmp",1
`prepare matrix texture 1,1,1,1
randomize matrix 1,100
`set matrix 1,1,1,1,1,1,1,1
position matrix 1,0,0,0
update matrix 1
position camera 0-msize2,80,0-msize2
rotate camera 0,0,0
hide mouse
do
`simple camera rotation and movement with cursor keys

if upkey() then move camera 2
if downkey() then move camera -2
if rightkey() then yrotate camera wrapvalue(camera angle y()+2)
if leftkey() then yrotate camera wrapvalue(camera angle y()-2)
ScrollMatrix(1,msize,tsize)
`scrollmatrix2(1,msize2,tiles#)
`this takes care of the matrix
x# = camera position x():z#=camera position z()
y# = get ground height(1,x#-matrix position x(1),z#-matrix position z(1))
position camera x#,y#+20,z#
sync
loop




function ScrollMatrix(mnum,msize,tsize)
cx# = camera position x()
cz# = camera position z()
mx# = matrix position x(mnum)
mz# = matrix position z(mnum)
dx#=(mx#+msize/2)-cx#
dz#=(mz#+msize/2)-cz#
 if dz# > tsize
 shift matrix down mnum
 position matrix mnum,mx#,0,mz#-tsize
 endif
 if dz# < (0-tsize)
 shift matrix up mnum
 position matrix mnum,mx#,0,mz#+tsize
 endif
 if dx# > tsize
 shift matrix right mnum
 position matrix mnum,mx#-tsize,0,mz#
 endif
 if dx# < (0-tsize)
 shift matrix left mnum
 position matrix mnum,mx#+tsize,0,mz#
 endif
endfunction
Posted: 22nd Nov 2003 1:02
Thats amazing, it works great! You've been a huge help zombfied.
Thanks so much!
Posted: 23rd Nov 2003 22:32
... it jumps now and then


Perhaps those "jumps" appear when the x and z positions of the matrix have to be adjusted at the same time. In your code, for a given time, a change in the x position will restore the z position to mz even if it has to become mz +or- tsize.

Maybe the following code will solve it:

+ Code Snippet
sync on: sync rate 0

msize = 5000
msize2 = msize / 2
tiles# = 10
tsize = msize/tiles#


make matrix 1,msize,msize,tiles#,tiles#
`If you got an image for the texture put it here...
`load image "a.bmp",1
`prepare matrix texture 1,1,1,1
randomize matrix 1,100
`set matrix 1,1,1,1,1,1,1,1
position matrix 1,0,0,0
update matrix 1
position camera 0-msize2,80,0-msize2
rotate camera 0,0,0
hide mouse
do
  `simple camera rotation and movement with cursor keys

  if upkey() then move camera 2
  if downkey() then move camera -2
  if rightkey() then yrotate camera wrapvalue(camera angle y()+2)
  if leftkey() then yrotate camera wrapvalue(camera angle y()-2)
  ScrollMatrix(1,0,msize,tsize)
  `scrollmatrix2(1,msize2,tiles#)
  `this takes care of the matrix
  x# = camera position x()
  z#=camera position z()
  y# = get ground height(1,x#-matrix position x(1),z#-matrix position z(1))
  position camera x#,y#+20,z#
  sync
loop


function ScrollMatrix(matnum as integer, maincam as integer,_
                      msize as integer,tsize as float)

cx = camera position x(maincam)
cz = camera position z(maincam)
mx = matrix position x(matnum)
my = matrix position y(matnum)
mz = matrix position z(matnum)

dx=(mx+msize/2)-cx
dz=(mz+msize/2)-cz
offsetx=0
offsetz=0

if dz > tsize
  shift matrix down matnum
  offsetz=-tsize
endif
if dz < -tsize
  shift matrix up matnum
  offsetz=tsize
endif
if dx > tsize
  shift matrix right matnum
  offsetx=-tsize
endif
if dx < -tsize
  shift matrix left matnum
  offsetx=tsize
endif

position matrix matnum,mx+offsetx,my,mz+offsetz

endfunction


I get a problem when I try to use the code with a waving matrix (see attached code). I don't know whether it is the one you're referring as "tiling problem" or not, but I haven't found a solution for it yet. Any ideas?
Posted: 24th Nov 2003 7:12
When I have a matix prepared with tiles, it shifts the texture tiles by 1 each time I scroll through the entire matrix. I have no idea why it does this.

It's not a problem with matricies that are just 1 texture, but when there is a complex texture map, then it becomes a problem
Posted: 25th Nov 2003 15:14
I see ... my problem it's not with the "ScrollMatrix" function itself (I guess), but with the "MakeWaves" one.

If you run the source code of my last post you will see that as long as you move, the latter function makes the "updated" tiles show the height of the respective "older" ones, giving you the impression that you're not moving even though you really are.

I try modifying the MakeMatrix function but no success so far ... I do need help with this ...

Maybe something similar is happening with the textures as each texture was assigned to a certain tile through the set matrix tile command and this info remains static. I mean, the texture set to the tile x,y will always remain for the current tile x,y (regardless whether the original tile was shifted or not).

For test purposes only, try calling the set matrix tile command each time you shift the matrix, taking care where to shift each texture (if tile info of 5,4 was shifted to 5,5 then the texture of 5,4 has to be manually set to 5,5).
Posted: 1st Dec 2003 19:05
try looking at mine:
http://darkbasicpro.thegamecreators.com/?m=forum_view&t=17638&b=7
Its still WIP, but it moves the camera for real while scrolling the matrix under the camera wrapping it around.
Posted: 5th Dec 2003 22:03
This may be a dumb question but Wouldn't having multiple matrices and making them big enough so you can't see (from the middle of one) the others and surround the one you're on with 8 of them (encircle) and then when you got into the halfway point of a edge one you place all the others around that one? Kinda like having a mouse walk in your hand and you keep putting the next hand under it so it may thinks its getting somewhere?
I see some things that would make this tricky - like if you halfway across but standing on a seam...but... any thoughts?
Posted: 7th Dec 2003 2:07
It would be better to do it with data. Scrolling the data by with huge arrays or something.