Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Calculate chunk From Global X,Y,Z

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
4 replies to this topic

#1 Lance42   Members   

339
Like
0Likes
Like

Posted 19 September 2012 - 02:18 AM

I have a tiled world divided into 64x64x64 chunks. The player is at a global x,y,z tile position and I need to figure out which chunk he is in so I can render it. Currently the chunks are referenced by the global x,y,z position of the tile in the corner of the chunk(chunk position 0,0,0)but this is starting to suck as a referencing system. I clearly need to revisit math I haven't done in years, but while I'm doing that, could one of you math wizards point me in the right direction on this one? Thanks in advance.

Edited by Lance42, 19 September 2012 - 02:27 AM.


#2 rnlf   Members   

1860
Like
1Likes
Like

Posted 19 September 2012 - 03:09 AM

Why not just reference your chunks by their own coordinate system, using 0,0,0 for the first chunk, 1,0,0 for the chunk right of it, 0,1,0 for the one above and so on.

The chunk id is then just the player's (global) block position divided by chunk size truncated to zero decimal places.

#3 Ashaman73   Members   

13714
Like
1Likes
Like

Posted 19 September 2012 - 03:23 AM

First off, use integer positions for your chunk to avoid equal-comparisions of floats/doubles.

First approach: own coordination system like rnlf sugguested

int x = (int)(player.x/CHUNK_SIZE_X);
..

Second approach: chunk is referent by real coord
int x=(int)( floor(player.x/CHUNK_SIZE_X)*CHUNK_SIZE_X);

Edited by Ashaman73, 19 September 2012 - 03:24 AM.

Ashaman

 

Gnoblins: Website - Facebook - Twitter - Youtube - Steam Greenlit - IndieDB - Gamedev Log


#4 Lance42   Members   

339
Like
0Likes
Like

Posted 27 September 2012 - 09:34 AM

I got this working, or so I thought. The problem is my world is isometric and my tiles are...well...see for yourself:

Posted Image

So the above solution doesn't compute the correct chunk based on coordinates because it assumes square chunks. For reference, the Y axis goes northwest to southeast. I'll keep working away at it, but if anybody has an algorithm that will help I'd sure appreciate it. Thank you!

Lance...

#5 Ashaman73   Members   

13714
Like
0Likes
Like

Posted 27 September 2012 - 11:43 AM

Take a look here, there I have explained how to transform a screen position (or mouse position) into iso-tile positions. Once you have your tile position, you can use the chunk calculation from above.

Edited by Ashaman73, 27 September 2012 - 11:44 AM.

Ashaman

 

Gnoblins: Website - Facebook - Twitter - Youtube - Steam Greenlit - IndieDB - Gamedev Log





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.