From cc05fdc7396532b329f30decde5583853da92a44 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Sat, 27 Mar 2021 20:54:27 -0400 Subject: Drawing an ellipse --- frontend/shared_cpp/mathlib.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'frontend/shared_cpp/mathlib.h') 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"); } -- cgit v1.2.1