fix render offset

This commit is contained in:
2025-09-21 22:55:22 +02:00
parent e1bb0b3683
commit 81ef6d8a29
3 changed files with 49 additions and 54 deletions

View File

@@ -73,14 +73,11 @@ namespace Voxel
float tDeltaY = direction.Y != 0 ? MathF.Abs(1 / direction.Y) : float.MaxValue;
float tDeltaZ = direction.Z != 0 ? MathF.Abs(1 / direction.Z) : float.MaxValue;
float tMaxX = direction.X > 0
? (MathF.Ceiling(origin.X) - origin.X) * tDeltaX
float tMaxX = direction.X > 0 ? (MathF.Floor(origin.X) + 1 - origin.X) * tDeltaX
: (origin.X - MathF.Floor(origin.X)) * tDeltaX;
float tMaxY = direction.Y > 0
? (MathF.Ceiling(origin.Y) + 1 - origin.Y) * tDeltaY
float tMaxY = direction.Y > 0 ? (MathF.Floor(origin.Y) + 1 - origin.Y) * tDeltaY
: (origin.Y - MathF.Floor(origin.Y)) * tDeltaY;
float tMaxZ = direction.Z > 0
? (MathF.Ceiling(origin.Z) + 1 - origin.Z) * tDeltaZ
float tMaxZ = direction.Z > 0 ? (MathF.Floor(origin.Z) + 1 - origin.Z) * tDeltaZ
: (origin.Z - MathF.Floor(origin.Z)) * tDeltaZ;
float distance = 0f;
@@ -89,36 +86,34 @@ namespace Voxel
while (distance <= maxDistance)
{
Blocks block = GetBlock(x, y, z);
if (block != Blocks.Air)
{
return (true, block, x, y, z, normal);
}
// step to next voxel
if (block != Blocks.Air)
return (true, block, x, y, z, normal);
if (tMaxX < tMaxY && tMaxX < tMaxZ)
{
x += stepX;
normal = new Vector3i(-stepX, 0, 0);
distance = tMaxX;
tMaxX += tDeltaX;
normal = new Vector3i(stepX > 0 ? -1 : 1, 0, 0);
}
else if (tMaxY < tMaxZ)
{
y += stepY;
normal = new Vector3i(0, -stepY, 0);
distance = tMaxY;
tMaxY += tDeltaY;
normal = new Vector3i(0, stepY > 0 ? -1 : 1, 0);
}
else
{
z += stepZ;
normal = new Vector3i(0, 0, -stepZ);
distance = tMaxZ;
tMaxZ += tDeltaZ;
normal = new Vector3i(0, 0, stepZ > 0 ? -1 : 1);
}
}
return (false, Blocks.Air, 0, 0, 0, normal);
return (false, Blocks.Air, 0, 0, 0, Vector3i.Zero);
}
public void Update()