From 8d4c5116719825dce6222c494cd384fe1df775de Mon Sep 17 00:00:00 2001 From: mattkae Date: Sat, 26 Feb 2022 19:19:20 -0500 Subject: Actual working springy rectangle --- shared_cpp/mathlib.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'shared_cpp/mathlib.cpp') diff --git a/shared_cpp/mathlib.cpp b/shared_cpp/mathlib.cpp index 17f9f84..2e92aa8 100644 --- a/shared_cpp/mathlib.cpp +++ b/shared_cpp/mathlib.cpp @@ -80,6 +80,16 @@ Vector2 Vector2::rotate(float angle) { }; } +Vector2 Vector2::rotateAround(float angle, const Vector2& other) { + Vector2 point = { x - other.x, y - other.y }; + point = { + point.x * cosf(angle) - point.y * sinf(angle), + point.x * sinf(angle) + point.y * cosf(angle) + }; + point = point + other; + return point; +} + void Vector2::printDebug(const char* name) { printf("%s=Vector2(%f, %f)\n", name, x, y); } -- cgit v1.2.1