|
|
|
@ -64,50 +64,50 @@ inline void bgc_fp64_quaternion_make(BGC_FP64_Quaternion* quaternion, const doub
|
|
|
|
|
|
|
|
|
|
|
|
// ============= Get Square Modulus ============= //
|
|
|
|
// ============= Get Square Modulus ============= //
|
|
|
|
|
|
|
|
|
|
|
|
inline float bgc_fp32_quaternion_get_square_modulus(const BGC_FP32_Quaternion* quaternion)
|
|
|
|
inline float bgc_fp32_quaternion_get_square_magnitude(const BGC_FP32_Quaternion* quaternion)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return (quaternion->s0 * quaternion->s0 + quaternion->x1 * quaternion->x1) + (quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3);
|
|
|
|
return (quaternion->s0 * quaternion->s0 + quaternion->x1 * quaternion->x1) + (quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline double bgc_fp64_quaternion_get_square_modulus(const BGC_FP64_Quaternion* quaternion)
|
|
|
|
inline double bgc_fp64_quaternion_get_square_magnitude(const BGC_FP64_Quaternion* quaternion)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return (quaternion->s0 * quaternion->s0 + quaternion->x1 * quaternion->x1) + (quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3);
|
|
|
|
return (quaternion->s0 * quaternion->s0 + quaternion->x1 * quaternion->x1) + (quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ================ Get Modulus ================= //
|
|
|
|
// ================ Get Modulus ================= //
|
|
|
|
|
|
|
|
|
|
|
|
inline float bgc_fp32_quaternion_get_modulus(const BGC_FP32_Quaternion* quaternion)
|
|
|
|
inline float bgc_fp32_quaternion_get_magnitude(const BGC_FP32_Quaternion* quaternion)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return sqrtf(bgc_fp32_quaternion_get_square_modulus(quaternion));
|
|
|
|
return sqrtf(bgc_fp32_quaternion_get_square_magnitude(quaternion));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline double bgc_fp64_quaternion_get_modulus(const BGC_FP64_Quaternion* quaternion)
|
|
|
|
inline double bgc_fp64_quaternion_get_magnitude(const BGC_FP64_Quaternion* quaternion)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return sqrt(bgc_fp64_quaternion_get_square_modulus(quaternion));
|
|
|
|
return sqrt(bgc_fp64_quaternion_get_square_magnitude(quaternion));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ================== Is Zero =================== //
|
|
|
|
// ================== Is Zero =================== //
|
|
|
|
|
|
|
|
|
|
|
|
inline int bgc_fp32_quaternion_is_zero(const BGC_FP32_Quaternion* quaternion)
|
|
|
|
inline int bgc_fp32_quaternion_is_zero(const BGC_FP32_Quaternion* quaternion)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return bgc_fp32_quaternion_get_square_modulus(quaternion) <= BGC_FP32_SQUARE_EPSILON;
|
|
|
|
return bgc_fp32_quaternion_get_square_magnitude(quaternion) <= BGC_FP32_SQUARE_EPSILON;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline int bgc_fp64_quaternion_is_zero(const BGC_FP64_Quaternion* quaternion)
|
|
|
|
inline int bgc_fp64_quaternion_is_zero(const BGC_FP64_Quaternion* quaternion)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return bgc_fp64_quaternion_get_square_modulus(quaternion) <= BGC_FP64_SQUARE_EPSILON;
|
|
|
|
return bgc_fp64_quaternion_get_square_magnitude(quaternion) <= BGC_FP64_SQUARE_EPSILON;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ================== Is Unit =================== //
|
|
|
|
// ================== Is Unit =================== //
|
|
|
|
|
|
|
|
|
|
|
|
inline int bgc_fp32_quaternion_is_unit(const BGC_FP32_Quaternion* quaternion)
|
|
|
|
inline int bgc_fp32_quaternion_is_unit(const BGC_FP32_Quaternion* quaternion)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return bgc_fp32_is_square_unit(bgc_fp32_quaternion_get_square_modulus(quaternion));
|
|
|
|
return bgc_fp32_is_square_unit(bgc_fp32_quaternion_get_square_magnitude(quaternion));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline int bgc_fp64_quaternion_is_unit(const BGC_FP64_Quaternion* quaternion)
|
|
|
|
inline int bgc_fp64_quaternion_is_unit(const BGC_FP64_Quaternion* quaternion)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return bgc_fp64_is_square_unit(bgc_fp64_quaternion_get_square_modulus(quaternion));
|
|
|
|
return bgc_fp64_is_square_unit(bgc_fp64_quaternion_get_square_magnitude(quaternion));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ==================== Copy ==================== //
|
|
|
|
// ==================== Copy ==================== //
|
|
|
|
@ -358,7 +358,7 @@ inline int bgc_fp64_quaternion_divide_by_real(BGC_FP64_Quaternion* quotient, con
|
|
|
|
|
|
|
|
|
|
|
|
inline int bgc_fp32_quaternion_divide_by_quaternion(BGC_FP32_Quaternion* quotient, const BGC_FP32_Quaternion* divident, const BGC_FP32_Quaternion* divisor)
|
|
|
|
inline int bgc_fp32_quaternion_divide_by_quaternion(BGC_FP32_Quaternion* quotient, const BGC_FP32_Quaternion* divident, const BGC_FP32_Quaternion* divisor)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(divisor);
|
|
|
|
const float square_modulus = bgc_fp32_quaternion_get_square_magnitude(divisor);
|
|
|
|
|
|
|
|
|
|
|
|
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
return BGC_FAILURE;
|
|
|
|
return BGC_FAILURE;
|
|
|
|
@ -372,7 +372,7 @@ inline int bgc_fp32_quaternion_divide_by_quaternion(BGC_FP32_Quaternion* quotien
|
|
|
|
|
|
|
|
|
|
|
|
inline int bgc_fp64_quaternion_divide_by_quaternion(BGC_FP64_Quaternion* quotient, const BGC_FP64_Quaternion* divident, const BGC_FP64_Quaternion* divisor)
|
|
|
|
inline int bgc_fp64_quaternion_divide_by_quaternion(BGC_FP64_Quaternion* quotient, const BGC_FP64_Quaternion* divident, const BGC_FP64_Quaternion* divisor)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(divisor);
|
|
|
|
const double square_modulus = bgc_fp64_quaternion_get_square_magnitude(divisor);
|
|
|
|
|
|
|
|
|
|
|
|
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
return BGC_FAILURE;
|
|
|
|
return BGC_FAILURE;
|
|
|
|
@ -388,7 +388,7 @@ inline int bgc_fp64_quaternion_divide_by_quaternion(BGC_FP64_Quaternion* quotien
|
|
|
|
|
|
|
|
|
|
|
|
inline int bgc_fp32_quaternion_divide_by_conjugate(BGC_FP32_Quaternion* quotient, const BGC_FP32_Quaternion* divident, const BGC_FP32_Quaternion* divisor_to_conjugate)
|
|
|
|
inline int bgc_fp32_quaternion_divide_by_conjugate(BGC_FP32_Quaternion* quotient, const BGC_FP32_Quaternion* divident, const BGC_FP32_Quaternion* divisor_to_conjugate)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(divisor_to_conjugate);
|
|
|
|
const float square_modulus = bgc_fp32_quaternion_get_square_magnitude(divisor_to_conjugate);
|
|
|
|
|
|
|
|
|
|
|
|
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
return BGC_FAILURE;
|
|
|
|
return BGC_FAILURE;
|
|
|
|
@ -402,7 +402,7 @@ inline int bgc_fp32_quaternion_divide_by_conjugate(BGC_FP32_Quaternion* quotient
|
|
|
|
|
|
|
|
|
|
|
|
inline int bgc_fp64_quaternion_divide_by_conjugate(BGC_FP64_Quaternion* quotient, const BGC_FP64_Quaternion* divident, const BGC_FP64_Quaternion* divisor_to_conjugate)
|
|
|
|
inline int bgc_fp64_quaternion_divide_by_conjugate(BGC_FP64_Quaternion* quotient, const BGC_FP64_Quaternion* divident, const BGC_FP64_Quaternion* divisor_to_conjugate)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(divisor_to_conjugate);
|
|
|
|
const double square_modulus = bgc_fp64_quaternion_get_square_magnitude(divisor_to_conjugate);
|
|
|
|
|
|
|
|
|
|
|
|
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
return BGC_FAILURE;
|
|
|
|
return BGC_FAILURE;
|
|
|
|
@ -542,7 +542,7 @@ inline void bgc_fp64_quaternion_get_reverse(BGC_FP64_Quaternion* reverse, const
|
|
|
|
|
|
|
|
|
|
|
|
inline int bgc_fp32_quaternion_get_inverse(BGC_FP32_Quaternion* inverse, const BGC_FP32_Quaternion* quaternion)
|
|
|
|
inline int bgc_fp32_quaternion_get_inverse(BGC_FP32_Quaternion* inverse, const BGC_FP32_Quaternion* quaternion)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(quaternion);
|
|
|
|
const float square_modulus = bgc_fp32_quaternion_get_square_magnitude(quaternion);
|
|
|
|
|
|
|
|
|
|
|
|
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
return BGC_FAILURE;
|
|
|
|
return BGC_FAILURE;
|
|
|
|
@ -560,7 +560,7 @@ inline int bgc_fp32_quaternion_get_inverse(BGC_FP32_Quaternion* inverse, const B
|
|
|
|
|
|
|
|
|
|
|
|
inline int bgc_fp64_quaternion_get_inverse(BGC_FP64_Quaternion* inverse, const BGC_FP64_Quaternion* quaternion)
|
|
|
|
inline int bgc_fp64_quaternion_get_inverse(BGC_FP64_Quaternion* inverse, const BGC_FP64_Quaternion* quaternion)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(quaternion);
|
|
|
|
const double square_modulus = bgc_fp64_quaternion_get_square_magnitude(quaternion);
|
|
|
|
|
|
|
|
|
|
|
|
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
return BGC_FAILURE;
|
|
|
|
return BGC_FAILURE;
|
|
|
|
@ -590,7 +590,7 @@ inline int bgc_fp64_quaternion_invert(BGC_FP64_Quaternion* quaternion)
|
|
|
|
|
|
|
|
|
|
|
|
inline int bgc_fp32_quaternion_normalize(BGC_FP32_Quaternion* quaternion)
|
|
|
|
inline int bgc_fp32_quaternion_normalize(BGC_FP32_Quaternion* quaternion)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(quaternion);
|
|
|
|
const float square_modulus = bgc_fp32_quaternion_get_square_magnitude(quaternion);
|
|
|
|
|
|
|
|
|
|
|
|
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
return BGC_FAILURE;
|
|
|
|
return BGC_FAILURE;
|
|
|
|
@ -612,7 +612,7 @@ inline int bgc_fp32_quaternion_normalize(BGC_FP32_Quaternion* quaternion)
|
|
|
|
|
|
|
|
|
|
|
|
inline int bgc_fp64_quaternion_normalize(BGC_FP64_Quaternion* quaternion)
|
|
|
|
inline int bgc_fp64_quaternion_normalize(BGC_FP64_Quaternion* quaternion)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(quaternion);
|
|
|
|
const double square_modulus = bgc_fp64_quaternion_get_square_magnitude(quaternion);
|
|
|
|
|
|
|
|
|
|
|
|
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
return BGC_FAILURE;
|
|
|
|
return BGC_FAILURE;
|
|
|
|
@ -634,7 +634,7 @@ inline int bgc_fp64_quaternion_normalize(BGC_FP64_Quaternion* quaternion)
|
|
|
|
|
|
|
|
|
|
|
|
inline int bgc_fp32_quaternion_get_normalized(BGC_FP32_Quaternion* normalized, const BGC_FP32_Quaternion* quaternion)
|
|
|
|
inline int bgc_fp32_quaternion_get_normalized(BGC_FP32_Quaternion* normalized, const BGC_FP32_Quaternion* quaternion)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(quaternion);
|
|
|
|
const float square_modulus = bgc_fp32_quaternion_get_square_magnitude(quaternion);
|
|
|
|
|
|
|
|
|
|
|
|
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
bgc_fp32_quaternion_reset(normalized);
|
|
|
|
bgc_fp32_quaternion_reset(normalized);
|
|
|
|
@ -652,7 +652,7 @@ inline int bgc_fp32_quaternion_get_normalized(BGC_FP32_Quaternion* normalized, c
|
|
|
|
|
|
|
|
|
|
|
|
inline int bgc_fp64_quaternion_get_normalized(BGC_FP64_Quaternion* normalized, const BGC_FP64_Quaternion* quaternion)
|
|
|
|
inline int bgc_fp64_quaternion_get_normalized(BGC_FP64_Quaternion* normalized, const BGC_FP64_Quaternion* quaternion)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(quaternion);
|
|
|
|
const double square_modulus = bgc_fp64_quaternion_get_square_magnitude(quaternion);
|
|
|
|
|
|
|
|
|
|
|
|
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
bgc_fp64_quaternion_reset(normalized);
|
|
|
|
bgc_fp64_quaternion_reset(normalized);
|
|
|
|
@ -746,7 +746,7 @@ inline void _bgc_fp64_quaternion_turn_vector_back_roughly(BGC_FP64_Vector3* turn
|
|
|
|
|
|
|
|
|
|
|
|
inline int bgc_fp32_quaternion_turn_vector(BGC_FP32_Vector3* turned_vector, const BGC_FP32_Quaternion* quaternion, const BGC_FP32_Vector3* original_vector)
|
|
|
|
inline int bgc_fp32_quaternion_turn_vector(BGC_FP32_Vector3* turned_vector, const BGC_FP32_Quaternion* quaternion, const BGC_FP32_Vector3* original_vector)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(quaternion);
|
|
|
|
const float square_modulus = bgc_fp32_quaternion_get_square_magnitude(quaternion);
|
|
|
|
|
|
|
|
|
|
|
|
if (square_modulus < BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
if (square_modulus < BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
return BGC_FAILURE;
|
|
|
|
return BGC_FAILURE;
|
|
|
|
@ -772,7 +772,7 @@ inline int bgc_fp32_quaternion_turn_vector(BGC_FP32_Vector3* turned_vector, cons
|
|
|
|
|
|
|
|
|
|
|
|
inline int bgc_fp64_quaternion_turn_vector(BGC_FP64_Vector3* turned_vector, const BGC_FP64_Quaternion* quaternion, const BGC_FP64_Vector3* original_vector)
|
|
|
|
inline int bgc_fp64_quaternion_turn_vector(BGC_FP64_Vector3* turned_vector, const BGC_FP64_Quaternion* quaternion, const BGC_FP64_Vector3* original_vector)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(quaternion);
|
|
|
|
const double square_modulus = bgc_fp64_quaternion_get_square_magnitude(quaternion);
|
|
|
|
|
|
|
|
|
|
|
|
if (square_modulus < BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
if (square_modulus < BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
return BGC_FAILURE;
|
|
|
|
return BGC_FAILURE;
|
|
|
|
@ -800,7 +800,7 @@ inline int bgc_fp64_quaternion_turn_vector(BGC_FP64_Vector3* turned_vector, cons
|
|
|
|
|
|
|
|
|
|
|
|
inline int bgc_fp32_quaternion_turn_vector_back(BGC_FP32_Vector3* turned_vector, const BGC_FP32_Quaternion* quaternion, const BGC_FP32_Vector3* original_vector)
|
|
|
|
inline int bgc_fp32_quaternion_turn_vector_back(BGC_FP32_Vector3* turned_vector, const BGC_FP32_Quaternion* quaternion, const BGC_FP32_Vector3* original_vector)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(quaternion);
|
|
|
|
const float square_modulus = bgc_fp32_quaternion_get_square_magnitude(quaternion);
|
|
|
|
|
|
|
|
|
|
|
|
if (square_modulus < BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
if (square_modulus < BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
return BGC_FAILURE;
|
|
|
|
return BGC_FAILURE;
|
|
|
|
@ -826,7 +826,7 @@ inline int bgc_fp32_quaternion_turn_vector_back(BGC_FP32_Vector3* turned_vector,
|
|
|
|
|
|
|
|
|
|
|
|
inline int bgc_fp64_quaternion_turn_vector_back(BGC_FP64_Vector3* turned_vector, const BGC_FP64_Quaternion* quaternion, const BGC_FP64_Vector3* original_vector)
|
|
|
|
inline int bgc_fp64_quaternion_turn_vector_back(BGC_FP64_Vector3* turned_vector, const BGC_FP64_Quaternion* quaternion, const BGC_FP64_Vector3* original_vector)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(quaternion);
|
|
|
|
const double square_modulus = bgc_fp64_quaternion_get_square_magnitude(quaternion);
|
|
|
|
|
|
|
|
|
|
|
|
if (square_modulus < BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
if (square_modulus < BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
|
|
|
return BGC_FAILURE;
|
|
|
|
return BGC_FAILURE;
|
|
|
|
@ -1049,8 +1049,8 @@ inline int bgc_fp32_quaternion_are_close(const BGC_FP32_Quaternion* quaternion1,
|
|
|
|
const float dx2 = quaternion1->x2 - quaternion2->x2;
|
|
|
|
const float dx2 = quaternion1->x2 - quaternion2->x2;
|
|
|
|
const float dx3 = quaternion1->x3 - quaternion2->x3;
|
|
|
|
const float dx3 = quaternion1->x3 - quaternion2->x3;
|
|
|
|
|
|
|
|
|
|
|
|
const float square_modulus1 = bgc_fp32_quaternion_get_square_modulus(quaternion1);
|
|
|
|
const float square_modulus1 = bgc_fp32_quaternion_get_square_magnitude(quaternion1);
|
Internal server error - Personal Git Server: Beyond coding. We Forge.
500
Internal server error
Forgejo version: 11.0.1+gitea-1.22.0