You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

voxelutils.cpp 937B

123456789101112131415161718192021222324252627282930313233
  1. #include "voxelutils.h"
  2. #include "mathplus.h"
  3. namespace vtk {
  4. glm::ivec3 worldPosToChunkPos(const glm::ivec3& pos) {
  5. return glm::ivec3(mp::floor_div3(pos.x, 16),
  6. mp::floor_div3(pos.y, 16),
  7. mp::floor_div3(pos.z, 16));
  8. }
  9. glm::ivec2 worldPosToChunkPos(const glm::ivec2& pos) {
  10. return glm::ivec2(mp::floor_div3(pos.x, 16),
  11. mp::floor_div3(pos.y, 16));
  12. }
  13. glm::ivec3 chunkPosToWorldPos(const glm::ivec3& cPos, const glm::ivec3& lPos) {
  14. return glm::ivec3((cPos * 16) + lPos);
  15. }
  16. std::pair<glm::ivec3, glm::ivec3> worldPosToLocalPos(const glm::ivec3& pos) {
  17. auto cPos = worldPosToChunkPos(pos);
  18. auto lPos = pos - (16 * cPos);
  19. return std::make_pair(cPos, lPos);
  20. }
  21. std::pair<glm::ivec3, glm::ivec3> localPosToLocalPos(const glm::ivec3& cPos, const glm::ivec3& lPos) {
  22. glm::ivec3 wPos = chunkPosToWorldPos(cPos, lPos); // get world coords
  23. return worldPosToLocalPos(wPos);
  24. }
  25. }