Dan Albert | 287553d | 2017-02-16 10:47:51 -0800 | [diff] [blame] | 1 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2 | // OpenGL Mathematics Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net) |
| 3 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 4 | // Created : 2005-12-21 |
| 5 | // Updated : 2005-12-21 |
| 6 | // Licence : This source is under MIT License |
| 7 | // File : glm/gtx/orthonormalize.inl |
| 8 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 9 | |
| 10 | namespace glm |
| 11 | { |
| 12 | template <typename T, precision P> |
| 13 | GLM_FUNC_QUALIFIER detail::tmat3x3<T, P> orthonormalize |
| 14 | ( |
| 15 | const detail::tmat3x3<T, P>& m |
| 16 | ) |
| 17 | { |
| 18 | detail::tmat3x3<T, P> r = m; |
| 19 | |
| 20 | r[0] = normalize(r[0]); |
| 21 | |
| 22 | float d0 = dot(r[0], r[1]); |
| 23 | r[1] -= r[0] * d0; |
| 24 | r[1] = normalize(r[1]); |
| 25 | |
| 26 | float d1 = dot(r[1], r[2]); |
| 27 | d0 = dot(r[0], r[2]); |
| 28 | r[2] -= r[0] * d0 + r[1] * d1; |
| 29 | r[2] = normalize(r[2]); |
| 30 | |
| 31 | return r; |
| 32 | } |
| 33 | |
| 34 | template <typename T, precision P> |
| 35 | GLM_FUNC_QUALIFIER detail::tvec3<T, P> orthonormalize |
| 36 | ( |
| 37 | const detail::tvec3<T, P>& x, |
| 38 | const detail::tvec3<T, P>& y |
| 39 | ) |
| 40 | { |
| 41 | return normalize(x - y * dot(y, x)); |
| 42 | } |
| 43 | }//namespace glm |