Last active
March 27, 2022 21:08
-
-
Save vladdeSV/1f0b61f94fbcbcdd89a123b042211b08 to your computer and use it in GitHub Desktop.
My commonly used math-related helper functions in Game Maker Language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function map_range(a, b, c, d, value) { | |
return (value - a) / (b - a) * (d - c) + c | |
} | |
function normalize_arctan2_angle(angle) { | |
return (angle > 0) ? angle : angle + 2 * pi | |
} | |
function sin01(x) { | |
return 0.5 * (sin(x) + 1) | |
} | |
function cos01(x) { | |
return 0.5 * (cos(x) + 1) | |
} | |
function degrees_to_radians(degrees) { | |
return degrees / 180 * pi | |
} | |
function radians_to_degrees(radians) { | |
return radians * 180 / pi | |
} | |
function lerp2(a, b, t, threshold = 0.001) { | |
if (a == b) { | |
return b | |
} | |
if (abs(a - b) < threshold) { | |
return b | |
} | |
return lerp(a, b, t) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment