diff options
author | Wolfgang Draxinger <Wolfgang.Draxinger@draxit.de> | 2015-07-31 00:30:19 +0200 |
---|---|---|
committer | Wolfgang Draxinger <Wolfgang.Draxinger@draxit.de> | 2015-07-31 00:30:19 +0200 |
commit | 06b68f6caa214d9f98ada28db837c21e08ed2927 (patch) | |
tree | a744078ef0e0fe75ae13d9b25798a962c411d86b | |
parent | 543faf6415918e926c1ddc3e04348eed44d5ed37 (diff) | |
download | linmath-06b68f6caa214d9f98ada28db837c21e08ed2927.tar.gz linmath-06b68f6caa214d9f98ada28db837c21e08ed2927.tar.xz linmath-06b68f6caa214d9f98ada28db837c21e08ed2927.zip |
fixed out-of-bounds write in quat_mul_vec3 by replacing with a more elegant method
-rw-r--r-- | linmath.h | 22 |
1 files changed, 16 insertions, 6 deletions
@@ -476,12 +476,22 @@ static inline void quat_rotate(quat r, float angle, vec3 axis) { #define quat_norm vec4_norm static inline void quat_mul_vec3(vec3 r, quat q, vec3 v) { - quat v_ = {v[0], v[1], v[2], 0.f}; - - quat_conj(r, q); - quat_norm(r, r); - quat_mul(r, v_, r); - quat_mul(r, q, r); +/* + * Method by Fabian 'ryg' Giessen (of Farbrausch) +t = 2 * cross(q.xyz, v) +v' = v + q.w * t + cross(q.xyz, t) + */ + vec3 t = {q[0], q[1], q[2]}; + vec3 u = {q[0], q[1], q[2]}; + + vec3_mul_cross(t, t, v); + vec3_scale(t, t, 2); + + vec3_mul_cross(u, u, t); + vec3_scale(t, t, q[3]); + + vec3_add(r, v, t); + vec3_add(r, r, u); } static inline void mat4x4_from_quat(mat4x4 M, quat q) { |