aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <franklin@rockbox.org>2019-12-27 23:03:44 -0500
committerFranklin Wei <franklin@rockbox.org>2019-12-27 23:03:44 -0500
commit1171d9cbbf0f4a78288d01e2024a253d6b3ffd58 (patch)
tree3e50b961ec495057a9da15485668478e16db850c
parent8aeca32c1b4d5506744680b079d5e03a838178e4 (diff)
downloadlibfml-1171d9cbbf0f4a78288d01e2024a253d6b3ffd58.zip
libfml-1171d9cbbf0f4a78288d01e2024a253d6b3ffd58.tar.gz
libfml-1171d9cbbf0f4a78288d01e2024a253d6b3ffd58.tar.bz2
libfml-1171d9cbbf0f4a78288d01e2024a253d6b3ffd58.tar.xz
Add function to rotate a 2d vector
-rw-r--r--src/vec2.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/vec2.cpp b/src/vec2.cpp
index 712b440..ca26a08 100644
--- a/src/vec2.cpp
+++ b/src/vec2.cpp
@@ -71,6 +71,13 @@ namespace fml {
scalar vec2::dot(const vec2 &other) const {
return v[0] * other.v[0] + v[1] * other.v[1];
}
+ vec2 vec2::rotateby(scalar angle) {
+ double s, c;
+ sincos(angle, &s, c);
+ return vec2(v[0] * c - v[1] * s,
+ v[0] * s + v[1] * c);
+ }
+
std::ostream &operator<<(std::ostream &output, const vec2 &v) {
return output << v[0] << " " << v[1];
}