From e37531fe0104b1f97d75a24d2b0e03bf507eded8 Mon Sep 17 00:00:00 2001 From: Samuel Barney Date: Tue, 5 Nov 2013 09:22:28 -0700 Subject: Moved cTracer::SetValues to be an internal function because it is only ever used in cTracer::Trace. Removed SetValues from Bindings.cpp. Added some commenting to explain what each function does in cTracer. --- source/Tracer.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'source/Tracer.h') diff --git a/source/Tracer.h b/source/Tracer.h index 2f627366f..a4e2d352e 100644 --- a/source/Tracer.h +++ b/source/Tracer.h @@ -12,14 +12,29 @@ public: // tolua_export Vector3f BoxOffset; cTracer( cWorld* a_World); // tolua_export ~cTracer(); // tolua_export + + /// Determines if a collision occures along a line. int Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance ); // tolua_export - void SetValues( const Vector3f & a_Start, const Vector3f & a_Direction ); // tolua_export + + /// Contains the position of the block that caused the collision Vector3f BlockHitPosition; // tolua_export + + /// Contains which face was hit Vector3f HitNormal; // tolua_export + + /// Contains the exact position where a collision occured. (BlockHitPosition + Offset on block) Vector3f RealHit; // tolua_export private: + + /// Preps Tracer object for call of Trace function. Only used internally + void SetValues( const Vector3f & a_Start, const Vector3f & a_Direction ); + + /// Calculates where on the block a collision occured, if it does occur int intersect3D_SegmentPlane( const Vector3f & a_Origin, const Vector3f & a_End, const Vector3f & a_PlanePos, const Vector3f & a_PlaneNormal ); + + /// Determines which face on the block a collision occured, if it does occur int GetHitNormal( const Vector3f & start, const Vector3f & end, const Vector3i & a_BlockPos); + float SigNum( float a_Num ); cWorld* m_World; -- cgit v1.2.3 From 9d5d74d826ceaa227c3d1684dde0743c08ae1175 Mon Sep 17 00:00:00 2001 From: Samuel Barney Date: Tue, 5 Nov 2013 14:01:51 -0700 Subject: Added more documentation. Changed cTracer::Trace to return a bool instead of an int because it was only returning 1 or 0 anyways. --- source/Tracer.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'source/Tracer.h') diff --git a/source/Tracer.h b/source/Tracer.h index a4e2d352e..85cb406c8 100644 --- a/source/Tracer.h +++ b/source/Tracer.h @@ -13,8 +13,8 @@ public: // tolua_export cTracer( cWorld* a_World); // tolua_export ~cTracer(); // tolua_export - /// Determines if a collision occures along a line. - int Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance ); // tolua_export + /// Determines if a collision occures along a line. Returns true if a collision occurs. + bool Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance); // tolua_export /// Contains the position of the block that caused the collision Vector3f BlockHitPosition; // tolua_export @@ -26,13 +26,18 @@ public: // tolua_export Vector3f RealHit; // tolua_export private: - /// Preps Tracer object for call of Trace function. Only used internally + /// Preps Tracer object for call of Trace function. Only used internally. void SetValues( const Vector3f & a_Start, const Vector3f & a_Direction ); /// Calculates where on the block a collision occured, if it does occur + /// Returns 0 if no intersection occured + /// Returns 1 if an intersection occured at a single point + /// Returns 2 if the line segment lies in the plane being checked int intersect3D_SegmentPlane( const Vector3f & a_Origin, const Vector3f & a_End, const Vector3f & a_PlanePos, const Vector3f & a_PlaneNormal ); /// Determines which face on the block a collision occured, if it does occur + /// Returns 0 if the block is air, water or no collision occured + /// Return 1 through 6 for the following block faces, repectively: -x, -z, x, z, y, -y int GetHitNormal( const Vector3f & start, const Vector3f & end, const Vector3i & a_BlockPos); float SigNum( float a_Num ); -- cgit v1.2.3 From eefc6d37efd266edad5d1a2cbc2ea6e543e60cc2 Mon Sep 17 00:00:00 2001 From: Samuel Barney Date: Tue, 5 Nov 2013 14:11:13 -0700 Subject: cTracer can now handle mob sight. --- source/Tracer.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source/Tracer.h') diff --git a/source/Tracer.h b/source/Tracer.h index 85cb406c8..dc393ae5e 100644 --- a/source/Tracer.h +++ b/source/Tracer.h @@ -14,7 +14,12 @@ public: // tolua_export ~cTracer(); // tolua_export /// Determines if a collision occures along a line. Returns true if a collision occurs. - bool Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance); // tolua_export + bool Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance) // tolua_export + { + return Trace(a_Start, a_Direction, a_Distance, false); + } + + bool Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance, bool a_LineOfSight); // tolua_export /// Contains the position of the block that caused the collision Vector3f BlockHitPosition; // tolua_export -- cgit v1.2.3 From e6ace0e4f26afba50df1ad21e399fd76e4fcb19e Mon Sep 17 00:00:00 2001 From: Samuel Barney Date: Tue, 5 Nov 2013 14:19:49 -0700 Subject: More documentation. --- source/Tracer.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source/Tracer.h') diff --git a/source/Tracer.h b/source/Tracer.h index dc393ae5e..bc348d955 100644 --- a/source/Tracer.h +++ b/source/Tracer.h @@ -18,7 +18,10 @@ public: // tolua_export { return Trace(a_Start, a_Direction, a_Distance, false); } - + + /// Determines if a collision occures along a line. Returns true if a collision occurs. + /// When a_LineOfSight is true, we don't use the standard collision detection rules. Instead we use + /// the rules for monster vision. E.g. Only water and air do not block vision. bool Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance, bool a_LineOfSight); // tolua_export /// Contains the position of the block that caused the collision -- cgit v1.2.3