This is an old revision of the document!
Список всех математических функций ACSUtils.
fixed MATH_E
– число еfixed PI
– число π (пи)fixed SQRT_2
– квадратный корень из 2
num abs(num x)
Возвращает модуль (|x|) числа x.
Пример
abs(2.0) == 2.0; abs(-123) == 123;
num clamp(num x, num a, num b)
Заключает число x в промежуток [a; b]. Если число входит в промежуток, то возвращается x. Если x меньше a, возвращается a. Если число x больше b, возвращается b.
Пример
clamp(7, 6, 8) == 7; clamp(0.1, 0.2, 0.3) == 0.2;
int cmp(num a, num b)
Сравнивает два числа и возвращает результат:
1
– a > b-1
– a < b0
– a = b
num dist(num a, num b)
Возвращает абсолютное расстояние между числами.
Пример
dist(5.0, 8.0) == 3.0; dist(8.0, 5.0) == 3.0; dist(3.0, -2.0) == 5.0;
num max(num a, num b)
Возвращает большее из двух чисел.
Пример
max(3, 5) == 5; max(8.0, 7.5) == 8.0;
num min(num a, num b)
Возвращает меньшее из двух чисел.
Пример
min(3, 5) == 3; min(8.0, 7.5) == 7.5;
int sign(num x)
Возвращает знак числа x.
1
– x > 0 (положительное)-1
– x < 0 (отрицательное)0
– x = 0Пример
sign(12.3) == 1; sign(0) == 0; sign(-7) == -1;
Есть четыре вида округления:
Для каждого вида округления существует две функции. Те, что начинаются с “i” возвращают целое число. Другие, без “i” возвращают значение с типом данных fixed.
fixed ceil(fixed x)
int iceil(fixed x)
Возвращает число x, округленное вверх (до наибольшего ближайшего целого числа).
fixed floor(fixed x)
int ifloor(fixed x)
Возвращает число x, округленное вниз (до наименьшего ближайшего целого числа).
fixed round(fixed x)
int iround(fixed x)
Округляет число x до ближайшего целого числа.
fixed trunc(fixed x)
int itrunc(fixed x)
Возвращает число x без дробной части.
fixed lerp(fixed a, fixed b, fixed alpha)
Выполняет линейную интерполяцию (или экстраполяцию) между двумя числами и возвращает результат.
Примеры
lerp(a, b, 0.0) == a; lerp(a, b, 1.0) == b; lerp(a, b, 0.5) == (a + b) / 2; // Среднее арифметическое от a и b
// Простая анимация. for (int time = 0; time < 1.0; time += 0.05) { int x = lerp(x1, x2, time); int y = lerp(y1, y2, time); НарисоватьЧтоНибудь(x, y); Delay(1); }
int zan_Sqrt(int number)
fixed zan_FixedSqrt(fixed number)
Реализация квадратного корня для Zandronum, соответствует ZDoom 2.7.0 функциям.
Sin и cos уже присутствуют в Zdoom.
fixed tan(angle x)
Возвращает tg x (тангенс).
fixed cot(angle x)
Возвращает ctg x (котангенс).
fixed sec(angle x)
Возвращает sec x (секанс).
fixed cosec(angle x)
Возвращает cosec x (косеканс).
angle asin(fixed x)
Возвращает arcsin x (арксинус).
angle acos(fixed x)
Возвращает arccos x (арккосинус).
angle atan(fixed x)
Возвращает arctg x (арктангенс).
angle acot(fixed x)
Возвращает arcctg x (арккотангнес).
angle asec(fixed x)
Возвращает arcsec x (арксеканс).
angle acosec(fixed x)
Возвращает arccosec x (арккосеканс).
fixed dot2(fixed x1, fixed y1, fixed x2, fixed y2)
Returns the dot product of two 2D vectors.
fixed dot3(fixed x1, fixed y1, fixed z1, fixed x2, fixed y2, fixed z2)
Returns the dot product of two 3D vectors.
fixed length2d(fixed x, fixed y)
Returns the length of the given 2D vector. This is a Zandronum replacement for VectorLength.
fixed length2d2(int x, int y)
Returns the squared length of the given 2D vector.
fixed length3d(fixed x, fixed y, fixed z)
Returns the length of the given 3D vector.
fixed length3d2(int x, int y, int z)
Returns the squared length of the given 3D vector.
fixed, fixed normalize2d(fixed x, fixed y)
Normalizes the given 2D vector and returns the result.
fixed, fixed, fixed normalize3d(fixed x, fixed y, fixed z)
Normalizes the given 3D vector and returns the result.
fixed, fixed RotatePoint(fixed x, fixed y, fixed originX, fixed originY, angle angle)
Rotates the given point (x; y) around the given origin by the given angle and returns the resulting coordinates of the point.
fixed, fixed RotateVector(fixed x, fixed y, angle angle)
Rotates the vector by the given angle and returns its new coordinates.
This function returns multiple values.
Example
RotateVector(x, y, angle); int newX = r1; int newY = r2;
angle, angle VectorToAngles(fixed x, fixed y, fixed z)
Converts a vector to a pair of angles (yaw and pitch) that point to the same direction.
This function returns multiple values.
Example
// Make the player look along the vector VectorToAngles(1.0, 2.0, 3.0); int angle = r1; int pitch = r2; SetActorAngle(angle); SetActorPitch(pitch);