10inline constexpr f32 pi = 3.14159265358979f;
28constexpr vec2 operator-(
vec2 a,
vec2 b) {
return {a.x - b.x, a.y - b.y}; }
29constexpr vec2 operator*(
vec2 a,
vec2 b) {
return {a.x * b.x, a.y * b.y}; }
30constexpr vec2 operator/(
vec2 a,
vec2 b) {
return {a.x / b.x, a.y / b.y}; }
31constexpr vec2 operator*(
vec2 a,
f32 s) {
return {a.x * s, a.y * s}; }
32constexpr vec2 operator*(
f32 s,
vec2 a) {
return {a.x * s, a.y * s}; }
33constexpr vec2 operator/(
vec2 a,
f32 s) {
return {a.x / s, a.y / s}; }
34constexpr vec2 operator-(
vec2 a) {
return {-a.x, -a.y}; }
35constexpr vec2 &operator+=(
vec2 &a,
vec2 b) {
return a = a + b; }
36constexpr vec2 &operator-=(
vec2 &a,
vec2 b) {
return a = a - b; }
37constexpr vec2 &operator*=(
vec2 &a,
f32 s) {
return a = a * s; }
38constexpr vec2 &operator/=(
vec2 &a,
f32 s) {
return a = a / s; }
39constexpr bool operator==(
vec2 a,
vec2 b) {
return a.
x == b.x && a.y == b.y; }
40constexpr bool operator!=(
vec2 a,
vec2 b) {
return !(a == b); }
76 return len > 0.0f ? v / len :
vec2{0.0f, 0.0f};
84 const f32 r = degrees * (
pi / 180.0f);
85 const f32 c = std::cos(r);
86 const f32 s = std::sin(r);
87 return {v.
x * c - v.
y * s, v.
x * s + v.
y * c};
102constexpr vec3 operator+(vec3 a, vec3 b) {
return {a.x + b.x, a.y + b.y, a.z + b.z}; }
103constexpr vec3 operator-(
vec3 a,
vec3 b) {
return {a.x - b.x, a.y - b.y, a.z - b.z}; }
104constexpr vec3 operator*(
vec3 a,
f32 s) {
return {a.x * s, a.y * s, a.z * s}; }
105constexpr vec3 operator*(
f32 s,
vec3 a) {
return {a.x * s, a.y * s, a.z * s}; }
106constexpr vec3 operator/(
vec3 a,
f32 s) {
return {a.x / s, a.y / s, a.z / s}; }
107constexpr vec3 operator-(
vec3 a) {
return {-a.x, -a.y, -a.z}; }
108constexpr vec3 &operator+=(
vec3 &a,
vec3 b) {
return a = a + b; }
109constexpr vec3 &operator-=(
vec3 &a,
vec3 b) {
return a = a - b; }
110constexpr vec3 &operator*=(
vec3 &a,
f32 s) {
return a = a * s; }
111constexpr bool operator==(
vec3 a,
vec3 b) {
return a.
x == b.x && a.y == b.y && a.z == b.z; }
112constexpr bool operator!=(
vec3 a,
vec3 b) {
return !(a == b); }
126 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};
150 return len > 0.0f ? v / len :
vec3{0.0f, 0.0f, 0.0f};
204 return to > from ? (from + max_step > to ? to : from + max_step)
205 : (from - max_step < to ? to : from - max_step);
214 const vec2 d = to - from;
216 return len <= max_step || len == 0.0f ? to : from + d / len * max_step;
229 return {center - size * 0.5f, size};
236inline constexpr rgba red{0.9f, 0.16f, 0.22f, 1.0f};
238inline constexpr rgba blue{0.0f, 0.47f, 0.95f, 1.0f};
240inline constexpr rgba gray{0.51f, 0.51f, 0.51f, 1.0f};
constexpr f32 length_sq(vec2 v)
Bình phương độ dài.
Definition _math.h:58
constexpr f32 clamp(f32 v, f32 lo, f32 hi)
Giới hạn v trong khoảng [lo, hi].
Definition _math.h:165
f32 distance(vec2 a, vec2 b)
Khoảng cách giữa hai điểm.
Definition _math.h:69
constexpr f32 move_toward(f32 from, f32 to, f32 max_step)
Di chuyển from về phía to một đoạn tối đa max_step, không vượt quá.
Definition _math.h:203
vec2 rotate(vec2 v, f32 degrees)
Xoay vector theo chiều kim đồng hồ trên màn hình (trục y hướng xuống).
Definition _math.h:83
constexpr vec3 lerp(vec3 a, vec3 b, f32 t)
Nội suy tuyến tính giữa hai vector.
Definition _math.h:158
constexpr f32 dot(vec2 a, vec2 b)
Tích vô hướng.
Definition _math.h:47
constexpr vec2 rect_center(rect r)
Tâm của hình chữ nhật.
Definition _math.h:222
f32 length(vec2 v)
Độ dài.
Definition _math.h:63
constexpr f32 pi
Số pi.
Definition _math.h:10
constexpr f32 cross(vec2 a, vec2 b)
Tích có hướng 2D (thành phần z của tích có hướng 3D).
Definition _math.h:53
vec2 from_angle(f32 degrees)
Vector độ dài 1 theo một góc, 0 độ là hướng sang phải, tăng theo chiều kim đồng hồ trên màn hình.
Definition _math.h:94
f32 angle_of(vec2 v)
Góc của vector, cùng quy ước với from_angle().
Definition _math.h:99
vec2 normalize(vec2 v)
Vector cùng hướng, độ dài 1.
Definition _math.h:74
constexpr rect rect_from_center(vec2 center, vec2 size)
Tạo hình chữ nhật từ tâm và kích thước.
Definition _math.h:228
float f32
Số thực 32 bit.
Definition _types.h:28
Các màu hay dùng.
Definition _math.h:233
constexpr rgba yellow
Vàng.
Definition _math.h:239
constexpr rgba white
Trắng.
Definition _math.h:234
constexpr rgba red
Đỏ.
Definition _math.h:236
constexpr rgba black
Đen.
Definition _math.h:235
constexpr rgba green
Xanh lá.
Definition _math.h:237
constexpr rgba transparent
Trong suốt.
Definition _math.h:241
constexpr rgba blue
Xanh dương.
Definition _math.h:238
constexpr rgba gray
Xám.
Definition _math.h:240
Hình tròn.
Definition _math.h:19
vec2 center
Tâm.
Definition _math.h:20
f32 radius
Bán kính.
Definition _math.h:21
Hình chữ nhật thẳng trục: pos là góc trên trái, size là rộng và cao.
Definition _math.h:13
vec2 pos
Góc trên trái.
Definition _math.h:14
vec2 size
Chiều rộng (x) và chiều cao (y).
Definition _math.h:15
Màu gồm đỏ, xanh lá, xanh dương và alpha.
Definition _types.h:64
f32 r
Đỏ.
Definition _types.h:65
f32 a
Độ đục (0 = trong suốt, 1 = đục hoàn toàn).
Definition _types.h:68
f32 g
Xanh lá.
Definition _types.h:66
f32 b
Xanh dương.
Definition _types.h:67
Vector 2 chiều. Dùng cho vị trí, kích thước, độ dời.
Definition _types.h:39
f32 y
Thành phần dọc (trong không gian màn hình, y tăng khi đi xuống).
Definition _types.h:41
f32 x
Thành phần ngang.
Definition _types.h:40
Vector 3 chiều.
Definition _types.h:47
f32 x
Thành phần thứ nhất.
Definition _types.h:48
f32 z
Thành phần thứ ba.
Definition _types.h:50
f32 y
Thành phần thứ hai.
Definition _types.h:49