39 return {a.
x + b.
x, a.
y + b.
y, a.
z + b.
z};
43 return {a.
x - b.
x, a.
y - b.
y, a.
z - b.
z};
47 return {a.
x * s, a.
y * s, a.
z * s};
61 return a.
x * b.
x + a.
y * b.
y + a.
z * b.
z;
65 return {a.
y * b.
z - a.
z * b.
y, a.
z * b.
x - a.
x * b.
z, a.
x * b.
y - a.
y * b.
x};
70 const float magnitude =
length(a);
71 return magnitude > 1e-6f ? a * (1.0f / magnitude) :
Vec3{};
78 std::array<float, 16>
m{};
92 return {
m[0] * p.
x +
m[1] * p.
y +
m[2] * p.
z +
m[3],
93 m[4] * p.
x +
m[5] * p.
y +
m[6] * p.
z +
m[7],
94 m[8] * p.
x +
m[9] * p.
y +
m[10] * p.
z +
m[11],
95 m[12] * p.
x +
m[13] * p.
y +
m[14] * p.
z +
m[15]};
101 for (std::size_t row = 0; row < 4; ++row)
105 for (std::size_t k = 0; k < 4; ++k)
106 sum += a.
m[row * 4 + k] * b.
m[k * 4 +
column];
107 result.
m[row * 4 +
column] = sum;
121 cameraUp.
x, cameraUp.
y, cameraUp.
z, -
dot(cameraUp, eye),
122 -forward.x, -forward.y, -forward.z,
dot(forward, eye),
123 0.0f, 0.0f, 0.0f, 1.0f};
131 const float focal = 1.0f / std::tan(verticalFovRadians * 0.5f);
133 projection.
m[0] = focal / aspect;
134 projection.
m[5] = focal;
135 projection.
m[10] = (farPlane + nearPlane) / (nearPlane - farPlane);
136 projection.
m[11] = 2.0f * farPlane * nearPlane / (nearPlane - farPlane);
137 projection.
m[14] = -1.0f;
187 rect.
height * 0.5f / std::tan(verticalFovRadians * 0.5f);
196 const float inverseW = 1.0f / clip.
w;
225 float planeHeight = 0.0f)
const
228 if (direction.
z > -1e-4f)
return false;
229 const float distance = (planeHeight -
eye.
z) / direction.
z;
230 if (distance <= 0.0f)
return false;
231 out =
eye + direction * distance;
243template <
typename Vertex,
typename WOf,
typename Interpolate>
245 std::span<Vertex> output,
float nearPlane,
246 WOf wOf, Interpolate interpolate)
248 std::size_t written = 0;
249 const std::size_t count = input.size();
252 const Vertex& current = input[
index];
253 const Vertex& next = input[(
index + 1) % count];
254 const float currentDistance = wOf(current) - nearPlane;
255 const float nextDistance = wOf(next) - nearPlane;
256 if (currentDistance >= 0.0f && written < output.size())
257 output[written++] = current;
258 if ((currentDistance >= 0.0f) != (nextDistance >= 0.0f) &&
259 written < output.size())
261 output[written++] = interpolate(
262 current, next, currentDistance / (currentDistance - nextDistance));
271 return {a.
x + (b.
x - a.
x) * t, a.
y + (b.
y - a.
y) * t, a.
z + (b.
z - a.
z) * t,
272 a.
w + (b.
w - a.
w) * t};
277 std::span<Vec4> output,
281 input, output, nearPlane, [](
const Vec4& vertex) {
return vertex.
w; },
282 [](
const Vec4& a,
const Vec4& b,
float t) {
return lerp(a, b, t); });
288 constexpr float TWO_PI = 2.0f * std::numbers::pi_v<float>;
289 angle = std::fmod(angle + std::numbers::pi_v<float>, TWO_PI);
290 if (angle < 0.0f) angle += TWO_PI;
291 return angle - std::numbers::pi_v<float>;
303 return 1.0f - std::exp(-ratePerSecond * deltaSeconds);
321 if (number > 0 &&
claim(number))
return number;
322 for (
int number = 1; number <= 11; ++number)
323 if (
claim(number))
return number;
325 for (
int number = 12; number <
MAX_NUMBER; ++number)
326 if (
claim(number))
return number;
336 const std::uint64_t bit = std::uint64_t{1} << number;
337 if ((
used & bit) != 0U)
return false;
Definition match_render_math.h:314
std::uint64_t used
Definition match_render_math.h:332
static std::array< int, 3 > preferred(PlayerRole role)
Definition match_render_math.h:342
static constexpr int MAX_NUMBER
Definition match_render_math.h:331
int take(PlayerRole role, bool starter)
Definition match_render_math.h:316
bool claim(int number)
Definition match_render_math.h:334
Side side
Definition match_stadium_3d.cpp:389
Definition match_render_math.h:30
float worldYawFromFacing(float facingAngle)
Definition match_render_math.h:389
float dampingFactor(float ratePerSecond, float deltaSeconds)
Definition match_render_math.h:301
float lerpAngle(float from, float to, float t)
Definition match_render_math.h:295
constexpr Vec3 lerp(Vec3 a, Vec3 b, float t)
Definition match_render_math.h:73
constexpr float dot(Vec3 a, Vec3 b)
Definition match_render_math.h:59
float wrapAngle(float angle)
Definition match_render_math.h:286
Vec3 normalize(Vec3 a)
Definition match_render_math.h:68
Mat4 lookAt(Vec3 eye, Vec3 target, Vec3 up)
Definition match_render_math.h:114
std::size_t clipConvexToNearPlane(std::span< const Vertex > input, std::span< Vertex > output, float nearPlane, WOf wOf, Interpolate interpolate)
Definition match_render_math.h:244
Mat4 perspective(float verticalFovRadians, float aspect, float nearPlane, float farPlane)
Definition match_render_math.h:128
std::size_t clipPolygonToNearPlane(std::span< const Vec4 > input, std::span< Vec4 > output, float nearPlane)
Definition match_render_math.h:276
constexpr Vec3 cross(Vec3 a, Vec3 b)
Definition match_render_math.h:63
constexpr Vec3 worldFromPitch(Vector2F normalized, float heightMetres=0.0f)
Definition match_render_math.h:377
int index
Definition runtime_editor.cpp:94
std::string_view column
Definition runtime_editor_validation.cpp:45
static constexpr float WIDTH_METRES
Definition match_tuning.h:36
static constexpr float LENGTH_METRES
Definition match_tuning.h:35
Definition match_render_math.h:77
std::array< float, 16 > m
Definition match_render_math.h:78
static constexpr Mat4 identity()
Definition match_render_math.h:80
constexpr Vec4 transform(Vec3 p) const
Definition match_render_math.h:90
friend constexpr Mat4 operator*(const Mat4 &a, const Mat4 &b)
Definition match_render_math.h:98
Definition match_render_math.h:160
static Projection make(Vec3 eye, Vec3 target, float verticalFovRadians, float nearPlane, float farPlane, ScreenRect rect)
Definition match_render_math.h:172
Vec4 toClip(Vec3 point) const
Definition match_render_math.h:191
Mat4 viewProjection
Definition match_render_math.h:161
Vec3 rayThrough(float pixelX, float pixelY) const
Definition match_render_math.h:213
Vec3 up
Definition match_render_math.h:166
float depth(Vec3 point) const
Definition match_render_math.h:210
ScreenRect rect
Definition match_render_math.h:167
bool groundPointAt(float pixelX, float pixelY, Vec3 &out, float planeHeight=0.0f) const
Definition match_render_math.h:224
float nearPlane
Definition match_render_math.h:168
float focalPixels
Definition match_render_math.h:170
Vec3 forward
Definition match_render_math.h:163
bool project(Vec3 point, ScreenPoint &out) const
Definition match_render_math.h:202
Vec3 side
Definition match_render_math.h:165
Vec3 eye
Definition match_render_math.h:162
ScreenPoint clipToScreen(Vec4 clip) const
Definition match_render_math.h:194
Definition match_render_math.h:152
float depth
Definition match_render_math.h:155
float y
Definition match_render_math.h:154
float x
Definition match_render_math.h:153
Definition match_render_math.h:143
float y
Definition match_render_math.h:145
float width
Definition match_render_math.h:146
float x
Definition match_render_math.h:144
float height
Definition match_render_math.h:147
Definition match_render_math.h:32
friend constexpr Vec3 operator-(Vec3 a, Vec3 b)
Definition match_render_math.h:41
float x
Definition match_render_math.h:33
friend constexpr Vec3 operator+(Vec3 a, Vec3 b)
Definition match_render_math.h:37
friend constexpr Vec3 operator*(Vec3 a, float s)
Definition match_render_math.h:45
float z
Definition match_render_math.h:35
float y
Definition match_render_math.h:34
Definition match_render_math.h:52
float w
Definition match_render_math.h:56
float y
Definition match_render_math.h:54
float z
Definition match_render_math.h:55
float x
Definition match_render_math.h:53
A simple 2D float vector for pitch coordinates.
Definition types.h:84
float y
Definition types.h:86
float x
Definition types.h:85
float length
Definition synth.cpp:49
PlayerRole
Represents a specific tactical role on the pitch.
Definition types.h:63