From 5158cc5527556219fcff0fcf0b63bbc3a9037294 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 19 Mar 2021 11:04:47 +0900 Subject: [PATCH] [util] Add normal and magnitude float vector functions --- include/QF/simd/vec4f.h | 37 ++++++++++++++++++++++++++ libs/video/renderer/glsl/glsl_sprite.c | 4 +-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/include/QF/simd/vec4f.h b/include/QF/simd/vec4f.h index 85eb252eb..8fe207b74 100644 --- a/include/QF/simd/vec4f.h +++ b/include/QF/simd/vec4f.h @@ -93,6 +93,9 @@ GNU89INLINE inline vec4f_t qrotf (vec4f_t a, vec4f_t b) __attribute__((const)); GNU89INLINE inline vec4f_t qconjf (vec4f_t q) __attribute__((const)); GNU89INLINE inline vec4f_t loadvec3f (const float v3[3]) __attribute__((pure, access(read_only, 1))); GNU89INLINE inline void storevec3f (float v3[3], vec4f_t v4) __attribute__((access (write_only, 1))); +GNU89INLINE inline vec4f_t normalf (vec4f_t v) __attribute__((pure)); +GNU89INLINE inline vec4f_t magnitudef (vec4f_t v) __attribute__((pure)); +GNU89INLINE inline vec4f_t magnitude3f (vec4f_t v) __attribute__((pure)); #ifndef IMPLEMENT_VEC4F_Funcs GNU89INLINE inline @@ -288,4 +291,38 @@ storevec3f (float v3[3], vec4f_t v4) v3[2] = v4[2]; } +#ifndef IMPLEMENT_VEC4F_Funcs +GNU89INLINE inline +#else +VISIBLE +#endif +vec4f_t +normalf (vec4f_t v) +{ + return v / vsqrtf (dotf (v, v)); +} + +#ifndef IMPLEMENT_VEC4F_Funcs +GNU89INLINE inline +#else +VISIBLE +#endif +vec4f_t +magnitudef (vec4f_t v) +{ + return vsqrtf (dotf (v, v)); +} + +#ifndef IMPLEMENT_VEC4F_Funcs +GNU89INLINE inline +#else +VISIBLE +#endif +vec4f_t +magnitude3f (vec4f_t v) +{ + v[3] = 0; + return vsqrtf (dotf (v, v)); +} + #endif//__QF_simd_vec4f_h diff --git a/libs/video/renderer/glsl/glsl_sprite.c b/libs/video/renderer/glsl/glsl_sprite.c index 63704ebfa..4d35bc8d6 100644 --- a/libs/video/renderer/glsl/glsl_sprite.c +++ b/libs/video/renderer/glsl/glsl_sprite.c @@ -243,7 +243,7 @@ R_DrawSprite (void) VectorSet (0, 0, 1, svup); // CrossProduct (svup, -r_origin, svright) VectorSet (tvec[1], -tvec[0], 0, svright); - svright /= vsqrtf (dotf (svright, svright)); + svright = normalf (svright); // CrossProduct (svright, svup, svpn); VectorSet (-svright[1], svright[0], 0, svpn); break; @@ -268,7 +268,7 @@ R_DrawSprite (void) VectorSet (0, 0, 1, svup); // CrossProduct (svup, -r_origin, svright) VectorSet (vpn[1], -vpn[0], 0, svright); - svright /= vsqrtf (dotf (svright, svright)); + svright = normalf (svright); // CrossProduct (svright, svup, svpn); VectorSet (-svright[1], svright[0], 0, svpn); break;