use double precision for camera position and ray casts

A float position has a step of 6 cm at 1M blocks and of 2 m at 30M:
the camera moved by jumps and rays started not where the camera is.

worldvec3 (glm::dvec3) is the type of a position in the world.
Camera::position, the start and the end of block and entity ray casts
and the hit position of the player selection use it. Lua numbers are
doubles already, so cameras.set_pos/get_pos, block.raycast,
entities.raycast and world.raycast only stop rounding to float.
Entities::rayCast intersects a hitbox in the coordinates relative to
its position instead of a float AABB in the world space.
This commit is contained in:
ostermine 2026-11-12 00:58:10 +03:00
parent 89bdadd6aa
commit ad69663b2e
18 changed files with 86 additions and 71 deletions

View file

@ -180,10 +180,10 @@ void Shadows::generateShadowsMap(
float shadowMapScale = 0.32f / (1 << glm::max(0, quality)) * scale;
float shadowMapSize = resolution * shadowMapScale;
glm::vec3 basePos = glm::floor(camera.position / 4.0f) * 4.0f;
glm::vec3 prevPos = shadowCamera.position;
worldvec3 basePos = glm::floor(camera.position / 4.0) * 4.0;
worldvec3 prevPos = shadowCamera.position;
shadowCamera = Camera(
glm::distance2(prevPos, basePos) > 25.0f ? basePos : prevPos,
glm::distance2(prevPos, basePos) > 25.0 ? basePos : prevPos,
shadowMapSize
);
shadowCamera.near = 0.1f;
@ -206,9 +206,9 @@ void Shadows::generateShadowsMap(
glm::radians(0.0f)
);
shadowCamera.position -= shadowCamera.front * 500.0f;
shadowCamera.position += shadowCamera.up * 0.0f;
shadowCamera.position += camera.front * 0.0f;
shadowCamera.position -= worldvec3(shadowCamera.front * 500.0f);
shadowCamera.position += worldvec3(shadowCamera.up * 0.0f);
shadowCamera.position += worldvec3(camera.front * 0.0f);
auto view = shadowCamera.getView();

View file

@ -118,7 +118,7 @@ void DebugLinesRenderer::render(
if (showChunkBorders) {
linesShader.uniformMatrix("u_projview", camera.getProjView());
glm::vec3 coord = camera.position;
worldvec3 coord = camera.position;
if (coord.x < 0) coord.x--;
if (coord.z < 0) coord.z--;
int cx = floordiv(static_cast<int>(coord.x), CHUNK_W);

View file

@ -120,7 +120,7 @@ void Decorator::updateAcoustics(const Camera& camera) {
glm::vec3 dir = { r * std::cos(phi), r * std::sin(phi), z };
dir = glm::normalize(dir);
glm::vec3 end;
worldvec3 end;
glm::ivec3 norm;
glm::ivec3 iend;
blocks_agent::RaycastSettings raycast {};
@ -128,7 +128,7 @@ void Decorator::updateAcoustics(const Camera& camera) {
if (vox == nullptr) {
continue;
}
auto distance = glm::distance(start, end);
float distance = glm::distance(start, end);
if (distance >= length * 0.98f) {
continue;
}