649 lines
19 KiB
C
649 lines
19 KiB
C
#ifndef _GEOMETRY_MATRIX3X3_H_
|
|
#define _GEOMETRY_MATRIX3X3_H_
|
|
|
|
#include "vector3.h"
|
|
#include "matrixes.h"
|
|
|
|
// =================== Reset ==================== //
|
|
|
|
static inline void bg_fp32_matrix3x3_reset(BgFP32Matrix3x3* matrix)
|
|
{
|
|
matrix->r1c1 = 0.0f;
|
|
matrix->r1c2 = 0.0f;
|
|
matrix->r1c3 = 0.0f;
|
|
|
|
matrix->r2c1 = 0.0f;
|
|
matrix->r2c2 = 0.0f;
|
|
matrix->r2c3 = 0.0f;
|
|
|
|
matrix->r3c1 = 0.0f;
|
|
matrix->r3c2 = 0.0f;
|
|
matrix->r3c3 = 0.0f;
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_reset(BgFP64Matrix3x3* matrix)
|
|
{
|
|
matrix->r1c1 = 0.0;
|
|
matrix->r1c2 = 0.0;
|
|
matrix->r1c3 = 0.0;
|
|
|
|
matrix->r2c1 = 0.0;
|
|
matrix->r2c2 = 0.0;
|
|
matrix->r2c3 = 0.0;
|
|
|
|
matrix->r3c1 = 0.0;
|
|
matrix->r3c2 = 0.0;
|
|
matrix->r3c3 = 0.0;
|
|
}
|
|
|
|
// ================== Identity ================== //
|
|
|
|
static inline void bg_fp32_matrix3x3_set_to_identity(BgFP32Matrix3x3* matrix)
|
|
{
|
|
matrix->r1c1 = 1.0f;
|
|
matrix->r1c2 = 0.0f;
|
|
matrix->r1c3 = 0.0f;
|
|
|
|
matrix->r2c1 = 0.0f;
|
|
matrix->r2c2 = 1.0f;
|
|
matrix->r2c3 = 0.0f;
|
|
|
|
matrix->r3c1 = 0.0f;
|
|
matrix->r3c2 = 0.0f;
|
|
matrix->r3c3 = 1.0f;
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_set_to_identity(BgFP64Matrix3x3* matrix)
|
|
{
|
|
matrix->r1c1 = 1.0;
|
|
matrix->r1c2 = 0.0;
|
|
matrix->r1c3 = 0.0;
|
|
|
|
matrix->r2c1 = 0.0;
|
|
matrix->r2c2 = 1.0;
|
|
matrix->r2c3 = 0.0;
|
|
|
|
matrix->r3c1 = 0.0;
|
|
matrix->r3c2 = 0.0;
|
|
matrix->r3c3 = 1.0;
|
|
}
|
|
|
|
// ================ Make Diagonal =============== //
|
|
|
|
static inline void bg_fp32_matrix3x3_set_to_diagonal(const float d1, const float d2, const float d3, BgFP32Matrix3x3* matrix)
|
|
{
|
|
matrix->r1c1 = d1;
|
|
matrix->r1c2 = 0.0f;
|
|
matrix->r1c3 = 0.0f;
|
|
|
|
matrix->r2c1 = 0.0f;
|
|
matrix->r2c2 = d2;
|
|
matrix->r2c3 = 0.0f;
|
|
|
|
matrix->r3c1 = 0.0f;
|
|
matrix->r3c2 = 0.0f;
|
|
matrix->r3c3 = d2;
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_set_to_diagonal(const double d1, const double d2, const double d3, BgFP64Matrix3x3* matrix)
|
|
{
|
|
matrix->r1c1 = d1;
|
|
matrix->r1c2 = 0.0;
|
|
matrix->r1c3 = 0.0;
|
|
|
|
matrix->r2c1 = 0.0;
|
|
matrix->r2c2 = d2;
|
|
matrix->r2c3 = 0.0;
|
|
|
|
matrix->r3c1 = 0.0;
|
|
matrix->r3c2 = 0.0;
|
|
matrix->r3c3 = d2;
|
|
}
|
|
|
|
// ==================== Copy ==================== //
|
|
|
|
static inline void bg_fp32_matrix3x3_copy(const BgFP32Matrix3x3* from, BgFP32Matrix3x3* to)
|
|
{
|
|
to->r1c1 = from->r1c1;
|
|
to->r1c2 = from->r1c2;
|
|
to->r1c3 = from->r1c3;
|
|
|
|
to->r2c1 = from->r2c1;
|
|
to->r2c2 = from->r2c2;
|
|
to->r2c3 = from->r2c3;
|
|
|
|
to->r3c1 = from->r3c1;
|
|
to->r3c2 = from->r3c2;
|
|
to->r3c3 = from->r3c3;
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_copy(const BgFP64Matrix3x3* from, BgFP64Matrix3x3* to)
|
|
{
|
|
to->r1c1 = from->r1c1;
|
|
to->r1c2 = from->r1c2;
|
|
to->r1c3 = from->r1c3;
|
|
|
|
to->r2c1 = from->r2c1;
|
|
to->r2c2 = from->r2c2;
|
|
to->r2c3 = from->r2c3;
|
|
|
|
to->r3c1 = from->r3c1;
|
|
to->r3c2 = from->r3c2;
|
|
to->r3c3 = from->r3c3;
|
|
}
|
|
|
|
// ==================== Swap ==================== //
|
|
|
|
static inline void bg_fp32_matrix3x3_swap(BgFP32Matrix3x3* matrix1, BgFP32Matrix3x3* matrix2)
|
|
{
|
|
const float r1c1 = matrix2->r1c1;
|
|
const float r1c2 = matrix2->r1c2;
|
|
const float r1c3 = matrix2->r1c3;
|
|
|
|
const float r2c1 = matrix2->r2c1;
|
|
const float r2c2 = matrix2->r2c2;
|
|
const float r2c3 = matrix2->r2c3;
|
|
|
|
const float r3c1 = matrix2->r3c1;
|
|
const float r3c2 = matrix2->r3c2;
|
|
const float r3c3 = matrix2->r3c3;
|
|
|
|
matrix2->r1c1 = matrix1->r1c1;
|
|
matrix2->r1c2 = matrix1->r1c2;
|
|
matrix2->r1c3 = matrix1->r1c3;
|
|
|
|
matrix2->r2c1 = matrix1->r2c1;
|
|
matrix2->r2c2 = matrix1->r2c2;
|
|
matrix2->r2c3 = matrix1->r2c3;
|
|
|
|
matrix2->r3c1 = matrix1->r3c1;
|
|
matrix2->r3c2 = matrix1->r3c2;
|
|
matrix2->r3c3 = matrix1->r3c3;
|
|
|
|
matrix1->r1c1 = r1c1;
|
|
matrix1->r1c2 = r1c2;
|
|
matrix1->r1c3 = r1c3;
|
|
|
|
matrix1->r2c1 = r2c1;
|
|
matrix1->r2c2 = r2c2;
|
|
matrix1->r2c3 = r2c3;
|
|
|
|
matrix1->r3c1 = r3c1;
|
|
matrix1->r3c2 = r3c2;
|
|
matrix1->r3c3 = r3c3;
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_swap(BgFP64Matrix3x3* matrix1, BgFP64Matrix3x3* matrix2)
|
|
{
|
|
const double r1c1 = matrix2->r1c1;
|
|
const double r1c2 = matrix2->r1c2;
|
|
const double r1c3 = matrix2->r1c3;
|
|
|
|
const double r2c1 = matrix2->r2c1;
|
|
const double r2c2 = matrix2->r2c2;
|
|
const double r2c3 = matrix2->r2c3;
|
|
|
|
const double r3c1 = matrix2->r3c1;
|
|
const double r3c2 = matrix2->r3c2;
|
|
const double r3c3 = matrix2->r3c3;
|
|
|
|
matrix2->r1c1 = matrix1->r1c1;
|
|
matrix2->r1c2 = matrix1->r1c2;
|
|
matrix2->r1c3 = matrix1->r1c3;
|
|
|
|
matrix2->r2c1 = matrix1->r2c1;
|
|
matrix2->r2c2 = matrix1->r2c2;
|
|
matrix2->r2c3 = matrix1->r2c3;
|
|
|
|
matrix2->r3c1 = matrix1->r3c1;
|
|
matrix2->r3c2 = matrix1->r3c2;
|
|
matrix2->r3c3 = matrix1->r3c3;
|
|
|
|
matrix1->r1c1 = r1c1;
|
|
matrix1->r1c2 = r1c2;
|
|
matrix1->r1c3 = r1c3;
|
|
|
|
matrix1->r2c1 = r2c1;
|
|
matrix1->r2c2 = r2c2;
|
|
matrix1->r2c3 = r2c3;
|
|
|
|
matrix1->r3c1 = r3c1;
|
|
matrix1->r3c2 = r3c2;
|
|
matrix1->r3c3 = r3c3;
|
|
}
|
|
|
|
// ============= Set from twin type ============= //
|
|
|
|
static inline void bg_fp32_matrix3x3_set_from_fp64(const BgFP64Matrix3x3* from, BgFP32Matrix3x3* to)
|
|
{
|
|
to->r1c1 = (float) from->r1c1;
|
|
to->r1c2 = (float) from->r1c2;
|
|
to->r1c3 = (float) from->r1c3;
|
|
|
|
to->r2c1 = (float) from->r2c1;
|
|
to->r2c2 = (float) from->r2c2;
|
|
to->r2c3 = (float) from->r2c3;
|
|
|
|
to->r3c1 = (float) from->r3c1;
|
|
to->r3c2 = (float) from->r3c2;
|
|
to->r3c3 = (float) from->r3c3;
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_set_from_fp32(const BgFP32Matrix3x3* from, BgFP64Matrix3x3* to)
|
|
{
|
|
to->r1c1 = from->r1c1;
|
|
to->r1c2 = from->r1c2;
|
|
to->r1c3 = from->r1c3;
|
|
|
|
to->r2c1 = from->r2c1;
|
|
to->r2c2 = from->r2c2;
|
|
to->r2c3 = from->r2c3;
|
|
|
|
to->r3c1 = from->r3c1;
|
|
to->r3c2 = from->r3c2;
|
|
to->r3c3 = from->r3c3;
|
|
}
|
|
|
|
// ================ Determinant ================= //
|
|
|
|
static inline float bg_fp32_matrix3x3_get_determinant(const BgFP32Matrix3x3* matrix)
|
|
{
|
|
return matrix->r1c1 * (matrix->r2c2 * matrix->r3c3 - matrix->r2c3 * matrix->r3c2)
|
|
+ matrix->r1c2 * (matrix->r2c3 * matrix->r3c1 - matrix->r2c1 * matrix->r3c3)
|
|
+ matrix->r1c3 * (matrix->r2c1 * matrix->r3c2 - matrix->r2c2 * matrix->r3c1);
|
|
}
|
|
|
|
static inline double bg_fp64_matrix3x3_get_determinant(const BgFP64Matrix3x3* matrix)
|
|
{
|
|
return matrix->r1c1 * (matrix->r2c2 * matrix->r3c3 - matrix->r2c3 * matrix->r3c2)
|
|
+ matrix->r1c2 * (matrix->r2c3 * matrix->r3c1 - matrix->r2c1 * matrix->r3c3)
|
|
+ matrix->r1c3 * (matrix->r2c1 * matrix->r3c2 - matrix->r2c2 * matrix->r3c1);
|
|
}
|
|
|
|
// ================== Singular ================== //
|
|
|
|
static inline int bg_fp32_matrix3x3_is_singular(const BgFP32Matrix3x3* matrix)
|
|
{
|
|
const float determinant = bg_fp32_matrix3x3_get_determinant(matrix);
|
|
|
|
return -BG_FP32_EPSYLON <= determinant && determinant <= BG_FP32_EPSYLON;
|
|
}
|
|
|
|
static inline int bg_fp64_matrix3x3_is_singular(const BgFP64Matrix3x3* matrix)
|
|
{
|
|
const double determinant = bg_fp64_matrix3x3_get_determinant(matrix);
|
|
|
|
return -BG_FP64_EPSYLON <= determinant && determinant <= BG_FP64_EPSYLON;
|
|
}
|
|
|
|
// ================= Inversion ================== //
|
|
|
|
int bg_fp32_matrix3x3_invert(BgFP32Matrix3x3* matrix);
|
|
|
|
int bg_fp64_matrix3x3_invert(BgFP64Matrix3x3* matrix);
|
|
|
|
// =============== Transposition ================ //
|
|
|
|
static inline void bg_fp32_matrix3x3_transpose(BgFP32Matrix3x3* matrix)
|
|
{
|
|
float tmp = matrix->r1c2;
|
|
matrix->r1c2 = matrix->r2c1;
|
|
matrix->r2c1 = tmp;
|
|
|
|
tmp = matrix->r1c3;
|
|
matrix->r1c3 = matrix->r3c1;
|
|
matrix->r3c1 = tmp;
|
|
|
|
tmp = matrix->r2c3;
|
|
matrix->r2c3 = matrix->r3c2;
|
|
matrix->r3c2 = tmp;
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_transpose(BgFP64Matrix3x3* matrix)
|
|
{
|
|
double tmp = matrix->r1c2;
|
|
matrix->r1c2 = matrix->r2c1;
|
|
matrix->r2c1 = tmp;
|
|
|
|
tmp = matrix->r1c3;
|
|
matrix->r1c3 = matrix->r3c1;
|
|
matrix->r3c1 = tmp;
|
|
|
|
tmp = matrix->r2c3;
|
|
matrix->r2c3 = matrix->r3c2;
|
|
matrix->r3c2 = tmp;
|
|
}
|
|
|
|
// ================ Make Inverted =============== //
|
|
|
|
int bg_fp32_matrix3x3_set_inverted(const BgFP32Matrix3x3* matrix, BgFP32Matrix3x3* result);
|
|
|
|
int bg_fp64_matrix3x3_set_inverted(const BgFP64Matrix3x3* matrix, BgFP64Matrix3x3* result);
|
|
|
|
// =============== Make Transposed ============== //
|
|
|
|
static inline void bg_fp32_matrix3x3_set_transposed(const BgFP32Matrix3x3* matrix, BgFP32Matrix3x3* result)
|
|
{
|
|
if (matrix == result) {
|
|
bg_fp32_matrix3x3_transpose(result);
|
|
return;
|
|
}
|
|
|
|
result->r1c1 = matrix->r1c1;
|
|
result->r1c2 = matrix->r2c1;
|
|
result->r1c3 = matrix->r3c1;
|
|
|
|
result->r2c1 = matrix->r1c2;
|
|
result->r2c2 = matrix->r2c2;
|
|
result->r2c3 = matrix->r3c2;
|
|
|
|
result->r3c1 = matrix->r1c3;
|
|
result->r3c2 = matrix->r2c3;
|
|
result->r3c3 = matrix->r3c3;
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_set_transposed(const BgFP64Matrix3x3* matrix, BgFP64Matrix3x3* result)
|
|
{
|
|
if (matrix == result) {
|
|
bg_fp64_matrix3x3_transpose(result);
|
|
return;
|
|
}
|
|
|
|
result->r1c1 = matrix->r1c1;
|
|
result->r1c2 = matrix->r2c1;
|
|
result->r1c3 = matrix->r3c1;
|
|
|
|
result->r2c1 = matrix->r1c2;
|
|
result->r2c2 = matrix->r2c2;
|
|
result->r2c3 = matrix->r3c2;
|
|
|
|
result->r3c1 = matrix->r1c3;
|
|
result->r3c2 = matrix->r2c3;
|
|
result->r3c3 = matrix->r3c3;
|
|
}
|
|
|
|
// ================= Set Row 1 ================== //
|
|
|
|
static inline void bg_fp32_matrix3x3_set_row1(const float c1, const float c2, const float c3, BgFP32Matrix3x3* matrix)
|
|
{
|
|
matrix->r1c1 = c1;
|
|
matrix->r1c2 = c2;
|
|
matrix->r1c3 = c3;
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_set_row1(const double c1, const double c2, const double c3, BgFP64Matrix3x3* matrix)
|
|
{
|
|
matrix->r1c1 = c1;
|
|
matrix->r1c2 = c2;
|
|
matrix->r1c3 = c3;
|
|
}
|
|
|
|
// ================= Set Row 2 ================== //
|
|
|
|
static inline void bg_fp32_matrix3x3_set_row2(const float c1, const float c2, const float c3, BgFP32Matrix3x3* matrix)
|
|
{
|
|
matrix->r2c1 = c1;
|
|
matrix->r2c2 = c2;
|
|
matrix->r2c3 = c3;
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_set_row2(const double c1, const double c2, const double c3, BgFP64Matrix3x3* matrix)
|
|
{
|
|
matrix->r2c1 = c1;
|
|
matrix->r2c2 = c2;
|
|
matrix->r2c3 = c3;
|
|
}
|
|
|
|
// ================= Set Row 3 ================== //
|
|
|
|
static inline void bg_fp32_matrix3x3_set_row3(const float c1, const float c2, const float c3, BgFP32Matrix3x3* matrix)
|
|
{
|
|
matrix->r3c1 = c1;
|
|
matrix->r3c2 = c2;
|
|
matrix->r3c3 = c3;
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_set_row3(const double c1, const double c2, const double c3, BgFP64Matrix3x3* matrix)
|
|
{
|
|
matrix->r3c1 = c1;
|
|
matrix->r3c2 = c2;
|
|
matrix->r3c3 = c3;
|
|
}
|
|
|
|
// ================ Set Column 1 ================ //
|
|
|
|
static inline void bg_fp32_matrix3x3_set_column1(const float r1, const float r2, const float r3, BgFP32Matrix3x3* matrix)
|
|
{
|
|
matrix->r1c1 = r1;
|
|
matrix->r2c1 = r2;
|
|
matrix->r3c1 = r3;
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_set_column1(const double r1, const double r2, const double r3, BgFP64Matrix3x3* matrix)
|
|
{
|
|
matrix->r1c1 = r1;
|
|
matrix->r2c1 = r2;
|
|
matrix->r3c1 = r3;
|
|
}
|
|
|
|
// ================ Set Column 2 ================ //
|
|
|
|
static inline void bg_fp32_matrix3x3_set_column2(const float r1, const float r2, const float r3, BgFP32Matrix3x3* matrix)
|
|
{
|
|
matrix->r1c2 = r1;
|
|
matrix->r2c2 = r2;
|
|
matrix->r3c2 = r3;
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_set_column2(const double r1, const double r2, const double r3, BgFP64Matrix3x3* matrix)
|
|
{
|
|
matrix->r1c2 = r1;
|
|
matrix->r2c2 = r2;
|
|
matrix->r3c2 = r3;
|
|
}
|
|
|
|
// ================ Set Column 3 ================ //
|
|
|
|
static inline void bg_fp32_matrix3x3_set_column3(const float r1, const float r2, const float r3, BgFP32Matrix3x3* matrix)
|
|
{
|
|
matrix->r1c3 = r1;
|
|
matrix->r2c3 = r2;
|
|
matrix->r3c3 = r3;
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_set_column3(const double r1, const double r2, const double r3, BgFP64Matrix3x3* matrix)
|
|
{
|
|
matrix->r1c3 = r1;
|
|
matrix->r2c3 = r2;
|
|
matrix->r3c3 = r3;
|
|
}
|
|
|
|
// ================ Append scaled =============== //
|
|
|
|
static inline void bg_fp32_matrix3x3_append_scaled(BgFP32Matrix3x3* basic_vector, const BgFP32Matrix3x3* scalable_vector, const float scale)
|
|
{
|
|
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
|
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
|
basic_vector->r1c3 += scalable_vector->r1c3 * scale;
|
|
|
|
basic_vector->r2c1 += scalable_vector->r2c1 * scale;
|
|
basic_vector->r2c2 += scalable_vector->r2c2 * scale;
|
|
basic_vector->r2c3 += scalable_vector->r2c3 * scale;
|
|
|
|
basic_vector->r3c1 += scalable_vector->r3c1 * scale;
|
|
basic_vector->r3c2 += scalable_vector->r3c2 * scale;
|
|
basic_vector->r3c3 += scalable_vector->r3c3 * scale;
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_append_scaled(BgFP64Matrix3x3* basic_vector, const BgFP64Matrix3x3* scalable_vector, const double scale)
|
|
{
|
|
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
|
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
|
basic_vector->r1c3 += scalable_vector->r1c3 * scale;
|
|
|
|
basic_vector->r2c1 += scalable_vector->r2c1 * scale;
|
|
basic_vector->r2c2 += scalable_vector->r2c2 * scale;
|
|
basic_vector->r2c3 += scalable_vector->r2c3 * scale;
|
|
|
|
basic_vector->r3c1 += scalable_vector->r3c1 * scale;
|
|
basic_vector->r3c2 += scalable_vector->r3c2 * scale;
|
|
basic_vector->r3c3 += scalable_vector->r3c3 * scale;
|
|
}
|
|
|
|
// ================== Addition ================== //
|
|
|
|
static inline void bg_fp32_matrix3x3_add(const BgFP32Matrix3x3* matrix1, const BgFP32Matrix3x3* matrix2, BgFP32Matrix3x3* sum)
|
|
{
|
|
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
|
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
|
sum->r1c3 = matrix1->r1c3 + matrix2->r1c3;
|
|
|
|
sum->r2c1 = matrix1->r2c1 + matrix2->r2c1;
|
|
sum->r2c2 = matrix1->r2c2 + matrix2->r2c2;
|
|
sum->r2c3 = matrix1->r2c3 + matrix2->r2c3;
|
|
|
|
sum->r3c1 = matrix1->r3c1 + matrix2->r3c1;
|
|
sum->r3c2 = matrix1->r3c2 + matrix2->r3c2;
|
|
sum->r3c3 = matrix1->r3c3 + matrix2->r3c3;
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_add(const BgFP64Matrix3x3* matrix1, const BgFP64Matrix3x3* matrix2, BgFP64Matrix3x3* sum)
|
|
{
|
|
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
|
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
|
sum->r1c3 = matrix1->r1c3 + matrix2->r1c3;
|
|
|
|
sum->r2c1 = matrix1->r2c1 + matrix2->r2c1;
|
|
sum->r2c2 = matrix1->r2c2 + matrix2->r2c2;
|
|
sum->r2c3 = matrix1->r2c3 + matrix2->r2c3;
|
|
|
|
sum->r3c1 = matrix1->r3c1 + matrix2->r3c1;
|
|
sum->r3c2 = matrix1->r3c2 + matrix2->r3c2;
|
|
sum->r3c3 = matrix1->r3c3 + matrix2->r3c3;
|
|
}
|
|
|
|
// ================ Subtraction ================= //
|
|
|
|
static inline void bg_fp32_matrix3x3_subtract(const BgFP32Matrix3x3* minuend, const BgFP32Matrix3x3* subtrahend, BgFP32Matrix3x3* difference)
|
|
{
|
|
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
|
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
|
difference->r1c3 = minuend->r1c3 - subtrahend->r1c3;
|
|
|
|
difference->r2c1 = minuend->r2c1 - subtrahend->r2c1;
|
|
difference->r2c2 = minuend->r2c2 - subtrahend->r2c2;
|
|
difference->r2c3 = minuend->r2c3 - subtrahend->r2c3;
|
|
|
|
difference->r3c1 = minuend->r3c1 - subtrahend->r3c1;
|
|
difference->r3c2 = minuend->r3c2 - subtrahend->r3c2;
|
|
difference->r3c3 = minuend->r3c3 - subtrahend->r3c3;
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_subtract(const BgFP64Matrix3x3* minuend, const BgFP64Matrix3x3* subtrahend, BgFP64Matrix3x3* difference)
|
|
{
|
|
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
|
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
|
difference->r1c3 = minuend->r1c3 - subtrahend->r1c3;
|
|
|
|
difference->r2c1 = minuend->r2c1 - subtrahend->r2c1;
|
|
difference->r2c2 = minuend->r2c2 - subtrahend->r2c2;
|
|
difference->r2c3 = minuend->r2c3 - subtrahend->r2c3;
|
|
|
|
difference->r3c1 = minuend->r3c1 - subtrahend->r3c1;
|
|
difference->r3c2 = minuend->r3c2 - subtrahend->r3c2;
|
|
difference->r3c3 = minuend->r3c3 - subtrahend->r3c3;
|
|
}
|
|
|
|
// =============== Multiplication =============== //
|
|
|
|
static inline void bg_fp32_matrix3x3_multiply(const BgFP32Matrix3x3* multiplicand, const float multiplier, BgFP32Matrix3x3* product)
|
|
{
|
|
product->r1c1 = multiplicand->r1c1 * multiplier;
|
|
product->r1c2 = multiplicand->r1c2 * multiplier;
|
|
product->r1c3 = multiplicand->r1c3 * multiplier;
|
|
|
|
product->r2c1 = multiplicand->r2c1 * multiplier;
|
|
product->r2c2 = multiplicand->r2c2 * multiplier;
|
|
product->r2c3 = multiplicand->r2c3 * multiplier;
|
|
|
|
product->r3c1 = multiplicand->r3c1 * multiplier;
|
|
product->r3c2 = multiplicand->r3c2 * multiplier;
|
|
product->r3c3 = multiplicand->r3c3 * multiplier;
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_multiply(const BgFP64Matrix3x3* multiplicand, const double multiplier, BgFP64Matrix3x3* product)
|
|
{
|
|
product->r1c1 = multiplicand->r1c1 * multiplier;
|
|
product->r1c2 = multiplicand->r1c2 * multiplier;
|
|
product->r1c3 = multiplicand->r1c3 * multiplier;
|
|
|
|
product->r2c1 = multiplicand->r2c1 * multiplier;
|
|
product->r2c2 = multiplicand->r2c2 * multiplier;
|
|
product->r2c3 = multiplicand->r2c3 * multiplier;
|
|
|
|
product->r3c1 = multiplicand->r3c1 * multiplier;
|
|
product->r3c2 = multiplicand->r3c2 * multiplier;
|
|
product->r3c3 = multiplicand->r3c3 * multiplier;
|
|
}
|
|
|
|
// ================== Division ================== //
|
|
|
|
static inline void bg_fp32_matrix3x3_divide(const BgFP32Matrix3x3* dividend, const float divisor, BgFP32Matrix3x3* quotient)
|
|
{
|
|
bg_fp32_matrix3x3_multiply(dividend, 1.0f / divisor, quotient);
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_divide(const BgFP64Matrix3x3* dividend, const double divisor, BgFP64Matrix3x3* quotient)
|
|
{
|
|
bg_fp64_matrix3x3_multiply(dividend, 1.0 / divisor, quotient);
|
|
}
|
|
|
|
// ============ Left Vector Product ============= //
|
|
|
|
static inline void bg_fp32_matrix3x3_left_product(const BgFP32Vector3* vector, const BgFP32Matrix3x3* matrix, BgFP32Vector3* result)
|
|
{
|
|
const float x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1;
|
|
const float x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2;
|
|
const float x3 = vector->x1 * matrix->r1c3 + vector->x2 * matrix->r2c3 + vector->x3 * matrix->r3c3;
|
|
|
|
result->x1 = x1;
|
|
result->x2 = x2;
|
|
result->x3 = x3;
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_left_product(const BgFP64Vector3* vector, const BgFP64Matrix3x3* matrix, BgFP64Vector3* result)
|
|
{
|
|
const double x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1;
|
|
const double x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2;
|
|
const double x3 = vector->x1 * matrix->r1c3 + vector->x2 * matrix->r2c3 + vector->x3 * matrix->r3c3;
|
|
|
|
result->x1 = x1;
|
|
result->x2 = x2;
|
|
result->x3 = x3;
|
|
}
|
|
|
|
// ============ Right Vector Product ============ //
|
|
|
|
static inline void bg_fp32_matrix3x3_right_product(const BgFP32Matrix3x3* matrix, const BgFP32Vector3* vector, BgFP32Vector3* result)
|
|
{
|
|
const float x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3;
|
|
const float x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3;
|
|
const float x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2 + matrix->r3c3 * vector->x3;
|
|
|
|
result->x1 = x1;
|
|
result->x2 = x2;
|
|
result->x3 = x3;
|
|
}
|
|
|
|
static inline void bg_fp64_matrix3x3_right_product(const BgFP64Matrix3x3* matrix, const BgFP64Vector3* vector, BgFP64Vector3* result)
|
|
{
|
|
const double x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3;
|
|
const double x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3;
|
|
const double x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2 + matrix->r3c3 * vector->x3;
|
|
|
|
result->x1 = x1;
|
|
result->x2 = x2;
|
|
result->x3 = x3;
|
|
}
|
|
|
|
#endif
|