2022-12-07 08:51:01 +00:00
|
|
|
// HARFANG(R) Copyright (C) 2022 NWNC. Released under GPL/LGPL/Commercial Licence, see licence.txt for details.
|
2021-10-13 12:40:31 +00:00
|
|
|
|
|
|
|
#include "foundation/math.h"
|
|
|
|
#include "foundation/rotation_order.h"
|
2022-12-07 08:51:01 +00:00
|
|
|
|
2021-10-13 12:40:31 +00:00
|
|
|
#include <cfloat>
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
namespace hg {
|
|
|
|
|
2022-12-07 08:51:01 +00:00
|
|
|
RotationOrder ReverseRotationOrder(RotationOrder in) {
|
|
|
|
RotationOrder out;
|
|
|
|
|
|
|
|
if (in == RO_ZYX) {
|
|
|
|
out = RO_XYZ;
|
|
|
|
} else if (in == RO_YZX) {
|
|
|
|
out = RO_XZY;
|
|
|
|
} else if (in == RO_ZXY) {
|
|
|
|
out = RO_YXZ;
|
|
|
|
} else if (in == RO_XZY) {
|
|
|
|
out = RO_YZX;
|
|
|
|
} else if (in == RO_YXZ) {
|
|
|
|
out = RO_ZXY;
|
|
|
|
} else if (in == RO_XYZ) {
|
|
|
|
out = RO_ZYX;
|
|
|
|
} else {
|
|
|
|
out = RO_Default;
|
2021-10-13 12:40:31 +00:00
|
|
|
}
|
2022-12-07 08:51:01 +00:00
|
|
|
|
|
|
|
return out;
|
2021-10-13 12:40:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2022-12-07 08:51:01 +00:00
|
|
|
float Sqrt(float v) {
|
|
|
|
return sqrtf(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
float Pow(float v, float e) {
|
|
|
|
return pow(v, e);
|
|
|
|
}
|
2021-10-13 12:40:31 +00:00
|
|
|
|
2022-12-07 08:51:01 +00:00
|
|
|
float Ceil(float v) {
|
|
|
|
return ceilf(v);
|
|
|
|
}
|
2021-10-13 12:40:31 +00:00
|
|
|
|
2022-12-07 08:51:01 +00:00
|
|
|
float Floor(float v) {
|
|
|
|
return floorf(v);
|
|
|
|
}
|
2021-10-13 12:40:31 +00:00
|
|
|
|
2022-12-07 08:51:01 +00:00
|
|
|
float Round(float v) {
|
|
|
|
return roundf(v);
|
|
|
|
}
|
2021-10-13 12:40:31 +00:00
|
|
|
|
|
|
|
float Mod(float v) {
|
|
|
|
double integral;
|
|
|
|
return static_cast<float>(modf(v, &integral));
|
|
|
|
}
|
|
|
|
|
|
|
|
float RangeAdjust(float v, float old_min, float old_max, float new_min, float new_max) {
|
|
|
|
return Clamp((v - old_min) / (old_max - old_min) * (new_max - new_min) + new_min, new_min, new_max);
|
|
|
|
}
|
|
|
|
|
2022-12-07 08:51:01 +00:00
|
|
|
float Quantize(float v, float q) {
|
|
|
|
return Floor(v / q) * q;
|
|
|
|
}
|
2021-10-13 12:40:31 +00:00
|
|
|
|
2022-12-07 08:51:01 +00:00
|
|
|
float Frac(float v) {
|
|
|
|
return v - static_cast<float>(static_cast<int>(v));
|
|
|
|
}
|
2021-10-13 12:40:31 +00:00
|
|
|
|
|
|
|
//
|
2022-12-07 08:51:01 +00:00
|
|
|
bool IsFinite(float v) {
|
|
|
|
return (v <= FLT_MAX) && (v >= -FLT_MAX);
|
|
|
|
}
|
2021-10-13 12:40:31 +00:00
|
|
|
|
|
|
|
//
|
2022-12-07 08:51:01 +00:00
|
|
|
float Sin(float v) {
|
|
|
|
return sin(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
float ASin(float v) {
|
|
|
|
return asin(Clamp(v, -1.F, 1.F));
|
|
|
|
}
|
|
|
|
|
|
|
|
float Cos(float v) {
|
|
|
|
return cos(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
float ACos(float v) {
|
|
|
|
return acos(Clamp(v, -1.F, 1.F));
|
|
|
|
}
|
|
|
|
|
|
|
|
float Tan(float v) {
|
|
|
|
return tan(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
float ATan(float v) {
|
|
|
|
return atan(v);
|
|
|
|
}
|
2021-10-13 12:40:31 +00:00
|
|
|
|
|
|
|
} // namespace hg
|