Ich versuche, diesen Algorithmus in C#zu implementieren, aber ich habe im Moment sehr inkonsistente Ergebnisse, und ich kann nicht herausfinden, warum.public static IEnumerable
FastVoxelTraversal(Point a, Point b)
{
var ret = new List();
Vector direction = ((Vector)b - (Vector)a);
int stepX = direction.x >= 0 ? 1 : -1;
int stepY = direction.y >= 0 ? 1 : -1;
int stepZ = direction.z >= 0 ? 1 : -1;
var iterator = a;
float nextVoxelBoundaryX = (iterator.x + stepX);
float nextVoxelBoundaryY = (iterator.y + stepY);
float nextVoxelBoundaryZ = (iterator.z + stepZ);
float tMaxX = (direction.x != 0) ? (nextVoxelBoundaryX - a.x) / direction.x : float.MaxValue;
float tMaxY = (direction.y != 0) ? (nextVoxelBoundaryY - a.y) / direction.y : float.MaxValue;
float tMaxZ = (direction.z != 0) ? (nextVoxelBoundaryZ - a.z) / direction.z : float.MaxValue;
float tDeltaX = (direction.x != 0) ? 1f / direction.x * stepX : float.MaxValue;
float tDeltaY = (direction.y != 0) ? 1f / direction.y * stepY : float.MaxValue;
float tDeltaZ = (direction.z != 0) ? 1f / direction.z * stepZ : float.MaxValue;
while (iterator != b)
{
if (tMaxX < tMaxY)
{
if (tMaxX < tMaxZ)
{
iterator.x += stepX;
tMaxX += tDeltaX;
}
else
{
iterator.z += stepZ;
tMaxZ += tDeltaZ;
}
}
else
{
if (tMaxY < tMaxZ)
{
iterator.y += stepY;
tMaxY += tDeltaY;
}
else
{
iterator.z += stepZ;
tMaxZ += tDeltaZ;
}
}
ret.Add(iterator);
}
return ret;
}
< /code>
Die Zellgröße beträgt 1. Wie Sie sehen können, sind die Ergebnisse manchmal wie erwartet und manchmal nicht. src = "https://i.Sstatic.net/zobhfc95.png"/>
Was soll ich korrigieren? < /p>
Vielen Dank. Ich habe die Ergebnisse gemalt, die ich erwarte:
Dieser Algorithmus sollte eine "Supercover" ausführen, was bedeutet, dass es alle Zellen enthalten sollte. Dies unterscheidet sich von Bresenham, das eine approxative Rasterisierung ergeben soll.
Inkonsistente Ergebnisse mit meinem C# Fast Voxel -Traversal -Algorithmus (Amanatides und Woo) ⇐ C#
-
- Similar Topics
- Replies
- Views
- Last post