summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-09-01 20:39:22 +0200
committermadmaxoft <github@xoft.cz>2013-09-01 20:39:22 +0200
commite35402c61aa8c9749ff65e5a083184d369f79f15 (patch)
treef6077f392b7db8a162fc694fc1b79c1275b31875 /source
parentAdded dtRangedAttack, fixed faulty StringTODamageType() (diff)
downloadcuberite-e35402c61aa8c9749ff65e5a083184d369f79f15.tar
cuberite-e35402c61aa8c9749ff65e5a083184d369f79f15.tar.gz
cuberite-e35402c61aa8c9749ff65e5a083184d369f79f15.tar.bz2
cuberite-e35402c61aa8c9749ff65e5a083184d369f79f15.tar.lz
cuberite-e35402c61aa8c9749ff65e5a083184d369f79f15.tar.xz
cuberite-e35402c61aa8c9749ff65e5a083184d369f79f15.tar.zst
cuberite-e35402c61aa8c9749ff65e5a083184d369f79f15.zip
Diffstat (limited to 'source')
-rw-r--r--source/BoundingBox.cpp20
-rw-r--r--source/Vector3d.h9
2 files changed, 12 insertions, 17 deletions
diff --git a/source/BoundingBox.cpp b/source/BoundingBox.cpp
index c845fe372..bf53f3c6a 100644
--- a/source/BoundingBox.cpp
+++ b/source/BoundingBox.cpp
@@ -202,37 +202,37 @@ bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Min, const Vector3d &
// 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)
+ if ((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)
+ if ((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)
+ if ((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)
+ if ((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)
+ if ((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)
+ if ((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;
@@ -244,14 +244,6 @@ bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Min, const Vector3d &
return false;
}
- Vector3d Intersection = a_Line1 + (a_Line2 - a_Line1) * Coeff;
- if (!IsInside(a_Min, a_Max, Intersection))
- {
- // The line intersects with the individual wall planes, but not within this bounding box
- return false;
- }
-
- // True intersection, return all the values:
a_LineCoeff = Coeff;
a_Face = Face;
return true;
diff --git a/source/Vector3d.h b/source/Vector3d.h
index 081ce353f..a06a17c09 100644
--- a/source/Vector3d.h
+++ b/source/Vector3d.h
@@ -11,9 +11,6 @@ class Vector3f;
class Vector3d
{
public:
- static const double EPS; ///< The max difference between two coords for which the coords are assumed equal
- static const double NO_INTERSECTION; ///< Return value of LineCoeffToPlane() if the line is parallel to the plane
-
// convert from float
Vector3d(const Vector3f & v);
Vector3d(const Vector3f * v);
@@ -33,18 +30,21 @@ public:
/** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified Z coord
The result satisfies the following equation:
(*this + Result * (a_OtherEnd - *this)).z = a_Z
+ If the line is too close to being parallel, this function returns NO_INTERSECTION
*/
double LineCoeffToXYPlane(const Vector3d & a_OtherEnd, double a_Z) const;
/** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified Y coord
The result satisfies the following equation:
(*this + Result * (a_OtherEnd - *this)).y = a_Y
+ If the line is too close to being parallel, this function returns NO_INTERSECTION
*/
double LineCoeffToXZPlane(const Vector3d & a_OtherEnd, double a_Y) const;
/** Returns the coefficient for the (a_OtherEnd - this) line to reach the specified X coord
The result satisfies the following equation:
(*this + Result * (a_OtherEnd - *this)).x = a_X
+ If the line is too close to being parallel, this function returns NO_INTERSECTION
*/
double LineCoeffToYZPlane(const Vector3d & a_OtherEnd, double a_X) const;
@@ -69,6 +69,9 @@ public:
Vector3d operator / (const double f) const { return Vector3d(x / f, y / f, z / f ); }
double x, y, z;
+
+ static const double EPS; ///< The max difference between two coords for which the coords are assumed equal
+ static const double NO_INTERSECTION; ///< Return value of LineCoeffToPlane() if the line is parallel to the plane
} ;
// tolua_end