diff options
author | Matthew Kosarek <mattkae@protonmail.com> | 2021-04-01 17:02:44 -0400 |
---|---|---|
committer | Matthew Kosarek <mattkae@protonmail.com> | 2021-04-01 17:02:44 -0400 |
commit | dbd32f11e2a3df38162c70f946b5bfa9a8dedbfa (patch) | |
tree | df3c1baf5818a641f7c15acbc59d90abcf0360c5 /frontend/shared_cpp | |
parent | b17c518155fae64083eb5b56b78b9eec57603ac0 (diff) |
Lots of work in progress on pill intersections, but will have to read more up on it
Diffstat (limited to 'frontend/shared_cpp')
-rw-r--r-- | frontend/shared_cpp/MainLoop.cpp | 3 | ||||
-rw-r--r-- | frontend/shared_cpp/MainLoop.h | 4 | ||||
-rw-r--r-- | frontend/shared_cpp/mathlib.h | 29 |
3 files changed, 33 insertions, 3 deletions
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 <cstdio> #include <cstdlib> #include <cstring> +#include <cmath> + +#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 { |