diff options
-rw-r--r-- | maths.hpp | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -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); } |