From 51596c60a904a82e38deac9ba79c528bf51f5a7a Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sat, 30 Mar 2013 10:54:05 +0000 Subject: cTracer: Fixed asserts for invalid coords git-svn-id: http://mc-server.googlecode.com/svn/trunk@1327 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Tracer.cpp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'source') diff --git a/source/Tracer.cpp b/source/Tracer.cpp index fb1ab6c3b..548be8163 100644 --- a/source/Tracer.cpp +++ b/source/Tracer.cpp @@ -99,17 +99,33 @@ void cTracer::SetValues( const Vector3f & a_Start, const Vector3f & a_Direction } } + + + + int cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance) { - SetValues( a_Start, a_Direction ); + if (a_Start.y < 0) + { + LOGD("%s: Start is below the world", __FUNCTION__); + return 0; + } + + SetValues(a_Start, a_Direction); - const Vector3f End = a_Start + (dir * (float)a_Distance); + Vector3f End = a_Start + (dir * (float)a_Distance); + + if (End.y < 0) + { + float dist = -a_Start.y / dir.y; + End = a_Start + (dir * dist); + } // end voxel coordinates end1.x = (int)floorf(End.x); end1.y = (int)floorf(End.y); end1.z = (int)floorf(End.z); - + // check if first is occupied if( pos.Equals( end1 ) ) { @@ -180,9 +196,9 @@ int cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int return false; } - char BlockID = m_World->GetBlock( pos.x, pos.y, pos.z ); - //No collision with water ;) - if ( BlockID != E_BLOCK_AIR || IsBlockWater(BlockID)) + BLOCKTYPE BlockID = m_World->GetBlock( pos.x, pos.y, pos.z ); + // No collision with water ;) + if ((BlockID != E_BLOCK_AIR) || IsBlockWater(BlockID)) // _X 2013_03_29: Why is the IsBlockWater condition here? water equals air? { BlockHitPosition = pos; int Normal = GetHitNormal(a_Start, End, pos ); @@ -196,6 +212,10 @@ int cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int return 0; } + + + + // return 1 = hit, other is not hit int LinesCross(float x0,float y0,float x1,float y1,float x2,float y2,float x3,float y3) { -- cgit v1.2.3