2013-08-04 07:25:48 -04:00
|
|
|
|
|
|
|
// LineBlockTracer.h
|
|
|
|
|
|
|
|
// Declares the cLineBlockTracer class representing a cBlockTracer that traces along a straight line between two points
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockTracer.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fwd: Chunk.h
|
|
|
|
class cChunk;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-13 12:38:06 -04:00
|
|
|
class cLineBlockTracer:
|
2017-09-11 17:20:49 -04:00
|
|
|
public cBlockTracer
|
2013-08-04 07:25:48 -04:00
|
|
|
{
|
2020-04-13 12:38:06 -04:00
|
|
|
using Super = cBlockTracer;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-08-04 07:25:48 -04:00
|
|
|
public:
|
2020-04-13 12:38:06 -04:00
|
|
|
|
2017-05-11 08:34:36 -04:00
|
|
|
enum eLineOfSight
|
|
|
|
{
|
|
|
|
// Bit flags used for LineOfSightTrace's Sight parameter:
|
|
|
|
losAir = 1, // Can see through air
|
|
|
|
losWater = 2, // Can see through water
|
|
|
|
losLava = 4, // Can see through lava
|
|
|
|
|
|
|
|
// Common combinations:
|
|
|
|
losAirWaterLava = losAir | losWater | losLava,
|
|
|
|
losAirWater = losAir | losWater,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-04 07:25:48 -04:00
|
|
|
cLineBlockTracer(cWorld & a_World, cCallbacks & a_Callbacks);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Traces one line between Start and End; returns true if the entire line was traced (until OnNoMoreHits()) */
|
2020-05-08 05:04:07 -04:00
|
|
|
bool Trace(Vector3d a_Start, Vector3d a_End);
|
2013-08-04 07:25:48 -04:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
|
2020-05-08 05:04:07 -04:00
|
|
|
// Utility functions for simple one-line usage:
|
2013-08-04 07:25:48 -04:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Traces one line between Start and End; returns true if the entire line was traced (until OnNoMoreHits()) */
|
2020-05-08 05:04:07 -04:00
|
|
|
static bool Trace(cWorld & a_World, cCallbacks & a_Callbacks, const Vector3d a_Start, const Vector3d a_End);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2017-05-11 08:34:36 -04:00
|
|
|
/** Returns true if the two positions are within line of sight (not obscured by blocks).
|
|
|
|
a_Sight specifies which blocks are considered transparent for the trace, is an OR-combination of eLineOfSight constants. */
|
|
|
|
static bool LineOfSightTrace(cWorld & a_World, const Vector3d & a_Start, const Vector3d & a_End, int a_Sight);
|
|
|
|
|
|
|
|
/** Traces until the first solid block is hit (or until end, whichever comes first.
|
|
|
|
If a solid block was hit, returns true and fills a_HitCoords, a_HitBlockCoords and a_HitBlockFace.
|
|
|
|
If a_End is encountered without hitting any solid block, returns false and doesn't touch a_HitCoords, a_HitBlockCoords nor a_HitBlockFace.
|
|
|
|
a_HitCoords is the exact coords of the hit,
|
|
|
|
a_HitBlockCoords are the coords of the solid block that was hit,
|
|
|
|
a_HitBlockFace is the face of the solid block that was hit. */
|
|
|
|
static bool FirstSolidHitTrace(
|
|
|
|
cWorld & a_World,
|
|
|
|
const Vector3d & a_Start, const Vector3d & a_End,
|
|
|
|
Vector3d & a_HitCoords,
|
|
|
|
Vector3i & a_HitBlockCoords,
|
|
|
|
eBlockFace & a_HitBlockFace
|
|
|
|
);
|
|
|
|
|
2013-08-04 07:25:48 -04:00
|
|
|
protected:
|
2015-07-31 10:49:10 -04:00
|
|
|
/** The start point of the trace */
|
2020-05-08 05:04:07 -04:00
|
|
|
Vector3d m_Start;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** The end point of the trace */
|
2020-05-08 05:04:07 -04:00
|
|
|
Vector3d m_End;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** The difference in coords, End - Start */
|
2020-05-08 05:04:07 -04:00
|
|
|
Vector3d m_Diff;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** The increment at which the block coords are going from Start to End; either +1 or -1 */
|
2020-05-08 05:04:07 -04:00
|
|
|
Vector3i m_Dir;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** The current block */
|
2020-05-08 05:04:07 -04:00
|
|
|
Vector3i m_Current;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** The face through which the current block has been entered */
|
2017-05-11 08:34:36 -04:00
|
|
|
eBlockFace m_CurrentFace;
|
2013-08-04 07:25:48 -04:00
|
|
|
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Adjusts the start point above the world to just at the world's top */
|
2013-08-04 07:25:48 -04:00
|
|
|
void FixStartAboveWorld(void);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Adjusts the start point below the world to just at the world's bottom */
|
2013-08-04 07:25:48 -04:00
|
|
|
void FixStartBelowWorld(void);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Calculates the XZ coords of an intersection with the specified Yconst plane; assumes that such an intersection exists */
|
2013-08-04 07:25:48 -04:00
|
|
|
void CalcXZIntersection(double a_Y, double & a_IntersectX, double & a_IntersectZ);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Moves m_Current to the next block on the line; returns false if no move is possible (reached the end) */
|
2013-08-04 07:25:48 -04:00
|
|
|
bool MoveToNextBlock(void);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2017-09-11 17:20:49 -04:00
|
|
|
bool ChunkCallback(cChunk * a_Chunk);
|
2013-08-04 07:25:48 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|