Commit graph

3 commits

Author SHA1 Message Date
ostermine
95d2121318 add tests for positions far from the world origin
dev/tests/far_coords.lua: at 1M and 30M blocks a position of a player,
a spawn point and an entity is read back as it was set, a ray hits the
block it is cast to, a body with a velocity moves the same way as at
the world origin, and a position at 30M survives saving and loading of
the world. test/physics/Hitbox.cpp checks the AABB of a hitbox far from
the world origin, test/window/Camera.cpp checks the view relative to the
rendering origin with positions in doubles.
2026-11-12 10:05:09 +03:00
ostermine
89bdadd6aa render the world relative to an origin near the camera
World coordinates were passed to GPU as floats: u_model of a chunk and
of a model had the world translation, vertices of translucent blocks,
particles, precipitation, block wrappers, lines and 3D texts were built
in the world space, and the camera position was subtracted in shaders.
The float step grows with the distance from the world origin (6 cm at
1M blocks, 2 m at 30M): blocks got skewed, then stuck together.

Camera::getOrigin() is an integer point near the camera (X and Z are
rounded to 1024 blocks, Y is 0). Camera::getView() is relative to it,
and every position passed to GPU is "world - origin" calculated on CPU,
so the shaders keep working with small numbers and do not change:
u_cameraPos, a_modelpos, u_inverseView and the shadows matrices are in
the same space as before, shifted by the origin. Matrices of a shadow
map are converted from the origin of its camera to the origin of the
player camera. The clouds shader gets the origin wrapped by the period
of its waves, the waves stay bound to the world.

Vertices of translucent blocks are local to the chunk now, as vertices
of opaque ones, and drawn with u_model of the chunk.
2026-11-12 10:05:06 +03:00
ostermine
e1f6daabb7 fix camera view rotation far from the world origin
Camera::getView built the view with lookAt(position, position + front):
the direction came back as a difference of large floats. Far from the
origin the view turned away from where the camera looks - at 16M blocks
by up to 24 degrees, at 30M the camera looked straight up or down
whatever its yaw (at pitch 0 the direction is a zero vector, the matrix
is NaN). The rotation is built from front itself now, then translated
by -position: the same matrix, without the subtraction.
2026-11-12 10:05:05 +03:00