VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
Math.hpp
Go to the documentation of this file.
1#pragma once
2
3// Include this for Vector and QAngle instead of the SDK's <mathlib/vector.h>.
4#include <mathlib/vector.h>
5#include <numbers>
6
7namespace VoltMod
8{
9
10/** The engine's Vector. Its default constructor leaves the value uninitialised; write
11 * `Vector{0.0f, 0.0f, 0.0f}` for a zero. */
13
14/** The engine's angles in degrees: (pitch, yaw, roll), positive pitch looks down. */
16
17inline constexpr float DegreesPerRadian = 180.0f / std::numbers::pi_v<float>;
18
19/** The unit vector @p angles aim along; roll does not change it. */
20Vector AngleToForward(const QAngle& angles);
21
22/** The level unit vector heading @p yaw degrees. */
23Vector YawToForward(float yaw);
24
25/** A body's unit forward, left and up vectors. Left is the engine's right axis reversed. */
26struct Axes
27{
28 Vector Forward{1.0f, 0.0f, 0.0f};
29 Vector Left{0.0f, 1.0f, 0.0f};
30 Vector Up{0.0f, 0.0f, 1.0f};
31
32 /** As engine angles, with pitch and yaw in [-180, 180]. */
33 QAngle ToAngles() const;
34};
35
36/** The axes of a body turned to @p angles. */
37Axes AngleToAxes(const QAngle& angles);
38
39/** The point @p forwardLeftUp away from @p origin along the axes of @p angles, such as a muzzle on a
40 * turret that turns and pitches about @p origin. */
41Vector OffsetLocal(const Vector& origin, const QAngle& angles, const Vector& forwardLeftUp);
42
43/** The angles that aim from @p from at @p to, with no roll. Pitch is in [-90, 90], positive down, as
44 * the engine has it. */
45QAngle AngleTo(const Vector& from, const Vector& to);
46
47/** How far @p to is from @p from in degrees, the short way round, in [-180, 180). */
48float AngleDelta(float from, float to);
49
50/** @p current turned toward @p target by at most @p maxStep degrees, the short way round. */
51float TurnToward(float current, float target, float maxStep);
52
53} // namespace VoltMod
QAngle AngleTo(const Vector &from, const Vector &to)
Definition Math.cpp:42
Axes AngleToAxes(const QAngle &angles)
Definition Math.cpp:27
Vector AngleToForward(const QAngle &angles)
Definition Math.cpp:9
::QAngle QAngle
Definition Math.hpp:15
Vector YawToForward(float yaw)
Definition Math.cpp:16
float TurnToward(float current, float target, float maxStep)
Definition Math.cpp:55
::Vector Vector
Definition Math.hpp:12
float AngleDelta(float from, float to)
Definition Math.cpp:49
Vector OffsetLocal(const Vector &origin, const QAngle &angles, const Vector &forwardLeftUp)
Definition Math.cpp:36
constexpr float DegreesPerRadian
Definition Math.hpp:17
Vector Left
Definition Math.hpp:29
QAngle ToAngles() const
Definition Math.cpp:21
Vector Up
Definition Math.hpp:30
Vector Forward
Definition Math.hpp:28