Skip to content

Commit d1c67cb

Browse files
committed
math
1 parent 051e0fb commit d1c67cb

File tree

12 files changed

+616
-230
lines changed

12 files changed

+616
-230
lines changed
18.1 KB
Loading

current-scripts/Demos/useful-scripts/fonts/fnt_demo/fnt_demo.old.yy

Lines changed: 239 additions & 120 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
12.9 KB
Loading

current-scripts/Demos/useful-scripts/fonts/fnt_demo/fnt_demo.yy

Lines changed: 199 additions & 96 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
vec_A = new Vector2(3, 3);
2+
vec_B = new Vector2(-1, 2);
3+
vec_C = new Vector3(-2, 3, 4);
4+
vec_D = new Vector3(10, -5, 7);
5+
6+
pulse_counter = new ValueDelta(0, 0.01, 0, 1);
7+
pulse_t = 0;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
draw_set_font(fnt_title);
2+
draw_set_halign(fa_center);
3+
draw_set_colour(c_white);
4+
draw_text(room_width/2, 16, "Math Demo");
5+
6+
draw_set_halign(fa_left);
7+
draw_text(16, 64, "Vectors");
8+
draw_text(16, 176, "Normalized Vectors");
9+
draw_text(640, 64, "Cross Products");
10+
draw_text(640, 176, "Normalized Cross Product");
11+
12+
draw_text(16, 256, "Pulse");
13+
draw_sprite_ext(spr_meter, 0, 16, 288, 0.25, 0.25, 0, c_gray, 1);
14+
draw_sprite_ext(spr_meter, 0, 16, 288, 0.25, 0.25, 0, $80FFFF, pulse_t);
15+
16+
draw_set_font(fnt_demo);
17+
// Vectors
18+
draw_text(16, 96, "a = " + vec_A.to_string());
19+
draw_text(16, 128, "b = " + vec_B.to_string());
20+
draw_text(144, 96, "c = " + vec_C.to_string());
21+
draw_text(144, 128, "d = " + vec_D.to_string());
22+
23+
// Normalized Vectors
24+
draw_text(16, 208, "â = " + normalize_2d(vec_A).to_string());
25+
draw_text(192, 208, "ĉ = " + normalize_3d(vec_C).to_string());
26+
27+
// Cross Products
28+
draw_text(640, 96, "a x b = " + string(cross_product_2d(vec_A, vec_B)) + " (Z-component)");
29+
draw_text(640, 128, "c x d = " + cross_product(vec_C, vec_D).to_string());
30+
31+
// Normalized Cross Products
32+
draw_text(640, 208, "c x d / |c x d| = " + cross_product_normalized(vec_C, vec_D).to_string());
33+
34+
// Pulse
35+
draw_text(96, 288, "t: " + string(pulse_counter.v));
36+
draw_text(176, 288, "p(t): " + string(pulse_t));
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pulse_counter.update();
2+
pulse_t = pulse(pulse_counter.v, 0.5, 1);
3+
4+
if (pulse_counter.v == 1) {
5+
pulse_counter.v = 0;
6+
}

current-scripts/Demos/useful-scripts/objects/obj_math_demo/obj_math_demo.yy

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

current-scripts/Demos/useful-scripts/rooms/room_math_demo/room_math_demo.yy

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

current-scripts/Demos/useful-scripts/scripts/math_functions/math_functions.gml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
/// @func normalize_3d(vec)
2-
/// @desc Normalizes a Vector3
1+
/// @func normalize_2d(vec)
2+
/// @desc Normalizes a Vector2
3+
/// @param {Vector2} vec
4+
function normalize_2d(_vec) {
5+
var _len = point_distance(0, 0, _vec.x, _vec.y);
6+
return new Vector2(_vec.x / _len, _vec.y / _len);
7+
}
8+
9+
10+
/// @func normalize_3d(vec)
11+
/// @desc Normalizes a Vector3
312
/// @param {Vector3} vec
413
function normalize_3d(_vec) {
5-
var _len = point_distance_3d(0, 0, 0, _xp.x, _xp.y, _xp.z);
14+
var _len = point_distance_3d(0, 0, 0, _vec.x, _vec.y, _vec.z);
615
return new Vector3(_vec.x / _len, _vec.y / _len, _vec.z / _len);
716
}
817

918

10-
/// @func cross_product(vec1, vec2)
11-
/// @desc Calculates cross product of two Vector3s
19+
/// @func cross_product(vec1, vec2)
20+
/// @desc Calculates cross product of two Vector3s
1221
/// @param {Vector3} vec1
1322
/// @param {Vector3} vec2
1423
function cross_product(_vec1, _vec2) {
@@ -20,17 +29,17 @@ function cross_product(_vec1, _vec2) {
2029
}
2130

2231

23-
/// @func cross_product_2d(vec1, vec2)
24-
/// @desc Calculates the z-component of the "cross product" of two Vector2s
32+
/// @func cross_product_2d(vec1, vec2)
33+
/// @desc Calculates the z-component of the "cross product" of two Vector2s
2534
/// @param {Vector2} vec1
2635
/// @param {Vector2} vec2
2736
function cross_product_2d(_vec1, _vec2) {
28-
return _vec1.x*_vec2.y - _vec1.y*_vec2.x);
37+
return _vec1.x*_vec2.y - _vec1.y*_vec2.x;
2938
}
3039

3140

32-
/// @func cross_product_normalized(vec1, vec2)
33-
/// @desc Calculates the normalized cross product of two Vector3s
41+
/// @func cross_product_normalized(vec1, vec2)
42+
/// @desc Calculates the normalized cross product of two Vector3s
3443
/// @param {Vector3} vec1
3544
/// @param {Vector3} vec2
3645
function cross_product_normalized(_vec1, _vec2) {
@@ -49,8 +58,8 @@ function cross_product_normalized(_vec1, _vec2) {
4958
/// @param {real} min
5059
/// @param {real} max
5160
function pulse(_t, _min, _max) {
52-
return _t >= _min && _t <= _max)
53-
? 1 - ((_t - _min) / (_max - _min));
61+
return _t >= _min && _t <= _max
62+
? 1 - ((_t - _min) / (_max - _min))
5463
: 0;
5564
}
5665

0 commit comments

Comments
 (0)