Небольшие исправления, а также добавление гомогенного трёхмерного вектора
This commit is contained in:
parent
03627f4401
commit
043cc72c81
25 changed files with 1686 additions and 1644 deletions
|
|
@ -9,54 +9,54 @@
|
|||
|
||||
inline void bgc_fp32_matrix2x2_reset(BGC_FP32_Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = 0.0f;
|
||||
matrix->r1c2 = 0.0f;
|
||||
matrix->r2c1 = 0.0f;
|
||||
matrix->r2c2 = 0.0f;
|
||||
matrix->row1_col1 = 0.0f;
|
||||
matrix->row1_col2 = 0.0f;
|
||||
matrix->row2_col1 = 0.0f;
|
||||
matrix->row2_col2 = 0.0f;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_matrix2x2_reset(BGC_FP64_Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = 0.0;
|
||||
matrix->r1c2 = 0.0;
|
||||
matrix->r2c1 = 0.0;
|
||||
matrix->r2c2 = 0.0;
|
||||
matrix->row1_col1 = 0.0;
|
||||
matrix->row1_col2 = 0.0;
|
||||
matrix->row2_col1 = 0.0;
|
||||
matrix->row2_col2 = 0.0;
|
||||
}
|
||||
|
||||
// ================== Identity ================== //
|
||||
|
||||
inline void bgc_fp32_matrix2x2_make_identity(BGC_FP32_Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = 1.0f;
|
||||
matrix->r1c2 = 0.0f;
|
||||
matrix->r2c1 = 0.0f;
|
||||
matrix->r2c2 = 1.0f;
|
||||
matrix->row1_col1 = 1.0f;
|
||||
matrix->row1_col2 = 0.0f;
|
||||
matrix->row2_col1 = 0.0f;
|
||||
matrix->row2_col2 = 1.0f;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_matrix2x2_make_identity(BGC_FP64_Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = 1.0;
|
||||
matrix->r1c2 = 0.0;
|
||||
matrix->r2c1 = 0.0;
|
||||
matrix->r2c2 = 1.0;
|
||||
matrix->row1_col1 = 1.0;
|
||||
matrix->row1_col2 = 0.0;
|
||||
matrix->row2_col1 = 0.0;
|
||||
matrix->row2_col2 = 1.0;
|
||||
}
|
||||
|
||||
// ================ Set Diagonal ================ //
|
||||
|
||||
inline void bgc_fp32_matrix2x2_make_diagonal(BGC_FP32_Matrix2x2* matrix, const float d1, const float d2)
|
||||
{
|
||||
matrix->r1c1 = d1;
|
||||
matrix->r1c2 = 0.0f;
|
||||
matrix->r2c1 = 0.0f;
|
||||
matrix->r2c2 = d2;
|
||||
matrix->row1_col1 = d1;
|
||||
matrix->row1_col2 = 0.0f;
|
||||
matrix->row2_col1 = 0.0f;
|
||||
matrix->row2_col2 = d2;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_matrix2x2_make_diagonal(BGC_FP64_Matrix2x2* matrix, const double d1, const double d2)
|
||||
{
|
||||
matrix->r1c1 = d1;
|
||||
matrix->r1c2 = 0.0;
|
||||
matrix->r2c1 = 0.0;
|
||||
matrix->r2c2 = d2;
|
||||
matrix->row1_col1 = d1;
|
||||
matrix->row1_col2 = 0.0;
|
||||
matrix->row2_col1 = 0.0;
|
||||
matrix->row2_col2 = d2;
|
||||
}
|
||||
|
||||
// ============== Rotation Matrix =============== //
|
||||
|
|
@ -67,10 +67,10 @@ inline void bgc_fp32_matrix2x2_make_for_turn(BGC_FP32_Matrix2x2* matrix, const f
|
|||
const float cosine = cosf(radians);
|
||||
const float sine = sinf(radians);
|
||||
|
||||
matrix->r1c1 = cosine;
|
||||
matrix->r1c2 = -sine;
|
||||
matrix->r2c1 = sine;
|
||||
matrix->r2c2 = cosine;
|
||||
matrix->row1_col1 = cosine;
|
||||
matrix->row1_col2 = -sine;
|
||||
matrix->row2_col1 = sine;
|
||||
matrix->row2_col2 = cosine;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_matrix2x2_make_for_turn(BGC_FP64_Matrix2x2* matrix, const double angle, const int angle_unit)
|
||||
|
|
@ -79,36 +79,36 @@ inline void bgc_fp64_matrix2x2_make_for_turn(BGC_FP64_Matrix2x2* matrix, const d
|
|||
const double cosine = cos(radians);
|
||||
const double sine = sin(radians);
|
||||
|
||||
matrix->r1c1 = cosine;
|
||||
matrix->r1c2 = -sine;
|
||||
matrix->r2c1 = sine;
|
||||
matrix->r2c2 = cosine;
|
||||
matrix->row1_col1 = cosine;
|
||||
matrix->row1_col2 = -sine;
|
||||
matrix->row2_col1 = sine;
|
||||
matrix->row2_col2 = cosine;
|
||||
}
|
||||
|
||||
// ================ Determinant ================= //
|
||||
|
||||
inline float bgc_fp32_matrix2x2_get_determinant(const BGC_FP32_Matrix2x2* matrix)
|
||||
{
|
||||
return matrix->r1c1 * matrix->r2c2 - matrix->r1c2 * matrix->r2c1;
|
||||
return matrix->row1_col1 * matrix->row2_col2 - matrix->row1_col2 * matrix->row2_col1;
|
||||
}
|
||||
|
||||
inline double bgc_fp64_matrix2x2_get_determinant(const BGC_FP64_Matrix2x2* matrix)
|
||||
{
|
||||
return matrix->r1c1 * matrix->r2c2 - matrix->r1c2 * matrix->r2c1;
|
||||
return matrix->row1_col1 * matrix->row2_col2 - matrix->row1_col2 * matrix->row2_col1;
|
||||
}
|
||||
|
||||
// ================ Is Identity ================= //
|
||||
|
||||
inline int bgc_fp32_matrix2x2_is_identity(const BGC_FP32_Matrix2x2* matrix)
|
||||
{
|
||||
return bgc_fp32_is_unit(matrix->r1c1) && bgc_fp32_is_zero(matrix->r1c2)
|
||||
&& bgc_fp32_is_zero(matrix->r2c1) && bgc_fp32_is_unit(matrix->r2c2);
|
||||
return bgc_fp32_is_unit(matrix->row1_col1) && bgc_fp32_is_zero(matrix->row1_col2)
|
||||
&& bgc_fp32_is_zero(matrix->row2_col1) && bgc_fp32_is_unit(matrix->row2_col2);
|
||||
}
|
||||
|
||||
inline int bgc_fp64_matrix2x2_is_identity(const BGC_FP64_Matrix2x2* matrix)
|
||||
{
|
||||
return bgc_fp64_is_unit(matrix->r1c1) && bgc_fp64_is_zero(matrix->r1c2)
|
||||
&& bgc_fp64_is_zero(matrix->r2c1) && bgc_fp64_is_unit(matrix->r2c2);
|
||||
return bgc_fp64_is_unit(matrix->row1_col1) && bgc_fp64_is_zero(matrix->row1_col2)
|
||||
&& bgc_fp64_is_zero(matrix->row2_col1) && bgc_fp64_is_unit(matrix->row2_col2);
|
||||
}
|
||||
|
||||
// ================ Is Singular ================= //
|
||||
|
|
@ -129,11 +129,11 @@ inline int bgc_fp32_matrix2x2_is_rotation(const BGC_FP32_Matrix2x2* matrix)
|
|||
{
|
||||
BGC_FP32_Matrix2x2 product;
|
||||
|
||||
product.r1c1 = matrix->r1c1 * matrix->r1c1 + matrix->r1c2 * matrix->r2c1;
|
||||
product.r1c2 = matrix->r1c1 * matrix->r1c2 + matrix->r1c2 * matrix->r2c2;
|
||||
product.row1_col1 = matrix->row1_col1 * matrix->row1_col1 + matrix->row1_col2 * matrix->row2_col1;
|
||||
product.row1_col2 = matrix->row1_col1 * matrix->row1_col2 + matrix->row1_col2 * matrix->row2_col2;
|
||||
|
||||
product.r2c1 = matrix->r2c1 * matrix->r1c1 + matrix->r2c2 * matrix->r2c1;
|
||||
product.r2c2 = matrix->r2c1 * matrix->r1c2 + matrix->r2c2 * matrix->r2c2;
|
||||
product.row2_col1 = matrix->row2_col1 * matrix->row1_col1 + matrix->row2_col2 * matrix->row2_col1;
|
||||
product.row2_col2 = matrix->row2_col1 * matrix->row1_col2 + matrix->row2_col2 * matrix->row2_col2;
|
||||
|
||||
return bgc_fp32_matrix2x2_is_identity(&product);
|
||||
}
|
||||
|
|
@ -142,11 +142,11 @@ inline int bgc_fp64_matrix2x2_is_rotation(const BGC_FP64_Matrix2x2* matrix)
|
|||
{
|
||||
BGC_FP64_Matrix2x2 product;
|
||||
|
||||
product.r1c1 = matrix->r1c1 * matrix->r1c1 + matrix->r1c2 * matrix->r2c1;
|
||||
product.r1c2 = matrix->r1c1 * matrix->r1c2 + matrix->r1c2 * matrix->r2c2;
|
||||
product.row1_col1 = matrix->row1_col1 * matrix->row1_col1 + matrix->row1_col2 * matrix->row2_col1;
|
||||
product.row1_col2 = matrix->row1_col1 * matrix->row1_col2 + matrix->row1_col2 * matrix->row2_col2;
|
||||
|
||||
product.r2c1 = matrix->r2c1 * matrix->r1c1 + matrix->r2c2 * matrix->r2c1;
|
||||
product.r2c2 = matrix->r2c1 * matrix->r1c2 + matrix->r2c2 * matrix->r2c2;
|
||||
product.row2_col1 = matrix->row2_col1 * matrix->row1_col1 + matrix->row2_col2 * matrix->row2_col1;
|
||||
product.row2_col2 = matrix->row2_col1 * matrix->row1_col2 + matrix->row2_col2 * matrix->row2_col2;
|
||||
|
||||
return bgc_fp64_matrix2x2_is_identity(&product);
|
||||
}
|
||||
|
|
@ -155,84 +155,84 @@ inline int bgc_fp64_matrix2x2_is_rotation(const BGC_FP64_Matrix2x2* matrix)
|
|||
|
||||
inline void bgc_fp32_matrix2x2_copy(BGC_FP32_Matrix2x2* destination, const BGC_FP32_Matrix2x2* source)
|
||||
{
|
||||
destination->r1c1 = source->r1c1;
|
||||
destination->r1c2 = source->r1c2;
|
||||
destination->row1_col1 = source->row1_col1;
|
||||
destination->row1_col2 = source->row1_col2;
|
||||
|
||||
destination->r2c1 = source->r2c1;
|
||||
destination->r2c2 = source->r2c2;
|
||||
destination->row2_col1 = source->row2_col1;
|
||||
destination->row2_col2 = source->row2_col2;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_matrix2x2_copy(BGC_FP64_Matrix2x2* destination, const BGC_FP64_Matrix2x2* source)
|
||||
{
|
||||
destination->r1c1 = source->r1c1;
|
||||
destination->r1c2 = source->r1c2;
|
||||
destination->row1_col1 = source->row1_col1;
|
||||
destination->row1_col2 = source->row1_col2;
|
||||
|
||||
destination->r2c1 = source->r2c1;
|
||||
destination->r2c2 = source->r2c2;
|
||||
destination->row2_col1 = source->row2_col1;
|
||||
destination->row2_col2 = source->row2_col2;
|
||||
}
|
||||
|
||||
// ==================== Swap ==================== //
|
||||
|
||||
inline void bgc_fp32_matrix2x2_swap(BGC_FP32_Matrix2x2* matrix1, BGC_FP32_Matrix2x2* matrix2)
|
||||
{
|
||||
const float r1c1 = matrix2->r1c1;
|
||||
const float r1c2 = matrix2->r1c2;
|
||||
const float row1_col1 = matrix2->row1_col1;
|
||||
const float row1_col2 = matrix2->row1_col2;
|
||||
|
||||
const float r2c1 = matrix2->r2c1;
|
||||
const float r2c2 = matrix2->r2c2;
|
||||
const float row2_col1 = matrix2->row2_col1;
|
||||
const float row2_col2 = matrix2->row2_col2;
|
||||
|
||||
matrix2->r1c1 = matrix1->r1c1;
|
||||
matrix2->r1c2 = matrix1->r1c2;
|
||||
matrix2->row1_col1 = matrix1->row1_col1;
|
||||
matrix2->row1_col2 = matrix1->row1_col2;
|
||||
|
||||
matrix2->r2c1 = matrix1->r2c1;
|
||||
matrix2->r2c2 = matrix1->r2c2;
|
||||
matrix2->row2_col1 = matrix1->row2_col1;
|
||||
matrix2->row2_col2 = matrix1->row2_col2;
|
||||
|
||||
matrix1->r1c1 = r1c1;
|
||||
matrix1->r1c2 = r1c2;
|
||||
matrix1->row1_col1 = row1_col1;
|
||||
matrix1->row1_col2 = row1_col2;
|
||||
|
||||
matrix1->r2c1 = r2c1;
|
||||
matrix1->r2c2 = r2c2;
|
||||
matrix1->row2_col1 = row2_col1;
|
||||
matrix1->row2_col2 = row2_col2;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_matrix2x2_swap(BGC_FP64_Matrix2x2* matrix1, BGC_FP64_Matrix2x2* matrix2)
|
||||
{
|
||||
const double r1c1 = matrix2->r1c1;
|
||||
const double r1c2 = matrix2->r1c2;
|
||||
const double row1_col1 = matrix2->row1_col1;
|
||||
const double row1_col2 = matrix2->row1_col2;
|
||||
|
||||
const double r2c1 = matrix2->r2c1;
|
||||
const double r2c2 = matrix2->r2c2;
|
||||
const double row2_col1 = matrix2->row2_col1;
|
||||
const double row2_col2 = matrix2->row2_col2;
|
||||
|
||||
matrix2->r1c1 = matrix1->r1c1;
|
||||
matrix2->r1c2 = matrix1->r1c2;
|
||||
matrix2->row1_col1 = matrix1->row1_col1;
|
||||
matrix2->row1_col2 = matrix1->row1_col2;
|
||||
|
||||
matrix2->r2c1 = matrix1->r2c1;
|
||||
matrix2->r2c2 = matrix1->r2c2;
|
||||
matrix2->row2_col1 = matrix1->row2_col1;
|
||||
matrix2->row2_col2 = matrix1->row2_col2;
|
||||
|
||||
matrix1->r1c1 = r1c1;
|
||||
matrix1->r1c2 = r1c2;
|
||||
matrix1->row1_col1 = row1_col1;
|
||||
matrix1->row1_col2 = row1_col2;
|
||||
|
||||
matrix1->r2c1 = r2c1;
|
||||
matrix1->r2c2 = r2c2;
|
||||
matrix1->row2_col1 = row2_col1;
|
||||
matrix1->row2_col2 = row2_col2;
|
||||
}
|
||||
|
||||
// ================== Convert =================== //
|
||||
|
||||
inline void bgc_fp64_matrix2x2_convert_to_fp32(BGC_FP32_Matrix2x2* destination, const BGC_FP64_Matrix2x2* source)
|
||||
{
|
||||
destination->r1c1 = (float)source->r1c1;
|
||||
destination->r1c2 = (float)source->r1c2;
|
||||
destination->row1_col1 = (float)source->row1_col1;
|
||||
destination->row1_col2 = (float)source->row1_col2;
|
||||
|
||||
destination->r2c1 = (float)source->r2c1;
|
||||
destination->r2c2 = (float)source->r2c2;
|
||||
destination->row2_col1 = (float)source->row2_col1;
|
||||
destination->row2_col2 = (float)source->row2_col2;
|
||||
}
|
||||
|
||||
inline void bgc_fp32_matrix2x2_convert_to_fp64(BGC_FP64_Matrix2x2* destination, const BGC_FP32_Matrix2x2* source)
|
||||
{
|
||||
destination->r1c1 = source->r1c1;
|
||||
destination->r1c2 = source->r1c2;
|
||||
destination->row1_col1 = source->row1_col1;
|
||||
destination->row1_col2 = source->row1_col2;
|
||||
|
||||
destination->r2c1 = source->r2c1;
|
||||
destination->r2c2 = source->r2c2;
|
||||
destination->row2_col1 = source->row2_col1;
|
||||
destination->row2_col2 = source->row2_col2;
|
||||
}
|
||||
|
||||
// ================ Get Inverse ================= //
|
||||
|
|
@ -245,19 +245,19 @@ inline int bgc_fp32_matrix2x2_get_inverse(BGC_FP32_Matrix2x2* inverse, const BGC
|
|||
return 0;
|
||||
}
|
||||
|
||||
const float r1c1 = matrix->r2c2;
|
||||
const float r1c2 = -matrix->r1c2;
|
||||
const float row1_col1 = matrix->row2_col2;
|
||||
const float row1_col2 = -matrix->row1_col2;
|
||||
|
||||
const float r2c1 = -matrix->r2c1;
|
||||
const float r2c2 = matrix->r1c1;
|
||||
const float row2_col1 = -matrix->row2_col1;
|
||||
const float row2_col2 = matrix->row1_col1;
|
||||
|
||||
const float multiplier = 1.0f / determinant;
|
||||
|
||||
inverse->r1c1 = r1c1 * multiplier;
|
||||
inverse->r1c2 = r1c2 * multiplier;
|
||||
inverse->row1_col1 = row1_col1 * multiplier;
|
||||
inverse->row1_col2 = row1_col2 * multiplier;
|
||||
|
||||
inverse->r2c1 = r2c1 * multiplier;
|
||||
inverse->r2c2 = r2c2 * multiplier;
|
||||
inverse->row2_col1 = row2_col1 * multiplier;
|
||||
inverse->row2_col2 = row2_col2 * multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -270,19 +270,19 @@ inline int bgc_fp64_matrix2x2_get_inverse(BGC_FP64_Matrix2x2* inverse, const BGC
|
|||
return 0;
|
||||
}
|
||||
|
||||
const double r1c1 = matrix->r2c2;
|
||||
const double r1c2 = -matrix->r1c2;
|
||||
const double row1_col1 = matrix->row2_col2;
|
||||
const double row1_col2 = -matrix->row1_col2;
|
||||
|
||||
const double r2c1 = -matrix->r2c1;
|
||||
const double r2c2 = matrix->r1c1;
|
||||
const double row2_col1 = -matrix->row2_col1;
|
||||
const double row2_col2 = matrix->row1_col1;
|
||||
|
||||
const double multiplier = 1.0 / determinant;
|
||||
|
||||
inverse->r1c1 = r1c1 * multiplier;
|
||||
inverse->r1c2 = r1c2 * multiplier;
|
||||