Add seperation between ROTMATRIX and TRANSFERVECTOR

This commit is contained in:
2024-04-02 23:40:22 -05:00
parent 4da6772827
commit 1bf91b2d75
7 changed files with 73 additions and 132 deletions

View File

@@ -30,7 +30,7 @@ namespace JabyEngine {
Sets a 3x3 matrix m as a constant rotation matrix.
matrix: The rotation matrix to set
*/
static void set_rot_matrix(const MATRIX& matrix) {
static void set_rot_matrix(const ROTMATRIX& matrix) {
__asm__ volatile("lw $12, 0(%0)" :: "r"(&matrix) : "$12", "$13", "$14");
__asm__ volatile("lw $13, 4(%0)" :: "r"(&matrix) : "$12", "$13", "$14");
__asm__ volatile("ctc2 $12, $0" :: "r"(&matrix) : "$12", "$13", "$14");
@@ -49,7 +49,7 @@ namespace JabyEngine {
Writes the current 3x3 constant rotation matrix to matrix
(This doesn't require us to use memory clobber)
*/
static void get_rot_matrix(MATRIX &matrix) {
static void get_rot_matrix(ROTMATRIX &matrix) {
__asm__ volatile("cfc2 $12, $0" :: "r"(&matrix) : "$12", "$13", "$14");
__asm__ volatile("cfc2 $13, $1" :: "r"(&matrix) : "$12", "$13", "$14");
__asm__ volatile("sw $12, 0(%0)" :: "r"(&matrix) : "$12", "$13", "$14");
@@ -67,13 +67,13 @@ namespace JabyEngine {
Sets a constant parallel transfer vector specified by m
*/
static void set_trans_matrix(const MATRIX& matrix) {
__asm__ volatile("lw $12, 20(%0)" :: "r"(&matrix) : "$12", "$13", "$14");
__asm__ volatile("lw $13, 24(%0)" :: "r"(&matrix) : "$12", "$13", "$14");
__asm__ volatile("ctc2 $12, $5" :: "r"(&matrix) : "$12", "$13", "$14");
__asm__ volatile("lw $14, 28(%0)" :: "r"(&matrix) : "$12", "$13", "$14");
__asm__ volatile("ctc2 $13, $6" :: "r"(&matrix) : "$12", "$13", "$14");
__asm__ volatile("ctc2 $14, $7" :: "r"(&matrix) : "$12", "$13", "$14");
static void set_trans_vector(const TRANSFERVECTOR& vector) {
__asm__ volatile("lw $12, 0(%0)" :: "r"(&vector) : "$12", "$13", "$14");
__asm__ volatile("lw $13, 4(%0)" :: "r"(&vector) : "$12", "$13", "$14");
__asm__ volatile("ctc2 $12, $5" :: "r"(&vector) : "$12", "$13", "$14");
__asm__ volatile("lw $14, 8(%0)" :: "r"(&vector) : "$12", "$13", "$14");
__asm__ volatile("ctc2 $13, $6" :: "r"(&vector) : "$12", "$13", "$14");
__asm__ volatile("ctc2 $14, $7" :: "r"(&vector) : "$12", "$13", "$14");
}
/*
@@ -82,13 +82,13 @@ namespace JabyEngine {
Writes the current constant parallel transfer vector to matrix
(This doesn't require us to use memory clobber)
*/
static void get_trans_matrix(MATRIX& matrix) {
__asm__ volatile("cfc2 $14, $7" :: "r"(&matrix) : "$12", "$13", "$14");
__asm__ volatile("cfc2 $13, $6" :: "r"(&matrix) : "$12", "$13", "$14");
__asm__ volatile("sw $14, 28(%0)" :: "r"(&matrix) : "$12", "$13", "$14");
__asm__ volatile("cfc2 $12, $5" :: "r"(&matrix) : "$12", "$13", "$14");
__asm__ volatile("sw $13, 24(%0)" :: "r"(&matrix) : "$12", "$13", "$14");
__asm__ volatile("sw $12, 20(%0)" :: "r"(&matrix) : "$12", "$13", "$14");
static void get_trans_vector(TRANSFERVECTOR& vector) {
__asm__ volatile("cfc2 $14, $7" :: "r"(&vector) : "$12", "$13", "$14");
__asm__ volatile("cfc2 $13, $6" :: "r"(&vector) : "$12", "$13", "$14");
__asm__ volatile("sw $14, 8(%0)" :: "r"(&vector) : "$12", "$13", "$14");
__asm__ volatile("cfc2 $12, $5" :: "r"(&vector) : "$12", "$13", "$14");
__asm__ volatile("sw $13, 4(%0)" :: "r"(&vector) : "$12", "$13", "$14");
__asm__ volatile("sw $12, 0(%0)" :: "r"(&vector) : "$12", "$13", "$14");
}
/*
@@ -113,7 +113,7 @@ namespace JabyEngine {
Multiplies two matrices m0 and m1.
The function destroys the constant rotation matrix
*/
MATRIX& multiply_matrix(const MATRIX& m0, const MATRIX& m1, MATRIX& result);
ROTMATRIX& multiply_matrix(const ROTMATRIX& m0, const ROTMATRIX& m1, ROTMATRIX& result);
/*
CompMatrix
@@ -124,11 +124,11 @@ namespace JabyEngine {
return: returns result
*/
static MATRIX& comp_matrix(const MATRIX& m0, const MATRIX& m1, MATRIX& result) {
multiply_matrix(m0, m1, result);
set_trans_matrix(m0);
GTE::ldlv0(reinterpret_cast<const VECTOR&>(m1.trans));
multiply_matrix(m0.rotation, m1.rotation, result.rotation);
set_trans_vector(m0.transfer);
GTE::ldlv0(reinterpret_cast<const VECTOR&>(m1.transfer));
GTE::rt();
GTE::stlvnl(reinterpret_cast<VECTOR&>(result.trans));
GTE::stlvnl(reinterpret_cast<VECTOR&>(result.transfer));
return result;
}

View File

@@ -33,7 +33,7 @@ namespace JabyEngine {
}
// Load column vector of MATRIX to universal register
static __always_inline void ldclmv(const MATRIX& matrix, size_t col) {
static __always_inline void ldclmv(const ROTMATRIX& matrix, size_t col) {
__asm__ volatile("lhu $12, 0(%0)" :: "r"(reinterpret_cast<uintptr_t>(&matrix) + (col << 1)) : "$12", "$13", "$14");
__asm__ volatile("lhu $13, 6(%0)" :: "r"(reinterpret_cast<uintptr_t>(&matrix) + (col << 1)) : "$12", "$13", "$14");
__asm__ volatile("lhu $14, 12(%0)" :: "r"(reinterpret_cast<uintptr_t>(&matrix) + (col << 1)) : "$12", "$13", "$14");
@@ -50,7 +50,7 @@ namespace JabyEngine {
}
// Store MATRIX column from 16 bit universal register
static __always_inline void stclmv(MATRIX& matrix, size_t col) {
static __always_inline void stclmv(ROTMATRIX& matrix, size_t col) {
__asm__ volatile("mfc2 $12, $9" :: "r"(reinterpret_cast<uintptr_t>(&matrix) + (col << 1)) : "$12", "$13", "$14", "memory");
__asm__ volatile("mfc2 $13, $10" :: "r"(reinterpret_cast<uintptr_t>(&matrix) + (col << 1)) : "$12", "$13", "$14", "memory");
__asm__ volatile("mfc2 $14, $11" :: "r"(reinterpret_cast<uintptr_t>(&matrix) + (col << 1)) : "$12", "$13", "$14", "memory");

View File

@@ -10,14 +10,13 @@ namespace JabyEngine {
T x;
T y;
T z;
T pad;
static constexpr VECTOR create() {
return VECTOR::create(0, 0, 0);
}
static constexpr VECTOR create(T x, T y, T z) {
return VECTOR{.x = x, .y = y, .z = z, .pad = 0};
return VECTOR{.x = x, .y = y, .z = z};
}
template<typename S>
@@ -31,28 +30,41 @@ namespace JabyEngine {
}
};
}
using VECTOR = internal::VECTOR<int32_t>;
using SVECTOR = internal::VECTOR<int16_t>;
// TODO: Split MATRIX into ROTMATRIX and TRANSFERVECTOR or something like that. But first get it running
struct MATRIX {
int16_t rot[3][3]; // Rotation matrix
int32_t trans[3]; // Translation vector
struct ROTMATRIX {
int16_t matrix[3][3];
static constexpr MATRIX identity() {
return MATRIX{
.rot = {
static constexpr ROTMATRIX identity() {
return ROTMATRIX{.matrix = {
{4096, 0, 0},
{0, 4096, 0},
{0, 0, 4096}
},
.trans = {0, 0, 0}
}
};
}
static MATRIX rotation(int32_t x, int32_t y, int32_t z);
} // TODO: replace int32_t with something weird for the DEG stuff??
static ROTMATRIX rotated(int32_t x, int32_t y, int32_t z);
};
using VECTOR = internal::VECTOR<int32_t>;
using SVECTOR = internal::VECTOR<int16_t>;
struct TRANSFERVECTOR : public VECTOR {
static constexpr TRANSFERVECTOR identity() {
return TRANSFERVECTOR::translated();
}
static constexpr TRANSFERVECTOR translated(int32_t x = 0, int32_t y = 0, int32_t z = 0) {
return TRANSFERVECTOR{{.x = x, .y = y, .z = z}};
}
};
struct MATRIX {
ROTMATRIX rotation;
TRANSFERVECTOR transfer;
static constexpr MATRIX identity() {
return MATRIX{.rotation = ROTMATRIX::identity(), .transfer = TRANSFERVECTOR::identity()};
}
};
static constexpr auto one_degree = FULL_CIRCLE/360;
static constexpr auto one_tenth_degree = FULL_CIRCLE/3600;