summaryrefslogtreecommitdiffstats
path: root/source/BoundingBox.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-09-02 19:51:13 +0200
committermadmaxoft <github@xoft.cz>2013-09-02 19:51:13 +0200
commitf5e0c8c77e66685f58a5013674c5f74a647d69a5 (patch)
tree1087aabcb5c0f7de47182e4a85b4d15838cb2c60 /source/BoundingBox.cpp
parentArrows deal damage. (diff)
downloadcuberite-f5e0c8c77e66685f58a5013674c5f74a647d69a5.tar
cuberite-f5e0c8c77e66685f58a5013674c5f74a647d69a5.tar.gz
cuberite-f5e0c8c77e66685f58a5013674c5f74a647d69a5.tar.bz2
cuberite-f5e0c8c77e66685f58a5013674c5f74a647d69a5.tar.lz
cuberite-f5e0c8c77e66685f58a5013674c5f74a647d69a5.tar.xz
cuberite-f5e0c8c77e66685f58a5013674c5f74a647d69a5.tar.zst
cuberite-f5e0c8c77e66685f58a5013674c5f74a647d69a5.zip
Diffstat (limited to '')
-rw-r--r--source/BoundingBox.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/source/BoundingBox.cpp b/source/BoundingBox.cpp
index e2b8c313e..d8a1bc679 100644
--- a/source/BoundingBox.cpp
+++ b/source/BoundingBox.cpp
@@ -239,42 +239,50 @@ bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Line1, const Vector3d
bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Min, const Vector3d & a_Max, const Vector3d & a_Line1, const Vector3d & a_Line2, double & a_LineCoeff, char & a_Face)
{
+ if (IsInside(a_Min, a_Max, a_Line1))
+ {
+ // The starting point is inside the bounding box.
+ a_LineCoeff = 0;
+ a_Face = BLOCK_FACE_YM; // Make it look as the top face was hit, although none really are.
+ return true;
+ }
+
char Face = 0;
double Coeff = Vector3d::NO_INTERSECTION;
// Check each individual bbox face for intersection with the line, remember the one with the lowest coeff
double c = a_Line1.LineCoeffToXYPlane(a_Line2, a_Min.z);
- if ((c < Coeff) && IsInside(a_Min, a_Max, a_Line1 + (a_Line2 - a_Line1) * c))
+ if ((c >= 0) && (c < Coeff) && IsInside(a_Min, a_Max, a_Line1 + (a_Line2 - a_Line1) * c))
{
Face = (a_Line1.z > a_Line2.z) ? BLOCK_FACE_ZP : BLOCK_FACE_ZM;
Coeff = c;
}
c = a_Line1.LineCoeffToXYPlane(a_Line2, a_Max.z);
- if ((c < Coeff) && IsInside(a_Min, a_Max, a_Line1 + (a_Line2 - a_Line1) * c))
+ if ((c >= 0) && (c < Coeff) && IsInside(a_Min, a_Max, a_Line1 + (a_Line2 - a_Line1) * c))
{
Face = (a_Line1.z > a_Line2.z) ? BLOCK_FACE_ZP : BLOCK_FACE_ZM;
Coeff = c;
}
c = a_Line1.LineCoeffToXZPlane(a_Line2, a_Min.y);
- if ((c < Coeff) && IsInside(a_Min, a_Max, a_Line1 + (a_Line2 - a_Line1) * c))
+ if ((c >= 0) && (c < Coeff) && IsInside(a_Min, a_Max, a_Line1 + (a_Line2 - a_Line1) * c))
{
Face = (a_Line1.y > a_Line2.y) ? BLOCK_FACE_YP : BLOCK_FACE_YM;
Coeff = c;
}
c = a_Line1.LineCoeffToXZPlane(a_Line2, a_Max.y);
- if ((c < Coeff) && IsInside(a_Min, a_Max, a_Line1 + (a_Line2 - a_Line1) * c))
+ if ((c >= 0) && (c >= 0) && (c < Coeff) && IsInside(a_Min, a_Max, a_Line1 + (a_Line2 - a_Line1) * c))
{
Face = (a_Line1.y > a_Line2.y) ? BLOCK_FACE_YP : BLOCK_FACE_YM;
Coeff = c;
}
c = a_Line1.LineCoeffToYZPlane(a_Line2, a_Min.x);
- if ((c < Coeff) && IsInside(a_Min, a_Max, a_Line1 + (a_Line2 - a_Line1) * c))
+ if ((c >= 0) && (c < Coeff) && IsInside(a_Min, a_Max, a_Line1 + (a_Line2 - a_Line1) * c))
{
Face = (a_Line1.x > a_Line2.x) ? BLOCK_FACE_XP : BLOCK_FACE_XM;
Coeff = c;
}
c = a_Line1.LineCoeffToYZPlane(a_Line2, a_Max.x);
- if ((c < Coeff) && IsInside(a_Min, a_Max, a_Line1 + (a_Line2 - a_Line1) * c))
+ if ((c >= 0) && (c < Coeff) && IsInside(a_Min, a_Max, a_Line1 + (a_Line2 - a_Line1) * c))
{
Face = (a_Line1.x > a_Line2.x) ? BLOCK_FACE_XP : BLOCK_FACE_XM;
Coeff = c;