[util] Add normal and magnitude float vector functions

This commit is contained in:
Bill Currie 2021-03-19 11:04:47 +09:00
parent 2015474468
commit 5158cc5527
2 changed files with 39 additions and 2 deletions

View file

@ -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

View file

@ -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;