summaryrefslogtreecommitdiffstats
path: root/src/LineBlockTracer.cpp
diff options
context:
space:
mode:
authorAlexander Harkness <me@bearbin.net>2015-06-05 12:03:19 +0200
committerAlexander Harkness <me@bearbin.net>2015-06-05 12:03:19 +0200
commit19491f83546d703fbf66051c545fd267da57b820 (patch)
tree47fcca680125e07fce8ef1be676f6e7ec38d7a40 /src/LineBlockTracer.cpp
parentMerge pull request #2069 from HaoTNN/master (diff)
parentFixed overshoot in cLineBlockTracer. (diff)
downloadcuberite-19491f83546d703fbf66051c545fd267da57b820.tar
cuberite-19491f83546d703fbf66051c545fd267da57b820.tar.gz
cuberite-19491f83546d703fbf66051c545fd267da57b820.tar.bz2
cuberite-19491f83546d703fbf66051c545fd267da57b820.tar.lz
cuberite-19491f83546d703fbf66051c545fd267da57b820.tar.xz
cuberite-19491f83546d703fbf66051c545fd267da57b820.tar.zst
cuberite-19491f83546d703fbf66051c545fd267da57b820.zip
Diffstat (limited to '')
-rw-r--r--src/LineBlockTracer.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/LineBlockTracer.cpp b/src/LineBlockTracer.cpp
index 315e8d082..587fa0e7c 100644
--- a/src/LineBlockTracer.cpp
+++ b/src/LineBlockTracer.cpp
@@ -154,38 +154,45 @@ bool cLineBlockTracer::MoveToNextBlock(void)
{
// Find out which of the current block's walls gets hit by the path:
static const double EPS = 0.00001;
- double Coeff = 1;
- enum eDirection
+ enum
{
dirNONE,
dirX,
dirY,
dirZ,
} Direction = dirNONE;
+
+ // Calculate the next YZ wall hit:
+ double Coeff = 1;
if (std::abs(m_DiffX) > EPS)
{
double DestX = (m_DirX > 0) ? (m_CurrentX + 1) : m_CurrentX;
- Coeff = (DestX - m_StartX) / m_DiffX;
- if (Coeff <= 1)
+ double CoeffX = (DestX - m_StartX) / m_DiffX;
+ if (CoeffX <= 1) // We need to include equality for the last block in the trace
{
+ Coeff = CoeffX;
Direction = dirX;
}
}
+
+ // If the next XZ wall hit is closer, use it instead:
if (std::abs(m_DiffY) > EPS)
{
double DestY = (m_DirY > 0) ? (m_CurrentY + 1) : m_CurrentY;
double CoeffY = (DestY - m_StartY) / m_DiffY;
- if (CoeffY < Coeff)
+ if (CoeffY <= Coeff) // We need to include equality for the last block in the trace
{
Coeff = CoeffY;
Direction = dirY;
}
}
+
+ // If the next XY wall hit is closer, use it instead:
if (std::abs(m_DiffZ) > EPS)
{
double DestZ = (m_DirZ > 0) ? (m_CurrentZ + 1) : m_CurrentZ;
double CoeffZ = (DestZ - m_StartZ) / m_DiffZ;
- if (CoeffZ < Coeff)
+ if (CoeffZ <= Coeff) // We need to include equality for the last block in the trace
{
Direction = dirZ;
}