summaryrefslogtreecommitdiff
path: root/include/JSystem
diff options
context:
space:
mode:
authorhatal175 <hatal175@users.noreply.github.com>2023-07-08 06:06:50 +0300
committerGitHub <noreply@github.com>2023-07-08 06:06:50 +0300
commitcf26cd610d4e88f391c7d854b5da5b7460d130c5 (patch)
tree60e6811736d30ccc13d62b086ab37e96a7c1f337 /include/JSystem
parentc59ac1f2e9593aaf31a3394777a122e5678c963b (diff)
parentb9383052a342986015d51c59440944b6b8ccf740 (diff)
Merge pull request #364 from hatal175/m_do_graphics
Work on m_Do_graphic
Diffstat (limited to 'include/JSystem')
-rw-r--r--include/JSystem/JGeometry.h39
-rw-r--r--include/JSystem/JParticle/JPAParticle.h5
2 files changed, 44 insertions, 0 deletions
diff --git a/include/JSystem/JGeometry.h b/include/JSystem/JGeometry.h
index dd984bcc85..8f37b01fc9 100644
--- a/include/JSystem/JGeometry.h
+++ b/include/JSystem/JGeometry.h
@@ -3,6 +3,8 @@
#include "dolphin/mtx/vec.h"
#include "dolphin/types.h"
+#include "MSL_C/float.h"
+#include "MSL_C/math.h"
namespace JGeometry {
@@ -46,6 +48,11 @@ inline void setTVec3f(const f32* vec_a, f32* vec_b) {
};
}
+inline float fsqrt_step(float mag) {
+ f32 root = __frsqrte(mag);
+ return 0.5f * root * (3.0f - mag * (root * root));
+}
+
template <>
struct TVec3<f32> {
f32 x;
@@ -110,6 +117,38 @@ struct TVec3<f32> {
};
return *this;
}
+
+ f32 squared() {
+ return C_VECSquareMag((Vec*)&x);
+ }
+
+ void normalize() {
+ f32 sq = squared();
+ if (sq <= FLT_EPSILON * 32.0f) {
+ return;
+ }
+ f32 norm;
+ if (sq <= 0.0f) {
+ norm = sq;
+ } else {
+ norm = fsqrt_step(sq);
+ }
+ scale(norm);
+ }
+
+ void scale(register f32 sc) {
+ register f32 z;
+ register f32 x_y;
+ register f32* dst = &x;
+ asm {
+ psq_l x_y, 0(dst), 0, 0
+ psq_l z, 8(dst), 1, 0
+ ps_muls0 x_y, x_y, sc
+ psq_st x_y, 0(dst), 0, 0
+ ps_muls0 x_y, z, sc
+ psq_st x_y, 8(dst), 1, 0
+ };
+ }
};
template <typename T>
diff --git a/include/JSystem/JParticle/JPAParticle.h b/include/JSystem/JParticle/JPAParticle.h
index ed4fe9142a..3d27dca8e4 100644
--- a/include/JSystem/JParticle/JPAParticle.h
+++ b/include/JSystem/JParticle/JPAParticle.h
@@ -75,6 +75,11 @@ public:
template <class T>
struct JPANode {
+ JPANode() {
+ mpPrev = NULL;
+ mpNext = NULL;
+ }
+ ~JPANode() {}
JPANode<T>* mpPrev;
JPANode<T>* mpNext;
T mData;