diff options
author | Matthew Kosarek <mattkae@protonmail.com> | 2021-03-27 20:54:27 -0400 |
---|---|---|
committer | Matthew Kosarek <mattkae@protonmail.com> | 2021-03-27 20:54:27 -0400 |
commit | cc05fdc7396532b329f30decde5583853da92a44 (patch) | |
tree | fc05dd91ef0245acfea1dcf539d4c968a081b5c5 /frontend/shared_cpp/mathlib.h | |
parent | 58488f8eabcc61089e0ae4297f38f10cc28d78c7 (diff) |
Drawing an ellipse
Diffstat (limited to 'frontend/shared_cpp/mathlib.h')
-rw-r--r-- | frontend/shared_cpp/mathlib.h | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/frontend/shared_cpp/mathlib.h b/frontend/shared_cpp/mathlib.h index 93ddbbd..7595045 100644 --- a/frontend/shared_cpp/mathlib.h +++ b/frontend/shared_cpp/mathlib.h @@ -41,6 +41,10 @@ struct Vector2 { Vector2 getPerp() { return { -y, x }; } + + void printDebug(const char* name) { + printf("%s=Vector2(%f, %f)\n", name, x, y); + } }; struct Vector3 { @@ -54,6 +58,22 @@ struct Vector4 { float y = 0.f; float z = 0.f; float w = 0.f; + + float length() { + return sqrtf(x * x + y * y + z * z + w * w); + } + + Vector4 normalize() { + float len = length(); + float inverseLength = len == 0 ? 1.0 : 1.0 / len; + + return { x * inverseLength, y * inverseLength, z * inverseLength, w * inverseLength }; + } + + Vector4 fromColor(float r, float g, float b, float a) { + float scale = 1.f / 255.f; + return { r * scale, g * scale, b * scale, a * scale }; + } }; struct Mat4x4 { @@ -123,7 +143,7 @@ struct Mat4x4 { void print() { printf("[ "); for (int idx = 0; idx < 16; idx++) { - printf("%d, ", idx); + printf("%f, ", m[idx]); } printf(" ]\n"); } |