From dbd32f11e2a3df38162c70f946b5bfa9a8dedbfa Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Thu, 1 Apr 2021 17:02:44 -0400 Subject: Lots of work in progress on pill intersections, but will have to read more up on it --- frontend/shared_cpp/MainLoop.cpp | 3 ++- frontend/shared_cpp/MainLoop.h | 4 ++-- frontend/shared_cpp/mathlib.h | 29 +++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) (limited to 'frontend/shared_cpp') diff --git a/frontend/shared_cpp/MainLoop.cpp b/frontend/shared_cpp/MainLoop.cpp index 82a24b5..09aa643 100644 --- a/frontend/shared_cpp/MainLoop.cpp +++ b/frontend/shared_cpp/MainLoop.cpp @@ -26,5 +26,6 @@ EM_BOOL loop(double time, void* loop) { mainLoop->numFrames = 0; } - return mainLoop->updateFunc(deltaTimeSeconds, NULL); + mainLoop->updateFunc(deltaTimeSeconds, NULL); + return true; } \ No newline at end of file diff --git a/frontend/shared_cpp/MainLoop.h b/frontend/shared_cpp/MainLoop.h index 7300f6b..2573bb8 100644 --- a/frontend/shared_cpp/MainLoop.h +++ b/frontend/shared_cpp/MainLoop.h @@ -11,9 +11,9 @@ struct MainLoop { bool isRunning = false; double lastTime = 0, elapsedTime = 0; int numFrames = 0; - EM_BOOL (*updateFunc)(float dtSeconds, void *userData); + void (*updateFunc)(float dtSeconds, void *userData); - void run(EM_BOOL (*cb)(float dtSeconds, void *userData)) { + void run(void (*cb)(float dtSeconds, void *userData)) { isRunning = true; lastTime = 0; elapsedTime = 0; diff --git a/frontend/shared_cpp/mathlib.h b/frontend/shared_cpp/mathlib.h index 7595045..2784f6a 100644 --- a/frontend/shared_cpp/mathlib.h +++ b/frontend/shared_cpp/mathlib.h @@ -2,6 +2,11 @@ #include #include #include +#include + +#define MAX(x, y) (((x) > (y)) ? (x) : (y)) +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) +#define ABS(x) (x < 0 ? -x : x) struct Vector2 { float x = 0; @@ -11,6 +16,12 @@ struct Vector2 { return { x + other.x, y + other.y }; } + Vector2& operator+=(Vector2 other) { + x += other.x; + y += other.y; + return *this; + } + Vector2 operator-(Vector2 other) { return { x - other.x, y - other.y }; } @@ -19,6 +30,10 @@ struct Vector2 { return { x * s, y * s }; } + Vector2 operator/(float s) { + return { x / s, y / s }; + } + float dot(Vector2 other) { return x * other.x + y * other.y; } @@ -45,6 +60,20 @@ struct Vector2 { void printDebug(const char* name) { printf("%s=Vector2(%f, %f)\n", name, x, y); } + + float determinant(Vector2 other) { + // + // [ a b ] + // [ c d ] + // + // [ x other.x ] + // [ y other.y ] + // + // det = a * d - b * c + // det = x * other.y - other.x * y + // + return x * other.y - other.x * y; + } }; struct Vector3 { -- cgit v1.2.1