Рефакторинг и оптимизация вычислений / Refactoring and optimization of computations
This commit is contained in:
parent
03e390c1d0
commit
2655e43cb4
15 changed files with 810 additions and 829 deletions
|
@ -181,6 +181,12 @@ static inline double bg_fp64_quaternion_get_modulus(const BgFP64Quaternion* quat
|
|||
return sqrt(bg_fp64_quaternion_get_square_modulus(quaternion));
|
||||
}
|
||||
|
||||
// =============== Normalization ================ //
|
||||
|
||||
int bg_fp32_quaternion_normalize(BgFP32Quaternion* quaternion);
|
||||
|
||||
int bg_fp64_quaternion_normalize(BgFP64Quaternion* quaternion);
|
||||
|
||||
// ============ Make Rotation Matrix ============ //
|
||||
|
||||
void bg_fp32_quaternion_get_rotation_matrix(const BgFP32Quaternion* quaternion, BgFP32Matrix3x3* matrix);
|
||||
|
@ -213,48 +219,56 @@ static inline void bg_fp64_quaternion_add(const BgFP64Quaternion * quaternion1,
|
|||
|
||||
// ================== Subtract ================== //
|
||||
|
||||
static inline void bg_fp32_quaternion_subtract(const BgFP32Quaternion * minuend, const BgFP32Quaternion * subtrahend, BgFP32Quaternion * result)
|
||||
static inline void bg_fp32_quaternion_subtract(const BgFP32Quaternion * minuend, const BgFP32Quaternion * subtrahend, BgFP32Quaternion * difference)
|
||||
{
|
||||
result->s0 = minuend->s0 - subtrahend->s0;
|
||||
result->x1 = minuend->x1 - subtrahend->x1;
|
||||
result->x2 = minuend->x2 - subtrahend->x2;
|
||||
result->x3 = minuend->x3 - subtrahend->x3;
|
||||
difference->s0 = minuend->s0 - subtrahend->s0;
|
||||
difference->x1 = minuend->x1 - subtrahend->x1;
|
||||
difference->x2 = minuend->x2 - subtrahend->x2;
|
||||
difference->x3 = minuend->x3 - subtrahend->x3;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_quaternion_subtract(const BgFP64Quaternion * minuend, const BgFP64Quaternion * subtrahend, BgFP64Quaternion * result)
|
||||
static inline void bg_fp64_quaternion_subtract(const BgFP64Quaternion * minuend, const BgFP64Quaternion * subtrahend, BgFP64Quaternion * difference)
|
||||
{
|
||||
result->s0 = minuend->s0 - subtrahend->s0;
|
||||
result->x1 = minuend->x1 - subtrahend->x1;
|
||||
result->x2 = minuend->x2 - subtrahend->x2;
|
||||
result->x3 = minuend->x3 - subtrahend->x3;
|
||||
difference->s0 = minuend->s0 - subtrahend->s0;
|
||||
difference->x1 = minuend->x1 - subtrahend->x1;
|
||||
difference->x2 = minuend->x2 - subtrahend->x2;
|
||||
difference->x3 = minuend->x3 - subtrahend->x3;
|
||||
}
|
||||
|
||||
// =============== Multiplication =============== //
|
||||
|
||||
static inline void bg_fp32_quaternion_multiply(const BgFP32Quaternion* left, const BgFP32Quaternion* right, BgFP32Quaternion* result)
|
||||
static inline void bg_fp32_quaternion_multiply(const BgFP32Quaternion* multiplicand, const float multipier, BgFP32Quaternion* product)
|
||||
{
|
||||
const float s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3);
|
||||
const float x1 = (left->x1 * right->s0 + left->s0 * right->x1) - (left->x3 * right->x2 - left->x2 * right->x3);
|
||||
const float x2 = (left->x2 * right->s0 + left->s0 * right->x2) - (left->x1 * right->x3 - left->x3 * right->x1);
|
||||
const float x3 = (left->x3 * right->s0 + left->s0 * right->x3) - (left->x2 * right->x1 - left->x1 * right->x2);
|
||||
|
||||
result->s0 = s0;
|
||||
result->x1 = x1;
|
||||
result->x2 = x2;
|
||||
result->x3 = x3;
|
||||
product->s0 = multiplicand->s0 * multipier;
|
||||
product->x1 = multiplicand->x1 * multipier;
|
||||
product->x2 = multiplicand->x2 * multipier;
|
||||
product->x3 = multiplicand->x3 * multipier;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_quaternion_multiply(const BgFP64Quaternion* left, const BgFP64Quaternion* right, BgFP64Quaternion* result)
|
||||
static inline void bg_fp64_quaternion_multiply(const BgFP64Quaternion* multiplicand, const double multipier, BgFP64Quaternion* product)
|
||||
{
|
||||
const double s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3);
|
||||
const double x1 = (left->x1 * right->s0 + left->s0 * right->x1) - (left->x3 * right->x2 - left->x2 * right->x3);
|
||||
const double x2 = (left->x2 * right->s0 + left->s0 * right->x2) - (left->x1 * right->x3 - left->x3 * right->x1);
|
||||
const double x3 = (left->x3 * right->s0 + left->s0 * right->x3) - (left->x2 * right->x1 - left->x1 * right->x2);
|
||||
|
||||
result->s0 = s0;
|
||||
result->x1 = x1;
|
||||
result->x2 = x2;
|
||||
result->x3 = x3;
|
||||
product->s0 = multiplicand->s0 * multipier;
|
||||
product->x1 = multiplicand->x1 * multipier;
|
||||
product->x2 = multiplicand->x2 * multipier;
|
||||
product->x3 = multiplicand->x3 * multipier;
|
||||
}
|
||||
|
||||
// ================== Division ================== //
|
||||
|
||||
static inline void bg_fp32_quaternion_divide(const BgFP32Quaternion* dividend, const float divisor, BgFP32Quaternion* quotient)
|
||||
{
|
||||
bg_fp32_quaternion_multiply(dividend, 1.0f / divisor, quotient);
|
||||
}
|
||||
|
||||
static inline void bg_fp64_quaternion_divide(const BgFP64Quaternion* dividend, const double divisor, BgFP64Quaternion* quotient)
|
||||
{
|
||||
bg_fp64_quaternion_multiply(dividend, 1.0 / divisor, quotient);
|
||||
}
|
||||
|
||||
// ================== Product =================== //
|
||||
|
||||
void bg_fp32_quaternion_get_product(const BgFP32Quaternion* left, const BgFP32Quaternion* right, BgFP32Quaternion* product);
|
||||
|
||||
void bg_fp64_quaternion_get_product(const BgFP64Quaternion* left, const BgFP64Quaternion* right, BgFP64Quaternion* product);
|
||||
|
||||
#endif // _GEOMETRY_QUATERNION_H_
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue