fix chunk loading based on player position
This commit is contained in:
@@ -45,13 +45,16 @@ errorret_t rpgCameraUpdate(void) {
|
|||||||
|
|
||||||
vec3 pos;
|
vec3 pos;
|
||||||
rpgCameraGetPosition(pos);
|
rpgCameraGetPosition(pos);
|
||||||
worldpos_t worldPos = {
|
|
||||||
(worldunit_t)pos[0],
|
// Round to the nearest chunk center rather than flooring, so the
|
||||||
(worldunit_t)pos[1],
|
// loaded window is always most centered on what the camera sees.
|
||||||
(worldunit_t)pos[2]
|
// 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){
|
errorChain(mapPositionSet((chunkpos_t){
|
||||||
.x = chunkPos.x - (MAP_CHUNK_WIDTH / 2),
|
.x = chunkPos.x - (MAP_CHUNK_WIDTH / 2),
|
||||||
|
|||||||
Reference in New Issue
Block a user