summaryrefslogtreecommitdiffstats
path: root/src/Tracer.cpp
diff options
context:
space:
mode:
authorWoazboat <f.kargl@posteo.de>2015-04-28 02:47:36 +0200
committerWoazboat <f.kargl@posteo.de>2015-05-08 15:12:32 +0200
commitc74bfc35d61022c1d1e660935601d461b39b8b88 (patch)
tree4e156383745ae637976a7c93757e5ea02fe78ce9 /src/Tracer.cpp
parentChanged Tracer::m_NormalTable to static array (diff)
downloadcuberite-c74bfc35d61022c1d1e660935601d461b39b8b88.tar
cuberite-c74bfc35d61022c1d1e660935601d461b39b8b88.tar.gz
cuberite-c74bfc35d61022c1d1e660935601d461b39b8b88.tar.bz2
cuberite-c74bfc35d61022c1d1e660935601d461b39b8b88.tar.lz
cuberite-c74bfc35d61022c1d1e660935601d461b39b8b88.tar.xz
cuberite-c74bfc35d61022c1d1e660935601d461b39b8b88.tar.zst
cuberite-c74bfc35d61022c1d1e660935601d461b39b8b88.zip
Diffstat (limited to 'src/Tracer.cpp')
-rw-r--r--src/Tracer.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/Tracer.cpp b/src/Tracer.cpp
index bd5fcebc5..38968bc61 100644
--- a/src/Tracer.cpp
+++ b/src/Tracer.cpp
@@ -69,6 +69,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;
@@ -78,10 +81,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
@@ -151,6 +152,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);