Добавлены функции модуля для версоров и кватернионо / Functions of modulus have been added for versors and quaternions
This commit is contained in:
parent
bef7ab98f4
commit
03e390c1d0
12 changed files with 246 additions and 211 deletions
|
@ -9,15 +9,15 @@ void bg_fp32_quaternion_get_rotation_matrix(const BgFP32Quaternion* quaternion,
|
|||
const float x2x2 = quaternion->x2 * quaternion->x2;
|
||||
const float x3x3 = quaternion->x3 * quaternion->x3;
|
||||
|
||||
const float square_module = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||
const float square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||
|
||||
if (-BG_FP32_EPSYLON <= square_module && square_module <= BG_FP32_EPSYLON)
|
||||
if (-BG_FP32_EPSYLON <= square_modulus && square_modulus <= BG_FP32_EPSYLON)
|
||||
{
|
||||
bg_fp32_matrix3x3_set_to_identity(matrix);
|
||||
return;
|
||||
}
|
||||
|
||||
const float corrector1 = 1.0f / square_module;
|
||||
const float corrector1 = 1.0f / square_modulus;
|
||||
const float corrector2 = 2.0f * corrector1;
|
||||
|
||||
const float s0x1 = quaternion->s0 * quaternion->x1;
|
||||
|
@ -47,15 +47,15 @@ void bg_fp64_quaternion_get_rotation_matrix(const BgFP64Quaternion* quaternion,
|
|||
const double x2x2 = quaternion->x2 * quaternion->x2;
|
||||
const double x3x3 = quaternion->x3 * quaternion->x3;
|
||||
|
||||
const double square_module = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||
const double square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||
|
||||
if (-BG_FP64_EPSYLON <= square_module && square_module <= BG_FP64_EPSYLON)
|
||||
if (-BG_FP64_EPSYLON <= square_modulus && square_modulus <= BG_FP64_EPSYLON)
|
||||
{
|
||||
bg_fp64_matrix3x3_set_to_identity(matrix);
|
||||
return;
|
||||
}
|
||||
|
||||
const double corrector1 = 1.0f / square_module;
|
||||
const double corrector1 = 1.0f / square_modulus;
|
||||
const double corrector2 = 2.0f * corrector1;
|
||||
|
||||
const double s0x1 = quaternion->s0 * quaternion->x1;
|
||||
|
@ -87,15 +87,15 @@ void bg_fp32_quaternion_get_reverse_matrix(const BgFP32Quaternion* quaternion, B
|
|||
const float x2x2 = quaternion->x2 * quaternion->x2;
|
||||
const float x3x3 = quaternion->x3 * quaternion->x3;
|
||||
|
||||
const float square_module = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||
const float square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||
|
||||
if (-BG_FP32_EPSYLON <= square_module && square_module <= BG_FP32_EPSYLON)
|
||||
if (-BG_FP32_EPSYLON <= square_modulus && square_modulus <= BG_FP32_EPSYLON)
|
||||
{
|
||||
bg_fp32_matrix3x3_set_to_identity(matrix);
|
||||
return;
|
||||
}
|
||||
|
||||
const float corrector1 = 1.0f / square_module;
|
||||
const float corrector1 = 1.0f / square_modulus;
|
||||
const float corrector2 = 2.0f * corrector1;
|
||||
|
||||
const float s0x1 = quaternion->s0 * quaternion->x1;
|
||||
|
@ -125,15 +125,15 @@ void bg_fp64_quaternion_get_reverse_matrix(const BgFP64Quaternion* quaternion, B
|
|||
const double x2x2 = quaternion->x2 * quaternion->x2;
|
||||
const double x3x3 = quaternion->x3 * quaternion->x3;
|
||||
|
||||
const double square_module = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||
const double square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||
|
||||
if (-BG_FP64_EPSYLON <= square_module && square_module <= BG_FP64_EPSYLON)
|
||||
if (-BG_FP64_EPSYLON <= square_modulus && square_modulus <= BG_FP64_EPSYLON)
|
||||
{
|
||||
bg_fp64_matrix3x3_set_to_identity(matrix);
|
||||
return;
|
||||
}
|
||||
|
||||
const double corrector1 = 1.0f / square_module;
|
||||
const double corrector1 = 1.0f / square_modulus;
|
||||
const double corrector2 = 2.0f * corrector1;
|
||||
|
||||
const double s0x1 = quaternion->s0 * quaternion->x1;
|
||||
|
|
|
@ -89,72 +89,96 @@ static inline void bg_fp64_quaternion_copy(const BgFP64Quaternion* from, BgFP64Q
|
|||
|
||||
// ============= Copy to twin type ============== //
|
||||
|
||||
static inline void bg_fp32_quaternion_set_from_fp64(const BgFP64Quaternion* versor, BgFP32Quaternion* result)
|
||||
static inline void bg_fp32_quaternion_set_from_fp64(const BgFP64Quaternion* quaternion, BgFP32Quaternion* result)
|
||||
{
|
||||
result->s0 = (float) versor->s0;
|
||||
result->x1 = (float) versor->x1;
|
||||
result->x2 = (float) versor->x2;
|
||||
result->x3 = (float) versor->x3;
|
||||
result->s0 = (float) quaternion->s0;
|
||||
result->x1 = (float) quaternion->x1;
|
||||
result->x2 = (float) quaternion->x2;
|
||||
result->x3 = (float) quaternion->x3;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_quaternion_set_from_fp32(const BgFP32Quaternion* versor, BgFP64Quaternion* result)
|
||||
static inline void bg_fp64_quaternion_set_from_fp32(const BgFP32Quaternion* quaternion, BgFP64Quaternion* result)
|
||||
{
|
||||
result->s0 = versor->s0;
|
||||
result->x1 = versor->x1;
|
||||
result->x2 = versor->x2;
|
||||
result->x3 = versor->x3;
|
||||
result->s0 = quaternion->s0;
|
||||
result->x1 = quaternion->x1;
|
||||
result->x2 = quaternion->x2;
|
||||
result->x3 = quaternion->x3;
|
||||
}
|
||||
|
||||
// ================= Inversion ================== //
|
||||
|
||||
static inline void bg_fp32_quaternion_conjugate(BgFP32Quaternion* versor)
|
||||
static inline void bg_fp32_quaternion_conjugate(BgFP32Quaternion* quaternion)
|
||||
{
|
||||
versor->x1 = -versor->x1;
|
||||
versor->x2 = -versor->x2;
|
||||
versor->x3 = -versor->x3;
|
||||
quaternion->x1 = -quaternion->x1;
|
||||
quaternion->x2 = -quaternion->x2;
|
||||
quaternion->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_quaternion_conjugate(BgFP64Quaternion* versor)
|
||||
static inline void bg_fp64_quaternion_conjugate(BgFP64Quaternion* quaternion)
|
||||
{
|
||||
versor->x1 = -versor->x1;
|
||||
versor->x2 = -versor->x2;
|
||||
versor->x3 = -versor->x3;
|
||||
quaternion->x1 = -quaternion->x1;
|
||||
quaternion->x2 = -quaternion->x2;
|
||||
quaternion->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
// ================ Set Conjugate =============== //
|
||||
|
||||
static inline void bg_fp32_quaternion_set_conjugate(const BgFP32Quaternion* versor, BgFP32Quaternion* result)
|
||||
static inline void bg_fp32_quaternion_set_conjugate(const BgFP32Quaternion* quaternion, BgFP32Quaternion* result)
|
||||
{
|
||||
result->s0 = versor->s0;
|
||||
result->x1 = -versor->x1;
|
||||
result->x2 = -versor->x2;
|
||||
result->x3 = -versor->x3;
|
||||
result->s0 = quaternion->s0;
|
||||
result->x1 = -quaternion->x1;
|
||||
result->x2 = -quaternion->x2;
|
||||
result->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_quaternion_set_conjugate(const BgFP64Quaternion* versor, BgFP64Quaternion* result)
|
||||
static inline void bg_fp64_quaternion_set_conjugate(const BgFP64Quaternion* quaternion, BgFP64Quaternion* result)
|
||||
{
|
||||
result->s0 = versor->s0;
|
||||
result->x1 = -versor->x1;
|
||||
result->x2 = -versor->x2;
|
||||
result->x3 = -versor->x3;
|
||||
result->s0 = quaternion->s0;
|
||||
result->x1 = -quaternion->x1;
|
||||
result->x2 = -quaternion->x2;
|
||||
result->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
// ================ Get Inverted ================ //
|
||||
// ================ Set Conjugate =============== //
|
||||
|
||||
static inline void bg_fp32_quaternion_set_conjugate_fp64(const BgFP64Quaternion* versor, BgFP32Quaternion* result)
|
||||
static inline void bg_fp32_quaternion_set_conjugate_fp64(const BgFP64Quaternion* quaternion, BgFP32Quaternion* result)
|
||||
{
|
||||
result->s0 = (float) versor->s0;
|
||||
result->x1 = (float) -versor->x1;
|
||||
result->x2 = (float) -versor->x2;
|
||||
result->x3 = (float) -versor->x3;
|
||||
result->s0 = (float) quaternion->s0;
|
||||
result->x1 = (float) -quaternion->x1;
|
||||
result->x2 = (float) -quaternion->x2;
|
||||
result->x3 = (float) -quaternion->x3;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_quaternion_set_conjugate_fp32(const BgFP32Quaternion* versor, BgFP64Quaternion* result)
|
||||
static inline void bg_fp64_quaternion_set_conjugate_fp32(const BgFP32Quaternion* quaternion, BgFP64Quaternion* result)
|
||||
{
|
||||
result->s0 = versor->s0;
|
||||
result->x1 = -versor->x1;
|
||||
result->x2 = -versor->x2;
|
||||
result->x3 = -versor->x3;
|
||||
result->s0 = quaternion->s0;
|
||||
result->x1 = -quaternion->x1;
|
||||
result->x2 = -quaternion->x2;
|
||||
result->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
// ============= Get Square Modulus ============= //
|
||||
|
||||
static inline float bg_fp32_quaternion_get_square_modulus(const BgFP32Quaternion* quaternion)
|
||||
{
|
||||
return (quaternion->s0 * quaternion->s0 + quaternion->x1 * quaternion->x1) + (quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3);
|
||||
}
|
||||
|
||||
static inline double bg_fp64_quaternion_get_square_modulus(const BgFP64Quaternion* quaternion)
|
||||
{
|
||||
return (quaternion->s0 * quaternion->s0 + quaternion->x1 * quaternion->x1) + (quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3);
|
||||
}
|
||||
|
||||
// ================ Get Modulus ================= //
|
||||
|
||||
static inline float bg_fp32_quaternion_get_modulus(const BgFP32Quaternion* quaternion)
|
||||
{
|
||||
return sqrtf(bg_fp32_quaternion_get_square_modulus(quaternion));
|
||||
}
|
||||
|
||||
static inline double bg_fp64_quaternion_get_modulus(const BgFP64Quaternion* quaternion)
|
||||
{
|
||||
return sqrt(bg_fp64_quaternion_get_square_modulus(quaternion));
|
||||
}
|
||||
|
||||
// ============ Make Rotation Matrix ============ //
|
||||
|
|
|
@ -8,19 +8,19 @@ float bg_fp32_vector2_get_angle(const BgFP32Vector2* vector1, const BgFP32Vector
|
|||
return 0.0f;
|
||||
}
|
||||
|
||||
const float square_module1 = bg_fp32_vector2_get_square_module(vector1);
|
||||
const float square_modulus1 = bg_fp32_vector2_get_square_modulus(vector1);
|
||||
|
||||
if (square_module1 <= BG_FP32_SQUARE_EPSYLON) {
|
||||
if (square_modulus1 <= BG_FP32_SQUARE_EPSYLON) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
const float square_module2 = bg_fp32_vector2_get_square_module(vector2);
|
||||
const float square_modulus2 = bg_fp32_vector2_get_square_modulus(vector2);
|
||||
|
||||
if (square_module2 <= BG_FP32_SQUARE_EPSYLON) {
|
||||
if (square_modulus2 <= BG_FP32_SQUARE_EPSYLON) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
const float cosine = bg_fp32_vector2_dot_product(vector1, vector2) / sqrtf(square_module1 * square_module2);
|
||||
const float cosine = bg_fp32_vector2_dot_product(vector1, vector2) / sqrtf(square_modulus1 * square_modulus2);
|
||||
|
||||
if (cosine >= 1.0f - BG_FP32_EPSYLON) {
|
||||
return 0.0f;
|
||||
|
@ -39,19 +39,19 @@ double bg_fp64_vector2_get_angle(const BgFP64Vector2* vector1, const BgFP64Vecto
|
|||
return 0.0;
|
||||
}
|
||||
|
||||
const double square_module1 = bg_fp64_vector2_get_square_module(vector1);
|
||||
const double square_modulus1 = bg_fp64_vector2_get_square_modulus(vector1);
|
||||
|
||||
if (square_module1 <= BG_FP64_SQUARE_EPSYLON) {
|
||||
if (square_modulus1 <= BG_FP64_SQUARE_EPSYLON) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
const double square_module2 = bg_fp64_vector2_get_square_module(vector2);
|
||||
const double square_modulus2 = bg_fp64_vector2_get_square_modulus(vector2);
|
||||
|
||||
if (square_module2 <= BG_FP64_SQUARE_EPSYLON) {
|
||||
if (square_modulus2 <= BG_FP64_SQUARE_EPSYLON) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
const double cosine = bg_fp64_vector2_dot_product(vector1, vector2) / sqrt(square_module1 * square_module2);
|
||||
const double cosine = bg_fp64_vector2_dot_product(vector1, vector2) / sqrt(square_modulus1 * square_modulus2);
|
||||
|
||||
if (cosine >= 1.0 - BG_FP64_EPSYLON) {
|
||||
return 0.0;
|
||||
|
|
|
@ -102,50 +102,50 @@ static inline void bg_fp64_vector2_set_reverse_fp32(const BgFP32Vector2* from, B
|
|||
|
||||
// =================== Module =================== //
|
||||
|
||||
static inline float bg_fp32_vector2_get_square_module(const BgFP32Vector2* vector)
|
||||
static inline float bg_fp32_vector2_get_square_modulus(const BgFP32Vector2* vector)
|
||||
{
|
||||
return vector->x1 * vector->x1 + vector->x2 * vector->x2;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_vector2_get_square_module(const BgFP64Vector2* vector)
|
||||
static inline double bg_fp64_vector2_get_square_modulus(const BgFP64Vector2* vector)
|
||||
{
|
||||
return vector->x1 * vector->x1 + vector->x2 * vector->x2;
|
||||
}
|
||||
|
||||
static inline float bg_fp32_vector2_get_module(const BgFP32Vector2* vector)
|
||||
static inline float bg_fp32_vector2_get_modulus(const BgFP32Vector2* vector)
|
||||
{
|
||||
return sqrtf(bg_fp32_vector2_get_square_module(vector));
|
||||
return sqrtf(bg_fp32_vector2_get_square_modulus(vector));
|
||||
}
|
||||
|
||||
static inline double bg_fp64_vector2_get_module(const BgFP64Vector2* vector)
|
||||
static inline double bg_fp64_vector2_get_modulus(const BgFP64Vector2* vector)
|
||||
{
|
||||
return sqrt(bg_fp64_vector2_get_square_module(vector));
|
||||
return sqrt(bg_fp64_vector2_get_square_modulus(vector));
|
||||
}
|
||||
|
||||
// ================= Comparison ================= //
|
||||
|
||||
static inline int bg_fp32_vector2_is_zero(const BgFP32Vector2* vector)
|
||||
{
|
||||
return bg_fp32_vector2_get_square_module(vector) <= BG_FP32_SQUARE_EPSYLON;
|
||||
return bg_fp32_vector2_get_square_modulus(vector) <= BG_FP32_SQUARE_EPSYLON;
|
||||
}
|
||||
|
||||
static inline int bg_fp64_vector2_is_zero(const BgFP64Vector2* vector)
|
||||
{
|
||||
return bg_fp64_vector2_get_square_module(vector) <= BG_FP64_SQUARE_EPSYLON;
|
||||
return bg_fp64_vector2_get_square_modulus(vector) <= BG_FP64_SQUARE_EPSYLON;
|
||||
}
|
||||
|
||||
static inline int bg_fp32_vector2_is_unit(const BgFP32Vector2* vector)
|
||||
{
|
||||
const float square_module = bg_fp32_vector2_get_square_module(vector);
|
||||
const float square_modulus = bg_fp32_vector2_get_square_modulus(vector);
|
||||
|
||||
return 1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON;
|
||||
return 1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON;
|
||||
}
|
||||
|
||||
static inline int bg_fp64_vector2_is_unit(const BgFP64Vector2* vector)
|
||||
{
|
||||
const double square_module = bg_fp64_vector2_get_square_module(vector);
|
||||
const double square_modulus = bg_fp64_vector2_get_square_modulus(vector);
|
||||
|
||||
return 1.0f - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP64_TWO_EPSYLON;
|
||||
return 1.0f - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP64_TWO_EPSYLON;
|
||||
}
|
||||
|
||||
// ==================== Add ===================== //
|
||||
|
@ -274,35 +274,35 @@ static inline double bg_fp64_vector2_cross_product(const BgFP64Vector2* vector1,
|
|||
|
||||
static inline int bg_fp32_vector2_normalize(BgFP32Vector2* vector)
|
||||
{
|
||||
const float square_module = bg_fp32_vector2_get_square_module(vector);
|
||||
const float square_modulus = bg_fp32_vector2_get_square_modulus(vector);
|
||||
|
||||
if (1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
||||
if (1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_module <= BG_FP32_SQUARE_EPSYLON) {
|
||||
if (square_modulus <= BG_FP32_SQUARE_EPSYLON) {
|
||||
bg_fp32_vector2_reset(vector);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bg_fp32_vector2_divide(vector, sqrtf(square_module), vector);
|
||||
bg_fp32_vector2_divide(vector, sqrtf(square_modulus), vector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline int bg_fp64_vector2_normalize(BgFP64Vector2* vector)
|
||||
{
|
||||
const double square_module = bg_fp64_vector2_get_square_module(vector);
|
||||
const double square_modulus = bg_fp64_vector2_get_square_modulus(vector);
|
||||
|
||||
if (1.0 - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
||||
if (1.0 - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_module <= BG_FP64_SQUARE_EPSYLON) {
|
||||
if (square_modulus <= BG_FP64_SQUARE_EPSYLON) {
|
||||
bg_fp64_vector2_reset(vector);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bg_fp64_vector2_divide(vector, sqrt(square_module), vector);
|
||||
bg_fp64_vector2_divide(vector, sqrt(square_modulus), vector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -360,38 +360,38 @@ static inline double bg_fp64_vector2_get_distance(const BgFP64Vector2* vector1,
|
|||
|
||||
static inline int bg_fp32_vector2_are_equal(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2)
|
||||
{
|
||||
const float square_module1 = bg_fp32_vector2_get_square_module(vector1);
|
||||
const float square_module2 = bg_fp32_vector2_get_square_module(vector2);
|
||||
const float square_module3 = bg_fp32_vector2_get_square_distance(vector1, vector2);
|
||||
const float square_modulus1 = bg_fp32_vector2_get_square_modulus(vector1);
|
||||
const float square_modulus2 = bg_fp32_vector2_get_square_modulus(vector2);
|
||||
const float square_modulus3 = bg_fp32_vector2_get_square_distance(vector1, vector2);
|
||||
|
||||
// 2.0f means dimension amount
|
||||
if (square_module1 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_module3 < (2.0f * BG_FP32_SQUARE_EPSYLON);
|
||||
if (square_modulus1 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_modulus3 < (2.0f * BG_FP32_SQUARE_EPSYLON);
|
||||
}
|
||||
|
||||
if (square_module1 <= square_module2) {
|
||||
return square_module3 <= (2.0f * BG_FP32_SQUARE_EPSYLON) * square_module2;
|
||||
if (square_modulus1 <= square_modulus2) {
|
||||
return square_modulus3 <= (2.0f * BG_FP32_SQUARE_EPSYLON) * square_modulus2;
|
||||
}
|
||||
|
||||
return square_module3 <= (2.0f * BG_FP32_SQUARE_EPSYLON) * square_module1;
|
||||
return square_modulus3 <= (2.0f * BG_FP32_SQUARE_EPSYLON) * square_modulus1;
|
||||
}
|
||||
|
||||
static inline int bg_fp64_vector2_are_equal(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2)
|
||||
{
|
||||
const double square_module1 = bg_fp64_vector2_get_square_module(vector1);
|
||||
const double square_module2 = bg_fp64_vector2_get_square_module(vector2);
|
||||
const double square_module3 = bg_fp64_vector2_get_square_distance(vector1, vector2);
|
||||
const double square_modulus1 = bg_fp64_vector2_get_square_modulus(vector1);
|
||||
const double square_modulus2 = bg_fp64_vector2_get_square_modulus(vector2);
|
||||
const double square_modulus3 = bg_fp64_vector2_get_square_distance(vector1, vector2);
|
||||
|
||||
// 2.0 means dimension amount
|
||||
if (square_module1 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_module3 < (2.0 * BG_FP64_SQUARE_EPSYLON);
|
||||
if (square_modulus1 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_modulus3 < (2.0 * BG_FP64_SQUARE_EPSYLON);
|
||||
}
|
||||
|
||||
if (square_module1 <= square_module2) {
|
||||
return square_module3 <= (2.0 * BG_FP64_SQUARE_EPSYLON) * square_module2;
|
||||
if (square_modulus1 <= square_modulus2) {
|
||||
return square_modulus3 <= (2.0 * BG_FP64_SQUARE_EPSYLON) * square_modulus2;
|
||||
}
|
||||
|
||||
return square_module3 <= (2.0 * BG_FP64_SQUARE_EPSYLON) * square_module1;
|
||||
return square_modulus3 <= (2.0 * BG_FP64_SQUARE_EPSYLON) * square_modulus1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -8,19 +8,19 @@ float bg_fp32_vector3_get_angle(const BgFP32Vector3* vector1, const BgFP32Vector
|
|||
return 0.0f;
|
||||
}
|
||||
|
||||
const float square_module1 = bg_fp32_vector3_get_square_module(vector1);
|
||||
const float square_modulus1 = bg_fp32_vector3_get_square_modulus(vector1);
|
||||
|
||||
if (square_module1 <= BG_FP32_SQUARE_EPSYLON) {
|
||||
if (square_modulus1 <= BG_FP32_SQUARE_EPSYLON) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
const float square_module2 = bg_fp32_vector3_get_square_module(vector2);
|
||||
const float square_modulus2 = bg_fp32_vector3_get_square_modulus(vector2);
|
||||
|
||||
if (square_module2 <= BG_FP32_SQUARE_EPSYLON) {
|
||||
if (square_modulus2 <= BG_FP32_SQUARE_EPSYLON) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
const float cosine = bg_fp32_vector3_dot_product(vector1, vector2) / sqrtf(square_module1 * square_module2);
|
||||
const float cosine = bg_fp32_vector3_dot_product(vector1, vector2) / sqrtf(square_modulus1 * square_modulus2);
|
||||
|
||||
if (cosine >= 1.0f - BG_FP32_EPSYLON) {
|
||||
return 0.0f;
|
||||
|
@ -39,19 +39,19 @@ double bg_fp64_vector3_get_angle(const BgFP64Vector3* vector1, const BgFP64Vecto
|
|||
return 0.0;
|
||||
}
|
||||
|
||||
const double square_module1 = bg_fp64_vector3_get_square_module(vector1);
|
||||
const double square_modulus1 = bg_fp64_vector3_get_square_modulus(vector1);
|
||||
|
||||
if (square_module1 <= BG_FP64_SQUARE_EPSYLON) {
|
||||
if (square_modulus1 <= BG_FP64_SQUARE_EPSYLON) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
const double square_module2 = bg_fp64_vector3_get_square_module(vector2);
|
||||
const double square_modulus2 = bg_fp64_vector3_get_square_modulus(vector2);
|
||||
|
||||
if (square_module2 <= BG_FP64_SQUARE_EPSYLON) {
|
||||
if (square_modulus2 <= BG_FP64_SQUARE_EPSYLON) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
const double cosine = bg_fp64_vector3_dot_product(vector1, vector2) / sqrt(square_module1 * square_module2);
|
||||
const double cosine = bg_fp64_vector3_dot_product(vector1, vector2) / sqrt(square_modulus1 * square_modulus2);
|
||||
|
||||
if (cosine >= 1.0 - BG_FP64_EPSYLON) {
|
||||
return 0.0;
|
||||
|
|
|
@ -116,50 +116,50 @@ static inline void bg_fp64_vector3_set_reverse_fp32(const BgFP32Vector3* from, B
|
|||
|
||||
// =================== Module =================== //
|
||||
|
||||
static inline float bg_fp32_vector3_get_square_module(const BgFP32Vector3* vector)
|
||||
static inline float bg_fp32_vector3_get_square_modulus(const BgFP32Vector3* vector)
|
||||
{
|
||||
return vector->x1 * vector->x1 + vector->x2 * vector->x2 + vector->x3 * vector->x3;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_vector3_get_square_module(const BgFP64Vector3* vector)
|
||||
static inline double bg_fp64_vector3_get_square_modulus(const BgFP64Vector3* vector)
|
||||
{
|
||||
return vector->x1 * vector->x1 + vector->x2 * vector->x2 + vector->x3 * vector->x3;
|
||||
}
|
||||
|
||||
static inline float bg_fp32_vector3_get_module(const BgFP32Vector3* vector)
|
||||
static inline float bg_fp32_vector3_get_modulus(const BgFP32Vector3* vector)
|
||||
{
|
||||
return sqrtf(bg_fp32_vector3_get_square_module(vector));
|
||||
return sqrtf(bg_fp32_vector3_get_square_modulus(vector));
|
||||
}
|
||||
|
||||
static inline double bg_fp64_vector3_get_module(const BgFP64Vector3* vector)
|
||||
static inline double bg_fp64_vector3_get_modulus(const BgFP64Vector3* vector)
|
||||
{
|
||||
return sqrt(bg_fp64_vector3_get_square_module(vector));
|
||||
return sqrt(bg_fp64_vector3_get_square_modulus(vector));
|
||||
}
|
||||
|
||||
// ================= Comparison ================= //
|
||||
|
||||
static inline int bg_fp32_vector3_is_zero(const BgFP32Vector3* vector)
|
||||
{
|
||||
return bg_fp32_vector3_get_square_module(vector) <= BG_FP32_SQUARE_EPSYLON;
|
||||
return bg_fp32_vector3_get_square_modulus(vector) <= BG_FP32_SQUARE_EPSYLON;
|
||||
}
|
||||
|
||||
static inline int bg_fp64_vector3_is_zero(const BgFP64Vector3* vector)
|
||||
{
|
||||
return bg_fp64_vector3_get_square_module(vector) <= BG_FP64_SQUARE_EPSYLON;
|
||||
return bg_fp64_vector3_get_square_modulus(vector) <= BG_FP64_SQUARE_EPSYLON;
|
||||
}
|
||||
|
||||
static inline int bg_fp32_vector3_is_unit(const BgFP32Vector3* vector)
|
||||
{
|
||||
const float square_module = bg_fp32_vector3_get_square_module(vector);
|
||||
const float square_modulus = bg_fp32_vector3_get_square_modulus(vector);
|
||||
|
||||
return 1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON;
|
||||
return 1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON;
|
||||
}
|
||||
|
||||
static inline int bg_fp64_vector3_is_unit(const BgFP64Vector3* vector)
|
||||
{
|
||||
const double square_module = bg_fp64_vector3_get_square_module(vector);
|
||||
const double square_modulus = bg_fp64_vector3_get_square_modulus(vector);
|
||||
|
||||
return 1.0f - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP64_TWO_EPSYLON;
|
||||
return 1.0f - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP64_TWO_EPSYLON;
|
||||
}
|
||||
|
||||
// ==================== Add ===================== //
|
||||
|
@ -350,35 +350,35 @@ static inline void bg_fp64_vector3_double_cross(const BgFP64Vector3* vector1, co
|
|||
|
||||
static inline int bg_fp32_vector3_normalize(BgFP32Vector3* vector)
|
||||
{
|
||||
const float square_module = bg_fp32_vector3_get_square_module(vector);
|
||||
const float square_modulus = bg_fp32_vector3_get_square_modulus(vector);
|
||||
|
||||
if (1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
||||
if (1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_module <= BG_FP32_SQUARE_EPSYLON) {
|
||||
if (square_modulus <= BG_FP32_SQUARE_EPSYLON) {
|
||||
bg_fp32_vector3_reset(vector);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bg_fp32_vector3_divide(vector, sqrtf(square_module), vector);
|
||||
bg_fp32_vector3_divide(vector, sqrtf(square_modulus), vector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline int bg_fp64_vector3_normalize(BgFP64Vector3* vector)
|
||||
{
|
||||
const double square_module = bg_fp64_vector3_get_square_module(vector);
|
||||
const double square_modulus = bg_fp64_vector3_get_square_modulus(vector);
|
||||
|
||||
if (1.0 - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
||||
if (1.0 - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_module <= BG_FP64_SQUARE_EPSYLON) {
|
||||
if (square_modulus <= BG_FP64_SQUARE_EPSYLON) {
|
||||
bg_fp64_vector3_reset(vector);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bg_fp64_vector3_divide(vector, sqrt(square_module), vector);
|
||||
bg_fp64_vector3_divide(vector, sqrt(square_modulus), vector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -438,38 +438,38 @@ static inline double bg_fp64_vector3_get_distance(const BgFP64Vector3* vector1,
|
|||
|
||||
static inline int bg_fp32_vector3_are_equal(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2)
|
||||
{
|
||||
const float square_module1 = bg_fp32_vector3_get_square_module(vector1);
|
||||
const float square_module2 = bg_fp32_vector3_get_square_module(vector2);
|
||||
const float square_module3 = bg_fp32_vector3_get_square_distance(vector1, vector2);
|
||||
const float square_modulus1 = bg_fp32_vector3_get_square_modulus(vector1);
|
||||
const float square_modulus2 = bg_fp32_vector3_get_square_modulus(vector2);
|
||||
const float square_modulus3 = bg_fp32_vector3_get_square_distance(vector1, vector2);
|
||||
|
||||
// 3.0f means dimension amount
|
||||
if (square_module1 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_module3 < (3.0f * BG_FP32_SQUARE_EPSYLON);
|
||||
if (square_modulus1 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_modulus3 < (3.0f * BG_FP32_SQUARE_EPSYLON);
|
||||
}
|
||||
|
||||
if (square_module1 <= square_module2) {
|
||||
return square_module3 <= (3.0f * BG_FP32_SQUARE_EPSYLON) * square_module2;
|
||||
if (square_modulus1 <= square_modulus2) {
|
||||
return square_modulus3 <= (3.0f * BG_FP32_SQUARE_EPSYLON) * square_modulus2;
|
||||
}
|
||||
|
||||
return square_module3 <= (3.0f * BG_FP32_SQUARE_EPSYLON) * square_module1;
|
||||
return square_modulus3 <= (3.0f * BG_FP32_SQUARE_EPSYLON) * square_modulus1;
|
||||
}
|
||||
|
||||
static inline int bg_fp64_vector3_are_equal(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2)
|
||||
{
|
||||
const double square_module1 = bg_fp64_vector3_get_square_module(vector1);
|
||||
const double square_module2 = bg_fp64_vector3_get_square_module(vector2);
|
||||
const double square_module3 = bg_fp64_vector3_get_square_distance(vector1, vector2);
|
||||
const double square_modulus1 = bg_fp64_vector3_get_square_modulus(vector1);
|
||||
const double square_modulus2 = bg_fp64_vector3_get_square_modulus(vector2);
|
||||
const double square_modulus3 = bg_fp64_vector3_get_square_distance(vector1, vector2);
|
||||
|
||||
// 3.0 means dimension amount
|
||||
if (square_module1 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_module3 < (3.0 * BG_FP64_SQUARE_EPSYLON);
|
||||
if (square_modulus1 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_modulus3 < (3.0 * BG_FP64_SQUARE_EPSYLON);
|
||||
}
|
||||
|
||||
if (square_module1 <= square_module2) {
|
||||
return square_module3 <= (3.0 * BG_FP64_SQUARE_EPSYLON) * square_module2;
|
||||
if (square_modulus1 <= square_modulus2) {
|
||||
return square_modulus3 <= (3.0 * BG_FP64_SQUARE_EPSYLON) * square_modulus2;
|
||||
}
|
||||
|
||||
return square_module3 <= (3.0 * BG_FP64_SQUARE_EPSYLON) * square_module1;
|
||||
return square_modulus3 <= (3.0 * BG_FP64_SQUARE_EPSYLON) * square_modulus1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,9 +7,9 @@ const BgFP32Versor BG_FP32_IDLE_VERSOR = { 1.0f, 0.0f, 0.0f, 0.0f };
|
|||
|
||||
const BgFP64Versor BG_FP64_IDLE_VERSOR = { 1.0, 0.0, 0.0, 0.0 };
|
||||
|
||||
void __bg_fp32_versor_normalize(const float square_module, __BgFP32DarkTwinVersor* twin)
|
||||
void __bg_fp32_versor_normalize(const float square_modulus, __BgFP32DarkTwinVersor* twin)
|
||||
{
|
||||
if (square_module <= BG_FP32_SQUARE_EPSYLON || (twin->s0 * twin->s0) >= (1.0f - BG_FP32_TWO_EPSYLON) * square_module) {
|
||||
if (square_modulus <= BG_FP32_SQUARE_EPSYLON || (twin->s0 * twin->s0) >= (1.0f - BG_FP32_TWO_EPSYLON) * square_modulus) {
|
||||
twin->s0 = 1.0f;
|
||||
twin->x1 = 0.0f;
|
||||
twin->x2 = 0.0f;
|
||||
|
@ -17,17 +17,17 @@ void __bg_fp32_versor_normalize(const float square_module, __BgFP32DarkTwinVerso
|
|||
return;
|
||||
}
|
||||
|
||||
const float module = sqrtf(square_module);
|
||||
const float modulus = sqrtf(square_modulus);
|
||||
|
||||
twin->s0 /= module;
|
||||
twin->x1 /= module;
|
||||
twin->x2 /= module;
|
||||
twin->x3 /= module;
|
||||
twin->s0 /= modulus;
|
||||
twin->x1 /= modulus;
|
||||
twin->x2 /= modulus;
|
||||
twin->x3 /= modulus;
|
||||
}
|
||||
|
||||
void __bg_fp64_versor_normalize(const double square_module, __BgFP64DarkTwinVersor* twin)
|
||||
void __bg_fp64_versor_normalize(const double square_modulus, __BgFP64DarkTwinVersor* twin)
|
||||
{
|
||||
if (square_module <= BG_FP64_SQUARE_EPSYLON || (twin->s0 * twin->s0) >= (1.0 - BG_FP64_TWO_EPSYLON) * square_module) {
|
||||
if (square_modulus <= BG_FP64_SQUARE_EPSYLON || (twin->s0 * twin->s0) >= (1.0 - BG_FP64_TWO_EPSYLON) * square_modulus) {
|
||||
twin->s0 = 1.0;
|
||||
twin->x1 = 0.0;
|
||||
twin->x2 = 0.0;
|
||||
|
@ -35,12 +35,12 @@ void __bg_fp64_versor_normalize(const double square_module, __BgFP64DarkTwinVers
|
|||
return;
|
||||
}
|
||||
|
||||
const double module = sqrt(square_module);
|
||||
const double modulus = sqrt(square_modulus);
|
||||
|
||||
twin->s0 /= module;
|
||||
twin->x1 /= module;
|
||||
twin->x2 /= module;
|
||||
twin->x3 /= module;
|
||||
twin->s0 /= modulus;
|
||||
twin->x1 /= modulus;
|
||||
twin->x2 /= modulus;
|
||||
twin->x3 /= modulus;
|
||||
}
|
||||
|
||||
// =============== Set Crude Turn =============== //
|
||||
|
@ -108,11 +108,11 @@ void bg_fp32_versor_get_rotation(const BgFP32Versor* versor, BgFP32Rotation3* re
|
|||
|
||||
result->radians = 2.0f * acosf(versor->s0 / sqrtf(versor->s0 * versor->s0 + square_vector));
|
||||
|
||||
const float vector_module = sqrtf(square_vector);
|
||||
const float vector_modulus = sqrtf(square_vector);
|
||||
|
||||
result->axis.x1 = versor->x1 / vector_module;
|
||||
result->axis.x2 = versor->x2 / vector_module;
|
||||
result->axis.x3 = versor->x3 / vector_module;
|
||||
result->axis.x1 = versor->x1 / vector_modulus;
|
||||
result->axis.x2 = versor->x2 / vector_modulus;
|
||||
result->axis.x3 = versor->x3 / vector_modulus;
|
||||
}
|
||||
|
||||
void bg_fp64_versor_get_rotation(const BgFP64Versor* versor, BgFP64Rotation3* result)
|
||||
|
@ -130,9 +130,9 @@ void bg_fp64_versor_get_rotation(const BgFP64Versor* versor, BgFP64Rotation3* re
|
|||
|
||||
result->radians = 2.0 * acos(versor->s0 / sqrt(versor->s0 * versor->s0 + square_vector));
|
||||
|
||||
const double vector_module = sqrt(square_vector);
|
||||
const double vector_modulus = sqrt(square_vector);
|
||||
|
||||
result->axis.x1 = versor->x1 / vector_module;
|
||||
result->axis.x2 = versor->x2 / vector_module;
|
||||
result->axis.x3 = versor->x3 / vector_module;
|
||||
result->axis.x1 = versor->x1 / vector_modulus;
|
||||
result->axis.x2 = versor->x2 / vector_modulus;
|
||||
result->axis.x3 = versor->x3 / vector_modulus;
|
||||
}
|
||||
|
|
|
@ -58,9 +58,9 @@ static inline void bg_fp64_versor_reset(BgFP64Versor* versor)
|
|||
|
||||
// ==================== Set ===================== //
|
||||
|
||||
void __bg_fp32_versor_normalize(const float square_module, __BgFP32DarkTwinVersor* twin);
|
||||
void __bg_fp32_versor_normalize(const float square_modulus, __BgFP32DarkTwinVersor* twin);
|
||||
|
||||
void __bg_fp64_versor_normalize(const double square_module, __BgFP64DarkTwinVersor* twin);
|
||||
void __bg_fp64_versor_normalize(const double square_modulus, __BgFP64DarkTwinVersor* twin);
|
||||
|
||||
static inline void bg_fp32_versor_set_values(const float s0, const float x1, const float x2, const float x3, BgFP32Versor* versor)
|
||||
{
|
||||
|
@ -71,13 +71,13 @@ static inline void bg_fp32_versor_set_values(const float s0, const float x1, con
|
|||
twin->x2 = x2;
|
||||
twin->x3 = x3;
|
||||
|
||||
const float square_module = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
|
||||
const float square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
|
||||
|
||||
if (1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
||||
if (1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
||||
return;
|
||||
}
|
||||
|
||||
__bg_fp32_versor_normalize(square_module, (__BgFP32DarkTwinVersor*)versor);
|
||||
__bg_fp32_versor_normalize(square_modulus, (__BgFP32DarkTwinVersor*)versor);
|
||||
}
|
||||
|
||||
static inline void bg_fp64_versor_set_values(const double s0, const double x1, const double x2, const double x3, BgFP64Versor* versor)
|
||||
|
@ -89,13 +89,13 @@ static inline void bg_fp64_versor_set_values(const double s0, const double x1, c
|
|||
twin->x2 = x2;
|
||||
twin->x3 = x3;
|
||||
|
||||
const double square_module = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
|
||||
const double square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
|
||||
|
||||
if (1.0 - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
||||
if (1.0 - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
||||
return;
|
||||
}
|
||||
|
||||
__bg_fp64_versor_normalize(square_module, twin);
|
||||
__bg_fp64_versor_normalize(square_modulus, twin);
|
||||
}
|
||||
|
||||
// ==================== Copy ==================== //
|
||||
|
@ -150,6 +150,30 @@ static inline void bg_fp64_versor_set_rotation(const BgFP64Rotation3* rotation,
|
|||
bg_fp64_versor_set_crude_turn(rotation->axis.x1, rotation->axis.x2, rotation->axis.x3, rotation->radians, BG_ANGLE_UNIT_RADIANS, result);
|
||||
}
|
||||
|
||||
// =============== Square modulus =============== //
|
||||
|
||||
static inline int bg_fp32_versor_get_square_modulus(const BgFP32Versor* versor)
|
||||
{
|
||||
return (versor->s0 * versor->s0 + versor->x1 * versor->x1) + (versor->x2 * versor->x2 + versor->x3 * versor->x3);
|
||||
}
|
||||
|
||||
static inline int bg_fp64_versor_get_square_modulus(const BgFP64Versor* versor)
|
||||
{
|
||||
return (versor->s0 * versor->s0 + versor->x1 * versor->x1) + (versor->x2 * versor->x2 + versor->x3 * versor->x3);
|
||||
}
|
||||
|
||||
// =================== Modulus ================== //
|
||||
|
||||
static inline int bg_fp32_versor_get_modulus(const BgFP32Versor* versor)
|
||||
{
|
||||
return sqrtf(bg_fp32_versor_get_square_modulus(versor));
|
||||
}
|
||||
|
||||
static inline int bg_fp64_versor_get_modulus(const BgFP64Versor* versor)
|
||||
{
|
||||
return sqrt(bg_fp64_versor_get_square_modulus(versor));
|
||||
}
|
||||
|
||||
// ================= Comparison ================= //
|
||||
|
||||
static inline int bg_fp32_versor_is_idle(const BgFP32Versor* versor)
|
||||
|
@ -257,7 +281,7 @@ static inline void bg_fp32_versor_combine(const BgFP32Versor* second, const BgFP
|
|||
const float x2 = (second->x2 * first->s0 + second->s0 * first->x2) - (second->x1 * first->x3 - second->x3 * first->x1);
|
||||
const float x3 = (second->x3 * first->s0 + second->s0 * first->x3) - (second->x2 * first->x1 - second->x1 * first->x2);
|
||||
|
||||
const float square_module = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
|
||||
const float square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
|
||||
|
||||
__BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)result;
|
||||
|
||||
|
@ -266,11 +290,11 @@ static inline void bg_fp32_versor_combine(const BgFP32Versor* second, const BgFP
|
|||
twin->x2 = x2;
|
||||
twin->x3 = x3;
|
||||
|
||||
if (1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
||||
if (1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
||||
return;
|
||||
}
|
||||
|
||||
__bg_fp32_versor_normalize(square_module, twin);
|
||||
__bg_fp32_versor_normalize(square_modulus, twin);
|
||||
}
|
||||
|
||||
static inline void bg_fp64_versor_combine(const BgFP64Versor* second, const BgFP64Versor* first, BgFP64Versor* result)
|
||||
|
@ -280,7 +304,7 @@ static inline void bg_fp64_versor_combine(const BgFP64Versor* second, const BgFP
|
|||
const double x2 = (second->x2 * first->s0 + second->s0 * first->x2) - (second->x1 * first->x3 - second->x3 * first->x1);
|
||||
const double x3 = (second->x3 * first->s0 + second->s0 * first->x3) - (second->x2 * first->x1 - second->x1 * first->x2);
|
||||
|
||||
const double square_module = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
|
||||
const double square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
|
||||
|
||||
__BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)result;
|
||||
|
||||
|
@ -289,11 +313,11 @@ static inline void bg_fp64_versor_combine(const BgFP64Versor* second, const BgFP
|
|||
twin->x2 = x2;
|
||||
twin->x3 = x3;
|
||||
|
||||
if (1.0 - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
||||
if (1.0 - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
||||
return;
|
||||
}
|
||||
|
||||
__bg_fp64_versor_normalize(square_module, twin);
|
||||
__bg_fp64_versor_normalize(square_modulus, twin);
|
||||
}
|
||||
|
||||
// ================= Rotation3 ================== //
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue