Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / infinite matrix function

Author
Message
ZomBfied
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location:
Posted: 20th Nov 2003 01:33 Edited at: 24th Nov 2003 07:11
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.


aprilfan
22
Years of Service
User Offline
Joined: 3rd Oct 2002
Location: Hell
Posted: 21st Nov 2003 06:26
once again thank you zombiefied.
aprilfan
22
Years of Service
User Offline
Joined: 3rd Oct 2002
Location: Hell
Posted: 21st Nov 2003 06: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?
ZomBfied
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location:
Posted: 21st Nov 2003 07:37 Edited at: 21st Nov 2003 07:38
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.
ZomBfied
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location:
Posted: 21st Nov 2003 07:46 Edited at: 21st Nov 2003 08:11
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.
aprilfan
22
Years of Service
User Offline
Joined: 3rd Oct 2002
Location: Hell
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.
ZomBfied
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location:
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...
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 21st Nov 2003 19:26
Try this:



Note the get ground height function has deduct current matrix position to work properly.


Boo!
ZomBfied
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location:
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.
ZomBfied
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location:
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...
ZomBfied
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location:
Posted: 21st Nov 2003 20:04 Edited at: 21st Nov 2003 21:10
OK here it is revised. Still Jumpy-pants (sometimes). Now to figure out the tiling problem...

aprilfan
22
Years of Service
User Offline
Joined: 3rd Oct 2002
Location: Hell
Posted: 22nd Nov 2003 01:02
Thats amazing, it works great! You've been a huge help zombfied.
Thanks so much!
Bighead
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location:
Posted: 23rd Nov 2003 22:32
Quote: "... 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:



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?
ZomBfied
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location:
Posted: 24th Nov 2003 07:12 Edited at: 24th Nov 2003 07:13
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
Bighead
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location:
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).
Darkflame
21
Years of Service
User Offline
Joined: 4th Jul 2003
Location:
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.

"The man who says it cannot be done is generally interrupted by someone doing it." ~ Elbert Hubbard
Jaze
21
Years of Service
User Offline
Joined: 20th Nov 2003
Location: Connecticut, USA
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?

-=/Jaze/=-
ZomBfied
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location:
Posted: 7th Dec 2003 02:07
It would be better to do it with data. Scrolling the data by with huge arrays or something.

Login to post a reply

Server time is: 2024-11-23 23:30:39
Your offset time is: 2024-11-23 23:30:39