From 4878f0fc6a039d220dd7adecb18d19c688ae50b0 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Thu, 1 Jul 2021 19:46:08 -0400 Subject: (mkosarek) Decent SAT description for now --- tools/transpiler/MathHelper.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tools/transpiler/MathHelper.h (limited to 'tools/transpiler/MathHelper.h') diff --git a/tools/transpiler/MathHelper.h b/tools/transpiler/MathHelper.h new file mode 100644 index 0000000..b9c9cb6 --- /dev/null +++ b/tools/transpiler/MathHelper.h @@ -0,0 +1,33 @@ +#pragma once + +#define PI 3.14159265358979323846f + +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define CLAMP(x, upper, lower) (MIN(upper, MAX(x, lower))) +#define DTOR (PI / 180.0f) +#define SWAP(x, y, T) do { T SWAP = x; x = y; y = SWAP; } while (0) + +namespace MathHelper { + inline float radiansToDegrees(float radians) { + return radians * 180.f / PI; + } + + inline float degreesToRadians(float degrees) { + return degrees * PI / 180.f; + } + + inline int nearestPowerOfTwo(int n) { + int v = n; + + v--; + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v++; // next power of 2 + + return v; + } +} -- cgit v1.2.1