math rads

v1
Brett 2023-12-29 19:32:16 -05:00
parent cc64e71c8d
commit 13f82dfc2f
2 changed files with 23 additions and 8 deletions

View File

@ -10,22 +10,35 @@
#include <blt/math/vectors.h> #include <blt/math/vectors.h>
#include <blt/math/matrix.h> #include <blt/math/matrix.h>
namespace blt { namespace blt
{
static inline constexpr double PI = 3.141592653589793238462643383279502884197;
template<typename T>
static inline T toRadians(T deg)
{
constexpr double CONV = PI / 180.0;
return deg * CONV;
}
/** /**
* fast number integer * fast number integer
*/ */
static inline unsigned int f_randi(unsigned int seed) { static inline unsigned int f_randi(unsigned int seed)
{
seed = (seed << 13) ^ seed; seed = (seed << 13) ^ seed;
return ((seed * (seed * seed * 15731 + 789221) + 1376312589) & 0x7fffffff); return ((seed * (seed * seed * 15731 + 789221) + 1376312589) & 0x7fffffff);
} }
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing" #pragma GCC diagnostic ignored "-Wstrict-aliasing"
/** /**
* fast inverse sqrt * fast inverse sqrt
*/ */
static inline float fsqrt(float n){ static inline float fsqrt(float n)
{
int i; int i;
float x, y; float x, y;
x = n * 0.5f; x = n * 0.5f;
@ -41,7 +54,8 @@ namespace blt {
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
static inline constexpr double pow(int b, int p) { static inline constexpr double pow(int b, int p)
{
int collection = 1; int collection = 1;
for (int i = 0; i < p; i++) for (int i = 0; i < p; i++)
collection *= b; collection *= b;
@ -55,9 +69,10 @@ namespace blt {
* @return * @return
*/ */
template<int decimal_places> template<int decimal_places>
static inline double round_up(double value) { static inline double round_up(double value)
{
constexpr double multiplier = pow(10, decimal_places); constexpr double multiplier = pow(10, decimal_places);
return ((int)(value * multiplier) + 1) / multiplier; return ((int) (value * multiplier) + 1) / multiplier;
} }
/*inline std::ostream& operator<<(std::ostream& out, const mat4x4& v) { /*inline std::ostream& operator<<(std::ostream& out, const mat4x4& v) {
@ -66,7 +81,7 @@ namespace blt {
<< " {" << v.m20() << ", " << v.m21() << ", " << v.m22() << ", " << v.m23() << "} \n"\ << " {" << v.m20() << ", " << v.m21() << ", " << v.m22() << ", " << v.m23() << "} \n"\
<< " {" << v.m30() << ", " << v.m31() << ", " << v.m32() << ", " << v.m33() << "} \n"; << " {" << v.m30() << ", " << v.m31() << ", " << v.m32() << ", " << v.m33() << "} \n";
}*/ }*/
} }
#endif //BLT_MATH_H #endif //BLT_MATH_H

@ -1 +1 @@
Subproject commit 401552da80b0971f818e648621260720ad40934e Subproject commit 946ebad67a21212d11a0dd4deb7cdedc297d47bc