fix chunk loading based on player position
This commit is contained in:
@@ -45,13 +45,16 @@ errorret_t rpgCameraUpdate(void) {
|
||||
|
||||
vec3 pos;
|
||||
rpgCameraGetPosition(pos);
|
||||
worldpos_t worldPos = {
|
||||
(worldunit_t)pos[0],
|
||||
(worldunit_t)pos[1],
|
||||
(worldunit_t)pos[2]
|
||||
|
||||
// Round to the nearest chunk center rather than flooring, so the
|
||||
// loaded window is always most centered on what the camera sees.
|
||||
// Adding half the chunk dimension before flooring snaps at the
|
||||
// midpoint of each chunk instead of at the boundary.
|
||||
chunkpos_t chunkPos = {
|
||||
.x = (chunkunit_t)floorf(pos[0] / CHUNK_WIDTH + 0.5f),
|
||||
.y = (chunkunit_t)floorf(pos[1] / CHUNK_HEIGHT + 0.5f),
|
||||
.z = (chunkunit_t)floorf(pos[2] / CHUNK_DEPTH + 0.5f)
|
||||
};
|
||||
chunkpos_t chunkPos;
|
||||
worldPosToChunkPos(&worldPos, &chunkPos);
|
||||
|
||||
errorChain(mapPositionSet((chunkpos_t){
|
||||
.x = chunkPos.x - (MAP_CHUNK_WIDTH / 2),
|
||||
|
||||
Reference in New Issue
Block a user