2013-11-09 13:49:36 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
#pragma once
|
|
|
|
|
2014-03-11 10:01:17 -04:00
|
|
|
#include "Vector3.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2015-04-28 18:14:42 -04:00
|
|
|
#include <array>
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-11-09 13:49:36 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fwd:
|
2012-06-14 09:06:06 -04:00
|
|
|
class cWorld;
|
2013-11-09 13:49:36 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// tolua_begin
|
|
|
|
|
|
|
|
class cTracer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Contains the position of the block that caused the collision */
|
2013-11-09 13:49:36 -05:00
|
|
|
Vector3f BlockHitPosition;
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Contains which face was hit */
|
2013-11-09 13:49:36 -05:00
|
|
|
Vector3f HitNormal;
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Contains the exact position where a collision occured. (BlockHitPosition + Offset on block) */
|
2013-11-09 13:49:36 -05:00
|
|
|
Vector3f RealHit;
|
|
|
|
|
|
|
|
|
|
|
|
cTracer(cWorld * a_World);
|
|
|
|
~cTracer();
|
2013-11-05 11:22:28 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Determines if a collision occures along a line. Returns true if a collision occurs. */
|
2013-11-09 13:49:36 -05:00
|
|
|
bool Trace(const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance)
|
2013-11-05 16:11:13 -05:00
|
|
|
{
|
|
|
|
return Trace(a_Start, a_Direction, a_Distance, false);
|
|
|
|
}
|
2013-11-05 16:19:49 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** 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.
|
|
|
|
a_Distance is the number of iterations (blocks hits) that are tested. */
|
2013-11-09 13:49:36 -05:00
|
|
|
bool Trace(const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance, bool a_LineOfSight);
|
2013-11-05 11:22:28 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
private:
|
2013-11-05 11:22:28 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Preps Tracer object for call of Trace function. Only used internally. */
|
|
|
|
void SetValues(const Vector3f & a_Start, const Vector3f & a_Direction);
|
2013-11-05 11:22:28 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** 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);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** 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);
|
2013-11-05 11:22:28 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Signum function */
|
2015-05-09 05:16:56 -04:00
|
|
|
int SigNum(float a_Num);
|
|
|
|
|
|
|
|
cWorld * m_World;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2015-04-28 18:14:42 -04:00
|
|
|
static const std::array<const Vector3f, 6> & m_NormalTable(void);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
Vector3f dir;
|
|
|
|
Vector3f tDelta;
|
|
|
|
Vector3i pos;
|
|
|
|
Vector3i end1;
|
|
|
|
Vector3i step;
|
|
|
|
Vector3f tMax;
|
2013-11-09 13:49:36 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// tolua_end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|