1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Chunk relative coordinates.

Discussion in 'Nerd Out Zone' started by adtdeveloping, Aug 7, 2014.

  1. adtdeveloping

    adtdeveloping Reinvented The Wheel

    • Member
    This might not be the right place to ask. But as this forum is about Nerd-out.

    Are there any game programmers who know's how to get the relative chunk coords by the player coords?

    Like. you have a chunk at 0, 0, 16 and your player coords are 0,0,8.
    How can I get the relative coords of the chunk?


    This doesn't seem to work:

    C++: local = glm::ivec3(((global.x % chunkSize.x) + chunkSize.x) % chunkSize.x, ((global.y % chunkSize.y) + chunkSize.y) % chunkSize.y, ((global.x % chunkSize.z) + chunkSize.z) % chunkSize.z);

    Math:
    ((PlayerX % ChunkSizeX) + ChunkSizeX) % ChunkSizeX
    ((PlayerY % ChunkSizeY) + ChunkSizeY) % ChunkSizeY
    ((PlayerZ % ChunkSizeZ) + ChunkSizeZ) % ChunkSizeZ
  2. joppiesaus

    joppiesaus Infamous Space-Octopus

    • Member
    I wish I knowed more about chunks. But this seems fine.
    What do you mean? The distance to the next chunk? The coords of the player from the chunk?
  3. adtdeveloping

    adtdeveloping Reinvented The Wheel

    • Member
    No, I mean. If the player is at X: 0, Y: 0, Z: 8 -- and the chunk he's standing on is at X: 0, Y: 0, Z: 0 (Chunk is 16*16*16)
    How can I get the XYZ coords of the the Chunk JUST by using the player coords?

    Eg: (Chunk: 0,0,0 -- Player: 0,0,8 -- How can I get the chunk's coords by only the player's coords?)
  4. PsychoticLeprechaun

    PsychoticLeprechaun Designer & Web Developer

    • Dev Member
    Okay, after mucking up once, getting it right once but doubting myself, then realising I was right:

    Code:
    ( PlayerX - ( PlayerX % ChunkSizeX ) ) / ChunkSizeX
    Case examples:

    PlayerX = 5, ChunkSizeX = 10:
    ( 5 - ( 5 % 10 ) ) / 10 = 0​

    PlayerX = 5, ChunkSizeX = 10:
    ( 14 - ( 14 % 10 ) ) / 10 = 1​
    Last edited: Aug 7, 2014
    PsychoticLeprechaun, Aug 7, 2014
    Last edited by PsychoticLeprechaun; at Aug 7, 2014
    #4
    adtdeveloping likes this.
  5. adtdeveloping

    adtdeveloping Reinvented The Wheel

    • Member
    I guess I multiply the output of that equation by 16? because. 16 is teh size? (To get the chunk world coordinates :D)
  6. adtdeveloping

    adtdeveloping Reinvented The Wheel

    • Member
    Thx :D! Worked
  7. PsychoticLeprechaun

    PsychoticLeprechaun Designer & Web Developer

    • Dev Member

Share This Page