summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWoazboat <f.kargl@posteo.de>2015-04-28 02:47:36 +0200
committerWoazboat <f.kargl@posteo.de>2015-04-28 02:47:36 +0200
commit797e3130d2ae721688b53dbaa2831d441ba0138a (patch)
treea334c0cba214405a0fcf68455bfb5b3ef9168323
parentconvert c style casts to c++ static casts (diff)
downloadcuberite-797e3130d2ae721688b53dbaa2831d441ba0138a.tar
cuberite-797e3130d2ae721688b53dbaa2831d441ba0138a.tar.gz
cuberite-797e3130d2ae721688b53dbaa2831d441ba0138a.tar.bz2
cuberite-797e3130d2ae721688b53dbaa2831d441ba0138a.tar.lz
cuberite-797e3130d2ae721688b53dbaa2831d441ba0138a.tar.xz
cuberite-797e3130d2ae721688b53dbaa2831d441ba0138a.tar.zst
cuberite-797e3130d2ae721688b53dbaa2831d441ba0138a.zip
-rw-r--r--src/Tracer.cpp14
-rw-r--r--src/Vector3.h5
2 files changed, 15 insertions, 4 deletions
diff --git a/src/Tracer.cpp b/src/Tracer.cpp
index 3f9501e1f..816bc0fe8 100644
--- a/src/Tracer.cpp
+++ b/src/Tracer.cpp
@@ -56,6 +56,9 @@ float cTracer::SigNum(float a_Num)
void cTracer::SetValues(const Vector3f & a_Start, const Vector3f & a_Direction)
{
+ // Since this method should only be called by Trace, zero length vectors should already have been taken care of
+ ASSERT(a_Direction.hasNonZeroLength());
+
// calculate the direction of the ray (linear algebra)
dir = a_Direction;
@@ -65,10 +68,8 @@ void cTracer::SetValues(const Vector3f & a_Start, const Vector3f & a_Direction)
step.z = (int) SigNum(dir.z);
// normalize the direction vector
- if (dir.SqrLength() > 0.f)
- {
- dir.Normalize();
- }
+ dir.Normalize();
+
// how far we must move in the ray direction before
// we encounter a new voxel in x-direction
@@ -139,6 +140,11 @@ void cTracer::SetValues(const Vector3f & a_Start, const Vector3f & a_Direction)
bool cTracer::Trace(const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance, bool a_LineOfSight)
{
+ if(!a_Direction.hasNonZeroLength())
+ {
+ return false;
+ }
+
if ((a_Start.y < 0) || (a_Start.y >= cChunkDef::Height))
{
LOGD("%s: Start Y is outside the world (%.2f), not tracing.", __FUNCTION__, a_Start.y);
diff --git a/src/Vector3.h b/src/Vector3.h
index 36f277ba4..f1fb2d257 100644
--- a/src/Vector3.h
+++ b/src/Vector3.h
@@ -78,6 +78,11 @@ public:
);
}
+ inline bool hasNonZeroLength(void) const
+ {
+ return ((x != 0) || (y != 0) || (z != 0));
+ }
+
inline double Length(void) const
{
return sqrt(static_cast<double>(x * x + y * y + z * z));