some progress

This commit is contained in:
veclavtlica
2026-10-07 11:21:21 +03:00
parent 14062e9d00
commit 8d502173a2
26 changed files with 705 additions and 212 deletions
+7 -10
View File
@@ -12,7 +12,7 @@
#include <stdint.h>
typedef struct {
com_def_alignedas(16) com_def_vector(com_fix_t, a, 3);
com_def_alignedas(16) com_def_vector(com_fix_t, a, 4 * sizeof(com_fix_t));
} com_vec_t;
static inline com_vec_t com_vec_from(com_fix_t x, com_fix_t y, com_fix_t z) {
@@ -63,20 +63,17 @@ static inline com_vec_t com_vec_scl(com_vec_t a, com_fix_t b) {
/* Resulted range depends on input, it's in -1 to 1 for normalized
* input and otherwise is -ab to +ab */
static inline com_fix_t com_vec_dot(com_vec_t a, com_vec_t b) {
return (((int64_t)a.a[0] * b.a[0]) + ((int64_t)a.a[1] * b.a[1]) +
((int64_t)a.a[2] * b.a[2])) >>
COM_FIX_FRACBITS;
return ((com_fix_mul(a.a[0], b.a[0])) + (com_fix_mul(a.a[1], b.a[1])) +
(com_fix_mul(a.a[2], b.a[2])));
}
/* Cross product produces a perpendicular for normalized vectors, or 0 for
* parallel vectors */
static inline com_vec_t com_vec_crs(com_vec_t a, com_vec_t b) {
int64_t const cx = ((int64_t)a.a[1] * b.a[2]) - ((int64_t)a.a[2] - b.a[1]);
int64_t const cy = ((int64_t)a.a[2] * b.a[0]) - ((int64_t)a.a[0] - b.a[2]);
int64_t const cz = ((int64_t)a.a[0] * b.a[1]) - ((int64_t)a.a[1] - b.a[0]);
return (com_vec_t){.a = {(com_fix_t)(cx >> COM_FIX_FRACBITS),
(com_fix_t)(cy >> COM_FIX_FRACBITS),
(com_fix_t)(cz >> COM_FIX_FRACBITS)}};
return (com_vec_t){
.a = {(com_fix_mul(a.a[1], b.a[2])) - (com_fix_mul(a.a[2], b.a[1])),
(com_fix_mul(a.a[2], b.a[0])) - (com_fix_mul(a.a[0], b.a[2])),
(com_fix_mul(a.a[0], b.a[1])) - (com_fix_mul(a.a[1], b.a[0]))}};
}
/* Normalize vector, making it a unit one (of length 1). */