Развитие SLERP для трёхмерных пространств, а также развитие дуальных чисел, векторов и кватернионов

This commit is contained in:
Andrey Pokidov 2026-02-13 20:34:11 +07:00
parent 053af33444
commit 86ea23de7d
23 changed files with 1063 additions and 830 deletions

View file

@ -0,0 +1,211 @@
#ifndef _BGC_HG_VECTOR3_H_INCLUDED_
#define _BGC_HG_VECTOR3_H_INCLUDED_
#include "./types.h"
#include "./utilities.h"
// ================ Reset Point ================= //
inline void bgc_fp32_hg_vector3_reset_point(BGC_FP32_HmgVector3* homogeneous_vector)
{
homogeneous_vector->x1 = 0.0f;
homogeneous_vector->x2 = 0.0f;
homogeneous_vector->x3 = 0.0f;
homogeneous_vector->d0 = 1.0f;
}
inline void bgc_fp64_hg_vector3_reset_point(BGC_FP64_HmgVector3* homogeneous_vector)
{
homogeneous_vector->x1 = 0.0;
homogeneous_vector->x2 = 0.0;
homogeneous_vector->x3 = 0.0;
homogeneous_vector->d0 = 1.0;
}
// ================ Reset Point ================= //
inline void bgc_fp32_hg_vector3_reset_vector(BGC_FP32_HmgVector3* homogeneous_vector)
{
homogeneous_vector->x1 = 0.0f;
homogeneous_vector->x2 = 0.0f;
homogeneous_vector->x3 = 0.0f;
homogeneous_vector->d0 = 0.0f;
}
inline void bgc_fp64_hg_vector3_reset_vector(BGC_FP64_HmgVector3* homogeneous_vector)
{
homogeneous_vector->x1 = 0.0;
homogeneous_vector->x2 = 0.0;
homogeneous_vector->x3 = 0.0;
homogeneous_vector->d0 = 0.0;
}
// ==================== Make ==================== //
inline void bgc_fp32_hg_vector3_make(BGC_FP32_HmgVector3* homogeneous_vector, const float x1, const float x2, const float x3, const float d0)
{
homogeneous_vector->x1 = x1;
homogeneous_vector->x2 = x2;
homogeneous_vector->x3 = x3;
homogeneous_vector->d0 = d0;
}
inline void bgc_fp64_hg_vector3_make(BGC_FP64_HmgVector3* homogeneous_vector, const double x1, const double x2, const double x3, const double d0)
{
homogeneous_vector->x1 = x1;
homogeneous_vector->x2 = x2;
homogeneous_vector->x3 = x3;
homogeneous_vector->d0 = d0;
}
// ================= Make Point ================= //
inline void bgc_fp32_hg_vector3_make_point(BGC_FP32_HmgVector3* homogeneous_vector, const BGC_FP32_Vector3* regular_vector)
{
homogeneous_vector->x1 = regular_vector->x1;
homogeneous_vector->x2 = regular_vector->x2;
homogeneous_vector->x3 = regular_vector->x3;
homogeneous_vector->d0 = 1.0f;
}
inline void bgc_fp64_hg_vector3_make_point(BGC_FP64_HmgVector3* homogeneous_vector, const BGC_FP64_Vector3* regular_vector)
{
homogeneous_vector->x1 = regular_vector->x1;
homogeneous_vector->x2 = regular_vector->x2;
homogeneous_vector->x3 = regular_vector->x3;
homogeneous_vector->d0 = 1.0;
}
// ================ Make Vector ================= //
inline void bgc_fp32_hg_vector3_make_vector(BGC_FP32_HmgVector3* homogeneous_vector, const BGC_FP32_Vector3* regular_vector)
{
homogeneous_vector->x1 = regular_vector->x1;
homogeneous_vector->x2 = regular_vector->x2;
homogeneous_vector->x3 = regular_vector->x3;
homogeneous_vector->d0 = 0.0f;
}
inline void bgc_fp64_hg_vector3_make_vector(BGC_FP64_HmgVector3* homogeneous_vector, const BGC_FP64_Vector3* regular_vector)
{
homogeneous_vector->x1 = regular_vector->x1;
homogeneous_vector->x2 = regular_vector->x2;
homogeneous_vector->x3 = regular_vector->x3;
homogeneous_vector->d0 = 0.0;
}
// ================== Is Point ================== //
inline int bgc_fp32_hg_vector3_is_point(const BGC_FP32_HmgVector3* homogeneous_vector)
{
return !bgc_fp32_is_zero(homogeneous_vector->d0);
}
inline int bgc_fp64_hg_vector3_is_point(const BGC_FP64_HmgVector3* homogeneous_vector)
{
return !bgc_fp64_is_zero(homogeneous_vector->d0);
}
// ================= Is Vector ================== //
inline int bgc_fp32_hg_vector3_is_vector(const BGC_FP32_HmgVector3* homogeneous_vector)
{
return bgc_fp32_is_zero(homogeneous_vector->d0);
}
inline int bgc_fp64_hg_vector3_is_vector(const BGC_FP64_HmgVector3* homogeneous_vector)
{
return bgc_fp64_is_zero(homogeneous_vector->d0);
}
// ==================== Copy ==================== //
inline void bgc_fp32_hg_vector3_copy(BGC_FP32_HmgVector3* destination, const BGC_FP32_HmgVector3* source)
{
destination->x1 = source->x1;
destination->x2 = source->x2;
destination->x3 = source->x3;
destination->d0 = source->d0;
}
inline void bgc_fp64_hg_vector3_copy(BGC_FP64_HmgVector3* destination, const BGC_FP64_HmgVector3* source)
{
destination->x1 = source->x1;
destination->x2 = source->x2;
destination->x3 = source->x3;
destination->d0 = source->d0;
}
// ==================== Swap ==================== //
inline void bgc_fp32_hg_vector3_swap(BGC_FP32_HmgVector3* first, BGC_FP32_HmgVector3* second)
{
const float x1 = first->x1;
const float x2 = first->x2;
const float x3 = first->x3;
const float d0 = first->d0;
first->x1 = second->x1;
first->x2 = second->x2;
first->x3 = second->x3;
first->d0 = second->d0;
second->x1 = x1;
second->x2 = x2;
second->x3 = x3;
second->d0 = d0;
}
inline void bgc_fp64_hg_vector3_swap(BGC_FP64_HmgVector3* first, BGC_FP64_HmgVector3* second)
{
const double x1 = first->x1;
const double x2 = first->x2;
const double x3 = first->x3;
const double d0 = first->d0;
first->x1 = second->x1;
first->x2 = second->x2;
first->x3 = second->x3;
first->d0 = second->d0;
second->x1 = x1;
second->x2 = x2;
second->x3 = x3;
second->d0 = d0;
}
// ================== Rescale =================== //
inline int bgc_fp32_hg_vector3_rescale(BGC_FP32_HmgVector3* homogeneous_vector, const float new_ratio)
{
if (bgc_fp32_is_zero(homogeneous_vector->d0)) {
return BGC_FAILURE;
}
const float multiplier = new_ratio / homogeneous_vector->d0;
homogeneous_vector->x1 *= multiplier;
homogeneous_vector->x2 *= multiplier;
homogeneous_vector->x3 *= multiplier;
homogeneous_vector->d0 = new_ratio;
return BGC_SUCCESS;
}
inline int bgc_fp64_hg_vector3_rescale(BGC_FP64_HmgVector3* homogeneous_vector, const double new_ratio)
{
if (bgc_fp64_is_zero(homogeneous_vector->d0)) {
return BGC_FAILURE;
}
const double multiplier = new_ratio / homogeneous_vector->d0;
homogeneous_vector->x1 *= multiplier;
homogeneous_vector->x2 *= multiplier;
homogeneous_vector->x3 *= multiplier;
homogeneous_vector->d0 = new_ratio;
return BGC_SUCCESS;
}
#endif