Cuberite
A lightweight, fast and extensible game server for Minecraft
LineBlockTracer.h
Go to the documentation of this file.
1 
2 // LineBlockTracer.h
3 
4 // Declares the cLineBlockTracer class representing a cBlockTracer that traces along a straight line between two points
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "BlockTracer.h"
13 
14 
15 
16 
17 
18 // fwd: Chunk.h
19 class cChunk;
20 
21 
22 
23 
24 
26  public cBlockTracer
27 {
28  typedef cBlockTracer super;
29 
30 public:
32  {
33  // Bit flags used for LineOfSightTrace's Sight parameter:
34  losAir = 1, // Can see through air
35  losWater = 2, // Can see through water
36  losLava = 4, // Can see through lava
37 
38  // Common combinations:
41  };
42 
43 
44  cLineBlockTracer(cWorld & a_World, cCallbacks & a_Callbacks);
45 
47  bool Trace(double a_StartX, double a_StartY, double a_StartZ, double a_EndX, double a_EndY, double a_EndZ);
48 
49  // Utility functions for simple one-line usage:
50 
52  static bool Trace(cWorld & a_World, cCallbacks & a_Callbacks, double a_StartX, double a_StartY, double a_StartZ, double a_EndX, double a_EndY, double a_EndZ);
53 
55  static bool Trace(cWorld & a_World, cCallbacks & a_Callbacks, const Vector3d & a_Start, const Vector3d & a_End);
56 
59  static bool LineOfSightTrace(cWorld & a_World, const Vector3d & a_Start, const Vector3d & a_End, int a_Sight);
60 
67  static bool FirstSolidHitTrace(
68  cWorld & a_World,
69  const Vector3d & a_Start, const Vector3d & a_End,
70  Vector3d & a_HitCoords,
71  Vector3i & a_HitBlockCoords,
72  eBlockFace & a_HitBlockFace
73  );
74 
75 protected:
78 
80  double m_EndX, m_EndY, m_EndZ;
81 
84 
87 
90 
93 
94 
96  void FixStartAboveWorld(void);
97 
99  void FixStartBelowWorld(void);
100 
102  void CalcXZIntersection(double a_Y, double & a_IntersectX, double & a_IntersectZ);
103 
105  bool MoveToNextBlock(void);
106 
107  bool ChunkCallback(cChunk * a_Chunk);
108 } ;
109 
110 
111 
112 
113 
int m_CurrentX
The current block.
eBlockFace m_CurrentFace
The face through which the current block has been entered.
bool MoveToNextBlock(void)
Moves m_Current to the next block on the line; returns false if no move is possible (reached the end)...
cBlockTracer super
static bool LineOfSightTrace(cWorld &a_World, const Vector3d &a_Start, const Vector3d &a_End, int a_Sight)
Returns true if the two positions are within line of sight (not obscured by blocks).
double m_EndX
The end point of the trace.
Definition: Chunk.h:49
void FixStartAboveWorld(void)
Adjusts the start point above the world to just at the world's top.
void CalcXZIntersection(double a_Y, double &a_IntersectX, double &a_IntersectZ)
Calculates the XZ coords of an intersection with the specified Yconst plane; assumes that such an int...
Definition: World.h:65
double m_DiffX
The difference in coords, End - Start.
void FixStartBelowWorld(void)
Adjusts the start point below the world to just at the world's bottom.
int m_DirX
The increment at which the block coords are going from Start to End; either +1 or -1...
bool ChunkCallback(cChunk *a_Chunk)
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
Definition: Defines.h:29
bool Trace(double a_StartX, double a_StartY, double a_StartZ, double a_EndX, double a_EndY, double a_EndZ)
Traces one line between Start and End; returns true if the entire line was traced (until OnNoMoreHits...
static bool FirstSolidHitTrace(cWorld &a_World, const Vector3d &a_Start, const Vector3d &a_End, Vector3d &a_HitCoords, Vector3i &a_HitBlockCoords, eBlockFace &a_HitBlockFace)
Traces until the first solid block is hit (or until end, whichever comes first.
double m_StartX
The start point of the trace.
cLineBlockTracer(cWorld &a_World, cCallbacks &a_Callbacks)