37 lines
1 KiB
C
37 lines
1 KiB
C
#include "tangent.h"
|
|
|
|
const BgcTangentFP32 BGC_IDLE_TANGENT_FP32 = { 1.0f, 0.0f };
|
|
|
|
const BgcTangentFP64 BGC_IDLE_TANGENT_FP64 = { 1.0, 0.0 };
|
|
|
|
void _bgc_tangent_normalize_fp32(const float square_modulus, _BgcDarkTwinTangentFP32* twin)
|
|
{
|
|
// (square_modulus != square_modulus) is true when square_modulus is NaN
|
|
|
|
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
|
twin->cos = 1.0f;
|
|
twin->sin = 0.0f;
|
|
return;
|
|
}
|
|
|
|
const float multiplier = sqrtf(1.0f / square_modulus);
|
|
|
|
twin->cos *= multiplier;
|
|
twin->sin *= multiplier;
|
|
}
|
|
|
|
void _bgc_tangent_normalize_fp64(const double square_modulus, _BgcDarkTwinTangentFP64* twin)
|
|
{
|
|
// (square_modulus != square_modulus) is true when square_modulus is NaN
|
|
|
|
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
|
twin->cos = 1.0;
|
|
twin->sin = 0.0;
|
|
return;
|
|
}
|
|
|
|
const double multiplier = sqrt(1.0 / square_modulus);
|
|
|
|
twin->cos *= multiplier;
|
|
twin->sin *= multiplier;
|
|
}
|