diff options
Diffstat (limited to 'shared_cpp')
-rw-r--r-- | shared_cpp/mathlib.cpp | 10 | ||||
-rw-r--r-- | shared_cpp/mathlib.h | 1 |
2 files changed, 11 insertions, 0 deletions
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); } diff --git a/shared_cpp/mathlib.h b/shared_cpp/mathlib.h index 9722f4f..f89addc 100644 --- a/shared_cpp/mathlib.h +++ b/shared_cpp/mathlib.h @@ -53,6 +53,7 @@ struct Vector2 { Vector2 negate(); Vector2 getPerp(); Vector2 rotate(float angle); + Vector2 rotateAround(float angle, const Vector2& other); float determinant(Vector2 other); void printDebug(const char* name); |