Files
tp/include/JSystem/TPosition3.h
T

89 lines
2.2 KiB
C++
Raw Normal View History

#ifndef TPOSITION3_H
#define TPOSITION3_H
2024-01-19 16:22:19 -08:00
#include "dolphin/mtx.h"
#include "JSystem/JMath/JMath.h"
2024-01-26 00:50:55 +02:00
#include "JSystem/JGeometry.h"
namespace JGeometry {
template <typename T>
struct SMatrix34C {
T data[3][4];
};
template <>
struct SMatrix34C<f32> {
f32 data[3][4];
typedef f32 ArrType[4];
2024-01-26 00:50:55 +02:00
void set(const ArrType* src) {
2024-10-23 19:25:13 -04:00
JMath::gekko_ps_copy12(data, src);
2024-01-26 00:50:55 +02:00
}
operator ArrType*() { return data; }
operator const ArrType*() const { return data; }
};
2024-01-26 00:50:55 +02:00
template <typename T>
struct SMatrix33C {
T data[3][3];
inline T& ref(int i, int j) {
return data[i][j];
}
2025-04-09 16:45:30 -04:00
inline T at(int i, int j) const {
2024-01-26 00:50:55 +02:00
return data[i][j];
}
inline void set(T param_1, T param_2, T param_3, T param_4, T param_5,
T param_6, T param_7, T param_8, T param_9) {
ref(0,0) = param_1;
ref(0,1) = param_2;
ref(0,2) = param_3;
ref(1,0) = param_4;
ref(1,1) = param_5;
ref(1,2) = param_6;
ref(2,0) = param_7;
ref(2,1) = param_8;
ref(2,2) = param_9;
}
};
template <typename T>
struct TMatrix34 : public T {
2025-12-06 01:24:34 -05:00
void identity() { MTXIdentity(this->data); }
};
template <typename T>
struct TRotation3 : public T {};
2025-04-09 16:45:30 -04:00
template<typename T>
struct TRotation3<SMatrix33C<T> > : public SMatrix33C<T> {
inline void getEulerXYZ(TVec3<T>* param_1) const {
2025-12-06 01:24:34 -05:00
if (this->at(2, 0) - TUtil<T>::one() >= -TUtil<T>::epsilon()) {
param_1->set(TUtil<T>::atan2(-this->at(0, 1), this->at(1, 1)), -TUtil<T>::halfPI(), 0.0);
2025-04-09 16:45:30 -04:00
} else {
2025-12-06 01:24:34 -05:00
if (this->at(2, 0) + TUtil<T>::one() <= TUtil<T>::epsilon()) {
param_1->set(TUtil<T>::atan2(this->at(0, 1), this->at(1, 1)), TUtil<T>::halfPI(), 0.0);
2025-04-09 16:45:30 -04:00
} else {
2025-12-06 01:24:34 -05:00
param_1->x = TUtil<T>::atan2(this->at(2, 1), this->at(2, 2));
param_1->z = TUtil<T>::atan2(this->at(1, 0), this->at(0, 0));
param_1->y = TUtil<T>::asin(-this->at(2, 0));
2025-04-09 16:45:30 -04:00
}
}
}
};
template <typename T>
struct TPosition3 : public T {
TPosition3() {}
};
typedef TPosition3<TMatrix34<SMatrix34C<f32> > > TPosition3f32;
} // namespace JGeometry
2024-10-23 19:25:13 -04:00
#endif