QcRaycast Namespace
Voxel traversal (Amanatides & Woo) along a ray, tested against the boxes of each block state: the drawn boxes of every block that is neither air nor liquid nor invisible, or the collision boxes only (including the part of a fence above its own cell). More...
| Header: | #include <common/physics/QcRaycast.h> |
Types
| enum class | Targets { Visible, Solid, VisibleAndLiquids } |
Variables
| const double | playerReach |
| const double | reachTolerance |
Functions
| std::optional<QcRaycastHit> | cast(const QcBlockAccess &world, const QcVec3 &origin, const QcVec3 &direction, double maxDistance, QcRaycast::Targets targets = Targets::Visible) |
| std::optional<double> | intersectBox(const QcVec3 &origin, const QcVec3 &direction, const QcAabb &box, double maxDistance) |
| std::optional<std::pair<double, QcBlockFace>> | intersectBoxFace(const QcVec3 &origin, const QcVec3 &direction, const QcAabb &box, double maxDistance, QcBlockFace insideFace) |
| bool | isWithinReach(const QcVec3 &eye, QcBlockPos pos) |
Detailed Description
Unloaded chunks stop the ray without a hit.
Type Documentation
enum class QcRaycast::Targets
What a ray hits.
| Constant | Value | Description |
|---|---|---|
QcRaycast::Targets::Visible | 0 | What the player can point at (also plants and torches). |
QcRaycast::Targets::Solid | 1 | What bodies collide with. |
QcRaycast::Targets::VisibleAndLiquids | 2 | Visible blocks and liquids (an empty bucket takes a liquid). |
Variable Documentation
const double QcRaycast::playerReach
How far a player reaches, in metres from the eye.
const double QcRaycast::reachTolerance
Slack of the server's reach check beyond playerReach (network jitter, a turn while clicking).
Function Documentation
std::optional<QcRaycastHit> QcRaycast::cast(const QcBlockAccess &world, const QcVec3 &origin, const QcVec3 &direction, double maxDistance, QcRaycast::Targets targets = Targets::Visible)
Returns the first block of world that the ray from origin along direction (it need not be normalised) hits within maxDistance, testing the boxes targets names; nothing when it hits none or reaches an unloaded chunk.
std::optional<double> QcRaycast::intersectBox(const QcVec3 &origin, const QcVec3 &direction, const QcAabb &box, double maxDistance)
Returns the distance along the ray from origin along the normalised direction to box, or std::nullopt when it misses within maxDistance.
std::optional<std::pair<double, QcBlockFace>> QcRaycast::intersectBoxFace(const QcVec3 &origin, const QcVec3 &direction, const QcAabb &box, double maxDistance, QcBlockFace insideFace)
Returns as intersectBox() (origin, direction, box, maxDistance), also telling the face through which the ray enters (the face it starts in for rays from inside the box: the one it leaves through is not useful, so it reports insideFace).
bool QcRaycast::isWithinReach(const QcVec3 &eye, QcBlockPos pos)
Returns whether the block at pos may be used from eye: its centre within playerReach plus reachTolerance. The server checks every use with it, the client asks it before it counts a block as reacting to a use.