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.

DarkBASIC Discussion / 3d coordinates to matrix tile

Author
Message
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 13th Dec 2009 07:36
im making an editor for a game and im able to find the 3d position on the matrix i want to raise but im not really sure how to go about transfering that to the matrix tile position. its a 4000x4000 matrix with 100x100 tiles. any help is appreciated
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 13th Dec 2009 16:29
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 13th Dec 2009 17:26
its an object matrix lol.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 13th Dec 2009 21:40
@pictionaryjr
Quote: "its an object matrix lol."

The ideas are very similar to TDKs matrix primer tutorial for an object matrix. But even using an object matrix with a size of 100x100 , that equals 20,000 polygons if it's single sided. 40,000 if it's double sided. That may be more overhead than you actually need.

Anyway, depending on the program you used to create the matrix, the vertices should be in a particular order. On a 100x100 grid, vertex 0 generally starts in the lower left corner and vertex 10201 would be in the upper right corner. This reversed Z layout is often used to correspond with how a bitmap is most often stored as a Windows "bottom-up" DIB. A bitmap is usually stored upside down, with the high Y values at the top and the low Y values at the bottom; this is for the possibility of compression... but never mind all that, I'm just saying that 3d terrains often have the Z values layed out the same way a "bottom-up" bitmap is layed out.

Whatever the layout, the vertices should be ordered. The 3d unit size of the grid and the number of tiles should allow you to calculate any tile that you are on. If your 3d unit size was 1000x1000 and your grid tile size was 10x10, that means there are 100 units between each X and Z value.

So, if you had a position at 275,623 , what tile would you be at?
Let's find the X tile first:
275 X position / 100 units per tile = 2.75
Since we can't have only part of tile, let's drop the decimal and the formula becomes

xtile=int(Xpos/(xunits_per_tile))

Z is the same thing

ztile=int(Zpos/(zunits_per_tile))

So the tile position is xtile,ztile . If you are at the extreme, 1000x1000 , the tile values would be returned as 10x10 which is too big (9x9 would be the largest because the first tile is 0x0 ) so you'd have to compensate:

Remember, tilex and tilez is the grid size you set your matrix up to originally.

if xtile >= tilex OR ztile >=tilez then position is out of bounds

Enjoy your day.
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 14th Dec 2009 22:22
Quote: "its an object matrix lol."


And how was I supposed to know that? I'm not a mind reader!

TDK

pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 15th Dec 2009 03:56
Just wanted to say thanks guys for the help with the matrix coordinates. I took a screenshot just to show it was working =P



@TDK
I wasn't saying that u were supposed to know it was an object matrix, just letting you know it was because you seemed kind of thrown off by the fact that it had 100x100 tiles =)

Login to post a reply

Server time is: 2024-04-19 09:22:03
Your offset time is: 2024-04-19 09:22:03