summaryrefslogtreecommitdiff
path: root/maths.hpp
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2025-01-27 21:45:15 +1100
committerquou <quou@disroot.org>2025-01-27 21:45:15 +1100
commit78c3bac3c690d48e9e751890c38769c785fadf50 (patch)
tree40dd73a64187f4d5d73dbfe8c6b3cae477e2ced2 /maths.hpp
parent7ca709069cc280969b8d71bb19a09b8aeb13b859 (diff)
perp
Diffstat (limited to 'maths.hpp')
-rw-r--r--maths.hpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/maths.hpp b/maths.hpp
index 74987d3..e432529 100644
--- a/maths.hpp
+++ b/maths.hpp
@@ -261,6 +261,13 @@ struct v3 {
return v3<T>(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
}
+ static v3<T> perp(const v3<T>& v) {
+ v3<T> up((T)0, (T)1, (T)0);
+ if (mag_sqrd(v - up) < (T)0.1f)
+ up = v3<T>((T)1, (T)0, (T)0);
+ return cross(v, up);
+ }
+
static T mag_sqrd(const v3<T>& v) {
return v3<T>::dot(v, v);
}